My Contra-type game
Hi. I'm trying to make a game just like contra, where you go walking forward(right) and shoot people around. Here's how i'm doing it : each stage(the whole stage) is inside a bmp file. What i'm trying to do is, when i press the right key, the background moves to the left, as if the character is going forward. But i don't know a SDL command to get pieces of the stage bmp file to be shown at the screen properly each time the character moves to the right. Thank you.
July 31, 2004 04:03 PM
You really should think of another way of saving your level than the whoe background in a bmp file :) Lets say you have the visible part 800*600 and you have as little as 3*10 screen level - that takes up about 57.6 MB of memory :)
Yeah. I've been thinking of it... But there are so many other things, so i'm confused. I've been stuck on this for a big time.. can you give me some help, maybe thru a real time chat? Thanks a lot.
Hmm, how long have you been programming games?
OK, I think what you want is a tile engine. Which is, instead of making the entire level a huge bitmap, you make many small bitmaps (usually 32x32), each one representing, say, a brick or something. Then:
Brick = 1
Grass = 2
Say you wanted a level with grass on the ground and a brick background. You would create a 2D array:
Then, to draw it:
Where drawTile() takes an integer as the tile to draw (brick, grass, ...) and the position at which to draw it.
If you've never seen a tile engine in action or have never built a tile engine, then you should start now! There are many resources, search Google for 'Tile Engine' or search GameDev.Net's articles.
Hope it helps.
OK, I think what you want is a tile engine. Which is, instead of making the entire level a huge bitmap, you make many small bitmaps (usually 32x32), each one representing, say, a brick or something. Then:
Brick = 1
Grass = 2
Say you wanted a level with grass on the ground and a brick background. You would create a 2D array:
int tiles[4][4] = { 1, 1, 1, 1, // A line of 4 brick tiles 1, 1, 1, 1, // Another line of 4 brick tiles 1, 1, 1, 1, // Another one... 2, 2, 2, 2 }; // And finally, the ground
Then, to draw it:
int index = 0, i = 0;while ( index < 4 ){ while ( i < 4 ) { drawTile( tiles[index], i * 32, index * 32 ); i++; } index++;}
Where drawTile() takes an integer as the tile to draw (brick, grass, ...) and the position at which to draw it.
If you've never seen a tile engine in action or have never built a tile engine, then you should start now! There are many resources, search Google for 'Tile Engine' or search GameDev.Net's articles.
Hope it helps.
- fyhuang [ site ]
I'm going to have to agree with everyone on this one. Saving a contra type level as a bmp file is not going to work. Tiles are a swell place to start. They have been around since the begining because in the begining tiles were the only way to get anything done. As mentioned there are lots of info on this site alone on the subject. And dont think tiles are only for old icky old skool NES games. Oh no. Use a good res, 32-bit color, and make plenty of tile types and it can look super sharp. If your a clever enough artist people might not even know its done with tiles.
Be forwarned though. wraping you head around drawing your viewport, learning how to draw rows and columns may irritate from time to time. Its not that is hard but if your as green as you sound then it may be alot to take in. I've made a couple of tile engines in days past and its interesting what mistakes you can make. I wish I could post a screen shot but I don't have any way to really make that happen. Fortunatly for you have SDL which should be easier to use than writing one in DOS like my first. My second one was made in Direct Draw which looks fab compared to old DOS but I don't recomend DirectX to anyone that dosen't like banging their head against their keyboard while trying to figure out all the setup code.
Yet that takes us back to your original problem about how to use only a piece of an image and not the whole source file. As you want to save all those tiles in one big BMP file and not a scad of little 32x32 or 50x50 images. Unfortuanatly I've never done that in SDL and saddly am no help.
Be forwarned though. wraping you head around drawing your viewport, learning how to draw rows and columns may irritate from time to time. Its not that is hard but if your as green as you sound then it may be alot to take in. I've made a couple of tile engines in days past and its interesting what mistakes you can make. I wish I could post a screen shot but I don't have any way to really make that happen. Fortunatly for you have SDL which should be easier to use than writing one in DOS like my first. My second one was made in Direct Draw which looks fab compared to old DOS but I don't recomend DirectX to anyone that dosen't like banging their head against their keyboard while trying to figure out all the setup code.
Yet that takes us back to your original problem about how to use only a piece of an image and not the whole source file. As you want to save all those tiles in one big BMP file and not a scad of little 32x32 or 50x50 images. Unfortuanatly I've never done that in SDL and saddly am no help.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
Check out Game Programming Genesis (http://www.gamedev.net/reference/articles/article1229.asp)
Part VIII should be of particular interest to you. But i advise you to read the whole series.
Part VIII should be of particular interest to you. But i advise you to read the whole series.
Thanks a lot for your help. I already solve my previous problem. Now i'm just making that jumps, shoots and all the conditions. If i get stuck again, i'll let you know.
Not to sound weird or anything, but is there any special reason that you made while loops instead or for loops. From my experience, a for loop is designed to do what your while loop did. If its just a personal preference, thats ok, but Im just curious.
well when i drew my tilemap using for loops they tiles didnt print they way they were supposed to. i cant really explain it but if you try to use for loops you will know what i mean.
[edit] that only applies if the array is rectangular and not square. if the array is square eg. as above [4][4] then for loops will certainly work. [/edit]
[edit] that only applies if the array is rectangular and not square. if the array is square eg. as above [4][4] then for loops will certainly work. [/edit]
To blit only a part of a SDL_Surface, you'll need a SDL_Rect to specify the coordinates to take from that surface:
hope that helps you how to blit only a part of a surface
Matt
SDL_Surface *tiles /* a surface containing all the tiles */SDL_Rect src_rect/* let takes the 2nd tile from the left and the 1st tile from the top */src_rect.x = 32;src_rect.y = 0;src_rect.w = 32;src_rect.h = 32;/* screen is your screen surface *//* dst_rect is the destination on the screen */SDL_BlitSurface(tiles, &src_rect, screen, &dst_rect);
hope that helps you how to blit only a part of a surface
Matt
Matt
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement