Computer Science Canada

Creating 2-D Arrays

Author:  yusong [ Thu May 08, 2008 9:13 am ]
Post subject:  Creating 2-D Arrays

It there a way to massively create variables?
As in I am creating a tiling system for a RPG game, but there are some tiles that you cannot walk over, so I want a 2-D array to say what you can and cannot walk over.
I need to massively creat because there are multiple screens.
Please give suggestions.
THX!

Author:  Asherel [ Thu May 08, 2008 1:15 pm ]
Post subject:  Re: Creating 2-D Arrays

You'll need to look into multi-dimentional arrays.Therefore, the one array would play as an (x,y) location on the screen for you to check.

There is a walkthrough for what you need there. Take a look into the Arrays.

If you still have questions, then look us up again.

Author:  CodeMonkey2000 [ Thu May 08, 2008 7:54 pm ]
Post subject:  RE:Creating 2-D Arrays

Here is the basic syntax for 2D arrays.
code:
const x := 5
const y := 6
var foo : array 1 .. x, 1 .. y of int
foo (1, 1) := 5
put foo (1, 1)


Now if you want dynamic maps (maps that vary in size) you will need to use a single dimensional flexible array. You just create how many ever elements you need, and just make up a convention you can use that takes the x and y values and finds the proper location in the single dimensional array. Remember a 3 by 3 array still has 9 elements.

Author:  Nick [ Thu May 08, 2008 8:01 pm ]
Post subject:  RE:Creating 2-D Arrays

Yusong knows how to do this based on her post
Quote:
so I want a 2-D array to say what you can and cannot walk over


so back to the question, the best way to "massively create" variables is to do so by a file, have each file be a single room, then when the player changes rooms, change the 2D array

Author:  Saad [ Thu May 08, 2008 8:04 pm ]
Post subject:  Re: Creating 2-D Arrays

Seeing how you said "massively create" brings me to think of how big. If a map is relatively big then you might want to consider splitting the bigger map into a group of smaller maps. That way if you need to you can load smaller sections of maps each time and avoid "massively creating" variables.

Author:  yusong [ Mon May 12, 2008 8:41 am ]
Post subject:  RE:Creating 2-D Arrays

Ok, I have already created the arrays and stored it in a pic. But there are tiles, like number 15 and aboves that you cannot walk over, so I either have to not use the pictures and create the tiles in the game or create more arrays and store where you can walk and cannot walk.

Author:  CodeMonkey2000 [ Mon May 12, 2008 10:43 am ]
Post subject:  RE:Creating 2-D Arrays

Use a record that memorizes the picutre and the property.


: