Skip to main content
GameDev.net gamedev.net
🔒 Locked

Side Scroller

Started by Shmuel Dec 19, 2004 at 1:15 AM 7 replies 1.3k views
Original Post
Shmuel
Shmuel
I'm quite comfortable with C++ and SDL and I just have a question about making a side scroller, like a mario clone lets say: You know how they have blocks in the air? Are they part of the level map itself or are they objects with their location in the map file? Since there are lots of blocks how do I know which blocks to check for collision against? My big question is how is everything organized? I think I can program it pretty much but I don't know how to design a system that would be easy enough to program.
case ShmuelPosted:StupidPosts++;
Alpha_ProgDes
Alpha_ProgDes
they would be in the map file.
for instance:
ssssssssssssssssssssssssssssssssssssssssssssssssssssssbbsssssssssssssssssssssssssssbbsssssssbbbssssssssssssssssssbbbbbssssssssssssssbbbbbbbbbbbbbbbbbbbbbb


where s is the sky and b is the block.

then you would have code that says:
(pseuodcode)read in mapif (character == s)   blt (sky.img)else if (character == b)   blt (block.img)


now block should be a variable such as:
typedef struct block {   bool visible;   bool collision;   char *img;} BLOCK, *pBLOCK;


i hope this helps.
Beginner in Game Development?  Read here. And read here.  
Shmuel
Shmuel
if (character == s)

and

if (character == b)

And how do I get that info? Where would I store his location so I could check it agianst the map?
case ShmuelPosted:StupidPosts++;
Julian Spillane
Julian Spillane
Well, what you'd do would be to store the map data in a two-dimensional array of bytes, and update your player's position in relation.

So if there's an s character at [10][25], you check to see if your character is also at location [10][25], and boom, you've collected a powerup. And, in the event of a block or obstacle, you do a check of squares adjacent in the matrix.

Now, this is old-school platform game mechanics. This is back in the day when they used to draw out their levels on grid paper, count the squares, create an array, and then map it back into their software. Nowadays, it's a bit easier just to use vector mathematics to represent direction and magnitudes of the characters' motions.

Anyways, this is classical game mechanics. XD Wow...wouldn't that be a great class? "Game Mechanics Classical to Modern: A Study of Applied Physics".

...Hawking's 1-Up theorem.
Shmuel
Shmuel
That would work if the player moved from tile to tile, I'm talking about if he moves pixels at a time. How would I get it to work then?
case ShmuelPosted:StupidPosts++;
Haytil
Haytil
All you have to do is calculate, given the character's position, what blocks he's intersecting with. He should be entirely in sky blocks. Then, when the player tries to move the character, see if the movement would make it intersect with any solid blocks. If so, don't allow the character to move.

All this should be easy if your blocks all have one standard size (the same width and the same height in pixels).
Alpha_ProgDes
Alpha_ProgDes
(sidenote: and people say LaMothe is useless....)
you should Google a little more but I'll do some searching also since you bring up a good question.
Beginner in Game Development?  Read here. And read here.  
Julian Spillane
Julian Spillane
Well, for pixels, just make note of the size of your level in pixels, (w x h), and the position of your blocks in pixels, and test against them in relation to the position of your character. Assuming that you're using a bounding box to surround your character, it should simply be a matter of comparing position and width/height values to the position + width & height values of your blocks.

If that paragraph made little to no sense, it's because it's 3:00am and I'm tired.
GroZZleR
GroZZleR
1. I don't see why the blocks would be part of the map and not entities. You can smash your head into them and break them, so why store 'em as a static object in the map array? It makes more sense (atleast to me) to have them be dynamic entities.

2. To get the tile that your character is currently over, divide his position by the width of the tiles.

int iTileX = PlayerX / TileSizeX;
int iTileY = PlayerY / TileSizeY;

This will give you the location of your character referenced into the map array, and then just check a tile or two around that location. To check things like enemies or bullets, you'll have to loop through that list of entities and check 'em. A spatial system would be a good idea to implement to assist in that, so you don't end up checking 1000s of entities that are miles away from your character.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.