HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

2D array???

02-05-2005, 12:23 PM#1
Tabris
Maybe a stupid question ( yes one more...) but can we declare 2D array (I mean matrice) if yes, how?
and another question: Is there global variable storing the map size?


Because I want to create a matrice wich would be a "pseudo-map"

well with exemple
matrice
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -

I run a algorithm included in a functionand the matrice become
- b - - - - - b - -
- - m - - l - - - -
- - - - - - - f - -
- f f f - - - f f -
- - - l - - - - - -
- - - - - - b - - -
- f - b - - - - - -
somting like that with each letter corresponding to something. Here
f forest
b beast
l life schrine
m mana schrine
Of course what . will programming will be more complex but that is the idea. So I need 2D array.
02-05-2005, 01:32 PM#2
Tommi
Yes. Declare a normal array of size [a*b], where a is the size of the first dimension and b is the size of the second dimension. Now, you can get a value from [x][y] by referencing [x*b+y]. It works the same way in C/C++.

Note: a*b may not be greater than 8192.
02-05-2005, 05:41 PM#3
Tabris
Quote:
Originally Posted by Tommi
Yes. Declare a normal array of size [a*b], where a is the size of the first dimension and b is the size of the second dimension. Now, you can get a value from [x][y] by referencing [x*b+y]. It works the same way in C/C++.

Note: a*b may not be greater than 8192.

well... In both C C++ you have [][] and not only one [] but maybe for the computer it is the same.... I don't know ^_^
Are we agree that a=Xmax et b=Ymax
this is limited to 8192 that is bad.....
64*64= 4096
128*128= 16384
So my map won't be so big.... Maybe I would chose another methode but his one was the easier.... ^_^
Anyone know how with the map size you know the limit of x and y
exemple :
map is 64*64 so ???<x<??? and ???<y<???
02-05-2005, 05:57 PM#4
Dalten
Quote:
Originally Posted by Tabris
well... In both C C++ you have [][] and not only one [] but maybe for the computer it is the same.... I don't know ^_^
Are we agree that a=Xmax et b=Ymax
this is limited to 8192 that is bad.....
64*64= 4096
128*128= 16384
So my map won't be so big.... Maybe I would chose another methode but his one was the easier.... ^_^
Anyone know how with the map size you know the limit of x and y
exemple :
map is 64*64 so ???<x<??? and ???<y<???

Couldn't you break the map up into quadrants, and use a set of variables for each of the 4 quadrants?

This would let you make a 128x128 map and if you need it larger just add more blocks of 64x64.. assuming it would be feasible to work with such blocks.
02-05-2005, 06:27 PM#5
Tabris
Quote:
Originally Posted by Dalten
Couldn't you break the map up into quadrants, and use a set of variables for each of the 4 quadrants?

This would let you make a 128x128 map and if you need it larger just add more blocks of 64x64.. assuming it would be feasible to work with such blocks.
yeah great idea the map will be brake ^_^ but with your idea mine always works
thanks!!!
PS in fact your idea is easy but I' haven't thought that....
02-06-2005, 05:02 PM#6
Tommi
Quote:
Originally Posted by Tabris
well... In both C C++ you have [][] and not only one [] but maybe for the computer it is the same.... I don't know ^_^

I meant that in C/C++, [][] is actually an abstraction. The compiler translates the [][] into a single dimension array using the same method I told you.