Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Creating 2-D Arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yusong




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
Asherel




PostPosted: 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.
CodeMonkey2000




PostPosted: 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.
Nick




PostPosted: 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
Saad




PostPosted: 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.
yusong




PostPosted: 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.
CodeMonkey2000




PostPosted: Mon May 12, 2008 10:43 am   Post subject: RE:Creating 2-D Arrays

Use a record that memorizes the picutre and the property.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: