GLBasic forum

Main forum => GLBasic - en => Topic started by: mrdremel on 2010-Jul-29

Title: How to create levels for a 2d jump 'n run game
Post by: mrdremel on 2010-Jul-29
Hi. I've beel fiddeling with glbasic a few years ago on the gp2x and made some really basic bames.

Now I have an Open Pandora and want to create some games for that platform.

I want to create a jump 'n run game. I have a totally working control scheme for walking left and right, jumping and bumping into enemies.

Now i want to create some levels (or one level to start with). But I need some info on something really basic. Do i create a bunch of sprites which i can just put in a level at different places (ground, palforms, etc)? How do I make my character walk on top of the ground for instance?

Can someone give me some pointers as to making this happen?

Thanks guys...
Title: Re: How to create levels for a 2d jump 'n run game
Post by: Slydog on 2010-Jul-29
Try this tutorial by MrTAToad (Jnr Platform Example #3):
http://www.glbasic.com/forum/index.php?topic=4683.0;topicseen

There are two other tutorials in this series also, try searching the forums for the others.
Title: Re: How to create levels for a 2d jump 'n run game
Post by: mrdremel on 2010-Jul-29
Basically what I want to do is draw some sprites (pieces of ground to walk on). I've got that covered.

I draw my character and let it walk left and right on the ground. When there is no more ground it has to fall down.

Can this be done with a sprcoll, without doing a sprcoll for every sprite the character can walk on seperately?

The example is done in a totally different way which i don't really understand.


I just need some pointers for this, without try-ing to understand a piece of sourcecode that is 100 times more complex than mine.
Title: Re: How to create levels for a 2d jump 'n run game
Post by: matchy on 2010-Jul-29
What code have you got so far?
Title: Re: How to create levels for a 2d jump 'n run game
Post by: ketil on 2010-Jul-29
I'm currently working on a tile/level/scroll engine (or whatever i should call it) it imports tilesets / levels build with tiled.
I can give you some of the code when it's finished. Just remind me in a few weeks.
Title: Re: How to create levels for a 2d jump 'n run game
Post by: mrdremel on 2010-Jul-30
Is it possible, to check weather there is a collision with a certain sprite id at the current location of the player? I tried it yesterday (sprcoll ([id_of_player], x_of_player, y_of_player, [id_of_terrain_sprite, x_of_player, y_of_player])), but i couldn't get that to work that way.

I need to know if this is a possible way of getting it to work and if not, some explaination of how I should go about this. Not so much in code, but in plain english (or Dutch for that matter).

How does that whole tile thing work? Do you seperate the map in a number of tiles with a fixed size? And what do you check for then?

Thanks guys...
Title: Re: How to create levels for a 2d jump 'n run game
Post by: Slydog on 2010-Jul-30
Quotesprcoll ([id_of_player], x_of_player, y_of_player, [id_of_terrain_sprite, x_of_player, y_of_player]))

Did you type that wrong, or did you mean for the 2nd 'x_of_player', 'y_of_player' to refer to the terrain, such as:

Code (glbasic) Select
SPRCOLL (player_id, player_x, player_y, terrain_id, terrain_x, terrain_y)

That should work.

Title: Re: How to create levels for a 2d jump 'n run game
Post by: mrdremel on 2010-Jul-30
Quote from: Slydog on 2010-Jul-30
Quotesprcoll ([id_of_player], x_of_player, y_of_player, [id_of_terrain_sprite, x_of_player, y_of_player]))

Did you type that wrong, or did you mean for the 2nd 'x_of_player', 'y_of_player' to refer to the terrain, such as:

Code (glbasic) Select
SPRCOLL (player_id, player_x, player_y, terrain_id, terrain_x, terrain_y)

That should work.

I know that should work, but I have the same sprite over 25 times to create the level (they are peices of ground). I don't want to do 25 IF statements to check, so I want to use the players position to check if there are any sprites of that terrain type causing a collition with the player. That is why I tried the same x and y.

I need to know how I can get this working in a proper way.
Title: Re: How to create levels for a 2d jump 'n run game
Post by: Slydog on 2010-Jul-30
That SPRCOLL check is saying:
"Will the player sprite, if it was at (x,y) collide with a terrain sprite if it was also at (x,y)"
That should always return true, since with that check both sprites would always be overlapping.

Sprites don't really exist/persist anywhere, think of them more as a BitBlt (blit) function.
Ie, to display them you just tell GLBasic to copy the bitmap to the screen at a certain location.
After that, the sprite doesn't exist at that position.

So, in general, the SPRCOLL check is asking:
"If I were to place sprite 1 at position x1, y1, would it collide with sprite 2 if I positioned it at x2, y2?"

So, you would need 25 SPRCOLL checks if you have 25 different terrain tiles.
If the terrain is in a tile map, a simple nested for loop (row, column) could be set up to check if the player would be colliding with each terrain tile.

Title: Re: How to create levels for a 2d jump 'n run game
Post by: mrdremel on 2010-Jul-30
Quote from: Slydog on 2010-Jul-30
That SPRCOLL check is saying:
"Will the player sprite, if it was at (x,y) collide with a terrain sprite if it was also at (x,y)"
That should always return true, since with that check both sprites would always be overlapping.

Sprites don't really exist/persist anywhere, think of them more as a BitBlt (blit) function.
Ie, to display them you just tell GLBasic to copy the bitmap to the screen at a certain location.
After that, the sprite doesn't exist at that position.

So, in general, the SPRCOLL check is asking:
"If I were to place sprite 1 at position x1, y1, would it collide with sprite 2 if I positioned it at x2, y2?"

So, you would need 25 SPRCOLL checks if you have 25 different terrain tiles.
If the terrain is in a tile map, a simple nested for loop (row, column) could be set up to check if the player would be colliding with each terrain tile.

Thanks, that was the explaination I was looking for. I'll see if I can build something to check all the positions of my map pieces.

I'm fairly new to building a game with this. I created games before, but not with maps and characters moving around on the map.

I'll let you know how I'm doing with this.
Title: Re: How to create levels for a 2d jump 'n run game
Post by: FutureCow on 2010-Aug-03
I don't have time to do a full explaination, and you'll find it in numerous tutorials anyway, but here are my suggestions (and keep in mind there's a million ways to handle the problem).

Store your level as a 2D array, with the value in each array location indicating the type of tile in that location.
eg. array value = 0  : empty tile
1 : floor tile
2 : right hand wall and floor tile
3 : right hand wall only
etc

Each game loop, update which tile the player is in
(eg. if your tiles are 20x20, and your player is at pixel location (40,60), then they are on tile [2][3])

You also need to store your player offset in that tile
eg. If the player is at pixel location (46,66), they are in tile [2][3] (use integer division so you don't have returned that they are in tile[2.3][3.3] as floating values won't work with arrays). Then calculate their offset in the tile
ie. Player Y Offset = remainder from integer division of 66 / 20 = 6
So they're 6 pixels down in that tile.

If that particular array location indicates that the tile they're on is a floor tile, and you know the floor is at Y pixel location 10 in that tile, then they're obviously 4 pixels off the ground and you need to run your "make player fall" routine.

How would you use this?
In your game loop calculate the absolute tile they're in, then the offset within that tile. You can then do something like
if player on tile 0 (empty) then run make player fall code
if player on tile 1 (floor tile)
    if player y offset = 10 (ie. they're standing on the floor)
         if right arrow pressed
              make player walk to the right
         endif
    else
         they're above the floor so make them fall
    endif
endif
if player on tile 2 ...
etc.