Just thought I would let you know, if your looking for a free tile based map editor there is a pretty good one called Mappy. You can get it here: http://www.geocities.com/SiliconValley/Vista/7336/robmpy.htm
Its got good documentation with it. Im using it for my game right now and so far its worked great. Just a thought.
ViPeR
Syntax Question for Tile-Based Engine
Muzzafarath, yes you're right. I meant the "rt" in fopen. Sorry about that. Yes, place_x, place_y, and *world[] are indeed global. I'll try those suggestions, and see if I have any luck. Thanks for all your time and info.
Viper, thanks...I'll check that program out.
I'm sure I'll have this working some century
This line, it just does not like...
for (j=0; j<=21; j++) {fscanf(fp, "%s", world[j]); }
So, fscanf should not need to know nor care how many characters there are in each row because of the
%s...just the number of rows of course, hence the variable j. Am I correct about this?
I tried:
for (j=0; j<=20; j++) {fscanf(fp, "%s", world[j]); }
with a 20 instead of 21, also, but to no avail.
I just don't get it, but I am learning a ton of info, so that's a good thing
Edited by - Nazrix on 4/19/00 12:52:21 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
One thing I just thought of is that perhaps the code that Andre used to read in the map data when it was hard-coded into the source code isn''t made to handle the one from a file?
I imagine it would make no difference, but here is the code he uses to read in the data to assign the proper bitmap for each number.
world_x and world_y is the coordinates you are in in ther world.
// compute starting map indices by dividing position by size of cell
start_map_x = world_x/64; // use >> 6 for speed, but this is clearer
start_map_y = world_y/64;
// compute end of map rectangle for best cast i.e. aligned on 64x64 boundary
end_map_x = start_map_x + 10 - 1;
end_map_y = start_map_y + 7 - 1;
// now compute number of pixels in x,y we are within the tile, i.e
// how much is scrolled off the edge?
offset_x = -(world_x % 64);
offset_y = -(world_y % 64);
// adjust end_map_x,y for offsets
if (offset_x)
end_map_x++;
if (offset_y)
end_map_y++;
// set starting position of first upper lh texture
int texture_x = offset_x;
int texture_y = offset_y;
// draw the current window
for (index_y = start_map_y; index_y <= end_map_y; index_y++)
{
for (index_x = start_map_x; index_x <= end_map_x; index_x++)
{
// set position to blit
textures.x = texture_x;
textures.y = texture_y;
// set frame
textures.curr_frame = world[index_y][index_x] - ''0'';
// draw the texture
Draw_BOB(&textures,lpddsback);
// update texture position
texture_x+=64;
} // end for map_x
// reset x postion, update y
texture_x = offset_x;
texture_y += 64;
} // end for map_y
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
"So, fscanf should not need to know nor care how many characters there are in each row because of the %s...just the number of rows of course, hence the variable j. Am I correct about this?"
Yes, you're right. fscanf() shouldn't (and won't) care about how many characters there are in each row. It will just read all characters until it comes across a space or a newline char and stuff all the characters it read into world[j].
Btw, the new function I suggested you try was wrong, here's a working version :
/. Muzzafarath
Edited by - Muzzafarath on 4/19/00 2:17:03 AM
Yes, you're right. fscanf() shouldn't (and won't) care about how many characters there are in each row. It will just read all characters until it comes across a space or a newline char and stuff all the characters it read into world[j].
Btw, the new function I suggested you try was wrong, here's a working version :
void Change_Map(void)
{
FILE *fp = NULL;
int j;
if (place_x==10 && place_y==9)
{
fp = fopen("map.txt", "rt");
if(fp == NULL) exit(1);
for (j=0; j<=21; j++)
{ fscanf(fp, "%s", world[j]); }
fclose(fp);
} // end if
} // end Change_Map()
/. Muzzafarath
Edited by - Muzzafarath on 4/19/00 2:17:03 AM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Okay, that's what I thought about fscanf()
Yes, I noticed that you wrote the path incorrectly, so I didn't do it that way
-----------------------------
Do you notice any problems in my previous post where the code tells it what bitmap to load according to *world[]?
This section looks starnge to me...I don't completely understand it and maybe it's a potential problem?
// set frame
textures.curr_frame = world[index_y][index_x] - '0';
textures.curr_frame, of course, is the var holding what bitmap to load for the current texture number....
Edited by - Nazrix on 4/19/00 2:48:03 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
I see no problem with the code you posted.
What textures.curr_frame = world[index_y][index_x] - ''0''; does is that it access one number from the world array and subtracts it by ''O'' (which is 48). I don''t think that''s the problem.
Does the game simply crash when it comes to the for loop? Does it give any error messages?
/. Muzzafarath
What textures.curr_frame = world[index_y][index_x] - ''0''; does is that it access one number from the world array and subtracts it by ''O'' (which is 48). I don''t think that''s the problem.
Does the game simply crash when it comes to the for loop? Does it give any error messages?
/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
I see...
No, it gives no error messages. It simply crashes back to windows. It''s so odd.
No, it gives no error messages. It simply crashes back to windows. It''s so odd.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Just butting into the thread, and i haven''t read it very carefully; but if the fscanf is giving the problem, isn''t it because it reads the whole file at once? It doesn''t see an end to the string! The WHOLE file is a string.
Or did I miss the point completely
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
Or did I miss the point completely
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
Well, fscanf is absolutely the problem. If I remark the for loop and put in 21 fscanf lines that read in world[0],world[1], etc. it still crashes on me. I think I am reading a line at a time w/ fscanf. Maybe I am wrong though.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Your file doesn''t have newlines or zero-terminators in it to delimit the strings, or does it? I''m not an expert on the inner workings of fscanf - but you should look into what exactly it interprets as a single string. In fact, I''ll look it up now ''cause I''m curious.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement