Archived

This topic is now archived and is closed to further replies.

webmunkey

Interesting Problem...

Recommended Posts

webmunkey    122
Hello, My problem is I have a tilebased engine where the map is specifed by something like this: char *world[21] = { "111111111111111111111111111111"... etc... and when I read it I use a for loop with two indexes to call each of the xpos and ypos inside the map, the number read by the for loops is then blitted off the bitmap and placed on the back buffer... the problem is I now have two digit numbers in the map and the game will only recognize one digit numbers (for obvious reasons)... so if I were to place a "121111... in the char *world array, the game would read it as "okay, lets make frame 1... okay now add 32 and make frame 2..." when really I want the game to think "okay, wait, thats frame 12, okay, blit frame 12, right then, now add 32 and blit frame 1, okay..." I''ve been brainstorming this problem and with my limited coding knowlegde I thought about maybe adding something special in front of the two digit numbers that would tell the game that it was a two digit number and to read the next two number instead of one, but wouldn''t that mess up the indexes in my for loop so that they''d come out one short? or maybe not because the cell is twice as big and...oh now I''m really confused... -Jesse

Share this post


Link to post
Share on other sites
webmunkey    122
Hey guys,
Nevermind, I figured it out. The solution is to put a letter in place of the first digit of the two digit number and then run something like this:
if (worldFrame > 10)
{
worldFrame = (worldFrame * 10) - 480 +
world[index_y + y_modify][index_x + x_modify + 1] - ''0'';
index_x++;
}
that takes the ascii code of the letter and converts it into a number such as 10, 20, 30 etc...
Hope this helps some other dumb newbie such as myself...
Cheers,
-Jesse

Share this post


Link to post
Share on other sites
parklife    132
You COULD make all the numbers two-digits long.

char* world=
{"01010101010101020101020304", ...

This however requires bit more work than your own solution. i think.



//John
-----------------------------------------
Swedish saying:
"The one who joins the game must face the consequences of the game."

Share this post


Link to post
Share on other sites
BeerNutts    4400
do you have to use character strings? Just make it characters, and instead of using long strings, use comma''s
ie
char *world[21] =
{
{1, 1, 12, 2, 34, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, },
.
.
.
}

?

Share this post


Link to post
Share on other sites
webmunkey    122
Thanks for the replies. When I started writing my map editor program, I realized that it would be a hundred times easier just to do what BeerNutts said, and that also takes care of the double digit problem... So, thanks for everyone''s input anyhow,
Later,
-Jesse

Share this post


Link to post
Share on other sites