Code:A 1D-array:
Dim A(10) as Integer
A 2D-array:
Dim A(10, 20) as Integer
...
Printable View
Code:A 1D-array:
Dim A(10) as Integer
A 2D-array:
Dim A(10, 20) as Integer
...
Oh, I forgot:
Array with any dimension and size:
Code:Dim A() as Long
ReDim A(10, 20)
ReDim A(34, 23, 54)
ReDim A(12000)
...whatever you like ;)
Stupid me... confused again :( I don't understand where I put the code.
You should put it in a Module. This will create a 10x10 Map.
Code:Public Map(10, 10) As Integer
Ohh... Do I put the code for the map the the module too? :)
You mean the code to read the Map? Yes, you can put that in a module and just call it when your Form loads.
I meant the code for the map:
>9 = You
>2 = Item
>1 = Wall
>0 = Walkable
>
>0000000000
>0111 1100 00
>0000000000
>0100 200020
>0100 000000
>0100 009000
>0100 000000
>0000000000
>011 1100 000
>000 0100 020
Is this a map?
The Map will be stored in the 2-dimensional Array, and yes, the Array should be stored in the Module.
The numbers in the map turn red when I put them in the modual :(
You do not put the number's directly into the module. You put the Array into the Module. The Number's go in a *.txt or *.map file and when you load the file, you store each each numbers in the Array.
What code do I out the the modual? The
Public Map(10, 10) As Integer
works, but how do I load my map? I tryed this:
ff=freefile
Open yourfile for binary as ff
get ff,,Width
get ff,,Height
redim map(width,height)
get map
close ff
But it doesnt work :(
Did you save a map before trying to load?
Code:Open FileName for binary as FileNumber
Put FileNumber,, Width
Put FileNumber,, Height
Put Map
Close FileNumber
I saved my map as a .txt file...
That's not a text file so don't name it .TXT, it's a binary dump and you have to use a hex editor to edit it.
Also I suggest you make an internal editor in your game so that you can design your maps there, that's if you don't have or want to use an hexaeditor.
How do I make an editor in my game? :)
Say you have a 10x10 Map. Draw a Grid in your Map editor which is 10x10. In terms of numbers, all our squares are 0's because they are empty.
Now when you select a Tile (a wall for example) and click on your Map, change that specifc square on the map to a 1 to represent the wall. Then when you select a "Death Spot" Tile, change the number to a 2.
Then you just save your Array when you are done your Map.
You should declare a palette variable that you can select a palette for drawing your map, then by clicking on the map you change the array:
If you don't need scrolling in your map just remove the scroll variables, you should set the tileW and TileH as the dimensions of your tiles in your gameCode:Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X - scrollX) / tileW < Width And (Y - scrollY) / tileH < Height Then
map((X - scrollX) / tileW, (Y - scrollY) / tileH) = Palette
End If
End Sub
It didnt do anything. What am I suposed to look for?
You should declare a palette variable
To which you assign values the way you want, by clicking on a terrain palette or pressing keys (0-9) or anything. You can even set palette=5 in immediate window and it will changeCode:Private palette as integer