Moving around inside arrays?

Willing to read. Willing to suffer. Want to learn. I've got till Sunday night.

C++...took first course 2 yrs ago and forgot most. Now in second course.

I have game that I will be improving through-out the semester. The first part can be simple, but must be C++...functions only - no objects.

First chunk: a (grid, map, array). On this grid I want 4 areas plus a starting place (5 areas i guess). In each area I want 1 room, and 1 object (set of instructions). In each room I want 2 objects (a container and an object). In each container I want another set of instructions. I want one player to move around, reading instructions, checking out objects, keeping objects, and win when player finds special object.

My battle plan is to create the grid, create the player, create areas, create the rooms, fill the rooms and areas, and play the game.

I'm stuck on how to create the array (grid) where my player can move around inside of it. Thanks for your help.
You need a tile-based map. I can't give a full explanation (because I'm rubbish and I'll just confuse you), but the idea is that the entire map is broken up into a number of tiles, that can be represented as a simple array. Each tile is only one position in the array, but can take up any given amount of space within the total map.

Eg. a map 64*64 could be represented as a 2d 8*8 boolean array, where a tile is either walkable or not walkable. The player then has their own co-ordinates that exist within the map, so they can move around on different tiles.

(I told you my explanation would be rubbish)
@Georgep why would you use a boolean array? Why not an array of anything (ints maybe) so you can represent more than two types of tile?

0 = not walkable, 1 = walkable, 2 = object, 3 = door? etc..

See what I'm saying?
Last edited on
Of course, I was just giving an example.
Something like this:

int world [4] [4] = {1,0,0,1; 0,0,0,0; 0,0,0,0; 1,0,0,1};
//where 1's are rooms and 0's are nothing yet?
Topic archived. No new replies allowed.