Array [x,y] or [x][y] or something else?

Talk about making games.

Array [x,y] or [x][y] or something else?

Postby NUTINC » Fri Feb 19, 2010 5:48 am

Hello. Could I get an explanation on how to do 2D arrays? I'm trying to design a map that could store the position of objects on it. I know how to do one array with variable[cloneindex] and stuff like that, and I might have to use that or something else, but how does one type an variable with a two dimensional array? Or better yet, how does the two dimensional array system work? :oops:
To those of you out there, I am not dead. I am a ghost! There is a difference!
Currently Working on: Parts, A self-assembling adventure
User avatar
NUTINC
 
Posts: 98
Joined: Fri Feb 09, 2007 1:06 am
Location: Lost in the deep dark recesses of my mind, wondering why the exit sign leads to brick wall
Score: 6 Give a positive score

Re: Array [x,y] or [x][y] or something else?

Postby skydereign » Fri Feb 19, 2010 6:02 am

Here is a simple 'example'.
Code: Select all
int position[10][2]; // Declaration of  a 2d array

You reference it in the same fashion when setting the values. The 10 in this case would be the actors you are holding the positions of, and the 2 would be the two values you want to hold. Below is one method of storing the positions.
Code: Select all
position[cloneindex][0]=x;
position[cloneindex][1]=y;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Array [x,y] or [x][y] or something else?

Postby Bee-Ant » Fri Feb 19, 2010 2:33 pm

array[5][5] means an array with 5 arrows and 5 columns. 2D array would draw a table like numbers.

21,34,56,91,27
64,52,13,76,38
21,34,56,91,27
64,52,13,76,38
21,34,56,91,27

Its usually used to handle tile map, clone with so many attributes, etc.
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Array [x,y] or [x][y] or something else?

Postby NUTINC » Sat Feb 20, 2010 4:34 am

Thanks, exactly what I needed. :mrgreen:
To those of you out there, I am not dead. I am a ghost! There is a difference!
Currently Working on: Parts, A self-assembling adventure
User avatar
NUTINC
 
Posts: 98
Joined: Fri Feb 09, 2007 1:06 am
Location: Lost in the deep dark recesses of my mind, wondering why the exit sign leads to brick wall
Score: 6 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron