game design, time to think about arrays.
imagine your game grid is 10 x 10 in size.
draw it on a piece of paper for clarity.
Now think of the across rows as the X dimension. ( to remember easier the X is two arrows pointing left and right)
think of the down columns as the Y dimension. ( the Y is an arrow pointing down and the opposite is up)
when you define an array it can be 1 dimension or 2/3/4/5
we are only thinking about a 2 dimensional one in this example.
arrays usually start from zero and upwards, for sanity and a little lost memory we will define the array starting at one.
lets make an array with one dimension to start with.
this makes an array of 1 dimension with 11 spaces. The zero pocket is counted as well.
0 1 2 3 4 5 6 7 8 9 10
Think of an egg carton with one row of 11 eggs.
each egg is your data, the carton is the array.
there is no data in each pocket so each location should represent zero.
if we want to populate this array with data we can fill it up manually.
myarray(0) = 0
myarray(1) = 1
myarray(2) = 2
etc..
that can get a little long winded so we deploy a loop
for c = 1 to 10
myarray(c) = c
next c
notice we didnt fill the first pocket with any data, it just helps to make it easier to manage.
otherwise myarray(0) could be 1 and therefore every valuable is one behind in the list.
we can easily print out the data as well by adding a print statement to your loop
for c = 1 to 10
myarray(c) = c * 2
print "my array location :"+STR$(c)+" = " +STR$(c)
next c
we are taking the result of c and doubling it for the data.
you can do anything here you like eg: c +5 would start the array data at 6 7 8 9 etc..
It should print something like this.
my array location :1 = 2
my array location :2 = 4
my array location :3 = 6
my array location :4 = 8
etc..
the variable c keeps going up to 10, the STR$() command just converts the numerals to textual data for use in the print statement.
now lets go back to the 2 dimensional array idea and create one and populate it with random numbers in each of the array locations, without filling the zero locations for clarity.
Dim MyMap(10,10)
for X = 1 to 10
for Y = 1 to 10
MyMap(X,Y) = rnd(10)
next X
next Y
we have just filled the array in both X and Y dimensions with random numbers from one to ten.
naturally if we want it to be truely random we have to add a small line at the top of the program
this command basically takes what time it is and seeds the randomize command with a starting number providing a good method to get a random result.
your challenge today is to add a command to above snippet that will print out the data to the screen. look at my first 1 dimensional array for a clue.
There is a lot more to learn about arrays but give them a go before you embark on things like A* path finding and you will find it a lot easier to read other examples.
arrays can be a godsend for game maps and well worth your learning.
when you want to destroy an array you would use the undim command.
This is best used at the end of your game when cleaning up.
Pretty soon you will get the hang of things, down the track it will get a lot easier in some ways.
just start slowly and dont skip stuff.