• Advertisement
Sign in to follow this  

Help on searching my Map Array

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have designed my maps so that they are in 2d arrays. I have defined one of my tiles attribs to have a start_level which equals 1. eg (tile.start_level =1). I am having a problem, about how do I go about scanning my map to find this tile and then placing my character on that tile. I'm going about it like this: for (int x = 0; x<=255; x++) { for (int y = 0; y<=255; y++) { //IF current position on the map is equal to start_level ==1// if(tiles[Map_Array[x][y][0].start_level==2) //) is the layer //DRAW THE CHARACTER AT THIS TILE// } } Any help on what I'm doing wrong would be greatly appreciated! Thanks

Share this post


Link to post
Share on other sites
Advertisement
If it is just one tile, it might be easier just to create a structure holding the (x,y) coordinates of that tile and using it to locate your character. It would save on both the search time as well as the memory used for describing each tile.

Another idea would be to have a single subscripted array made up of the (x,y) coordinates of the start tile for each level.

Share this post


Link to post
Share on other sites
I'd say that special cases like this call for holding a pointer to the tile in question, not for setting a variable. Since you're only going to have one tile where start_level == 1 anyway, you're basically special-coding the start tile location into memory (except that you're spending a few extra bytes for every other tile to say that it's not the start location). So if you're going to special-code this, you might as well make it easy on yourself. When you first find out which tile is the start location (i.e. when you would normally do start_level = 1), just set a pointer to the start location, that you can access when you need to find out where the start location is.

Share this post


Link to post
Share on other sites
Once you find the right tile to start on (looks to me like you figured that out already :)), just set the player's position to the position of the tile.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I figured out the problem, found an error in my code to position my character at that location

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement