Archived

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

Interesting Problem...

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

Recommended Posts

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 on other sites
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 on other sites
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 on other sites
I''d recommend just writing a map editor and learn how to read and write binary files in C++

It''ll simplify things a great deal and you should learn how to use files anyway. MIght as well start with something visual like the map so you know if it''s working or not.

Ben

[Icarus Independent | Jump Down The Rabbithole | Rabbit Tricks ]

Share on other sites
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, },
.
.
.
}

?

Or just use bits

Share on other sites
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

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 15
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631724
• Total Posts
3001903
×