Advertisement

plattform games

Started by May 09, 2001 12:21 PM
9 comments, last by lastms 23 years, 9 months ago
I have a queastion about plattform games. How do you do to make the game objects move upp when it hits sloping hills and so on? Is it some kind of collision detection or what?
Assuming that your game is tile based then supply a line segment for your tile and calculate the slope of this. So store, assuming again that this is a 2D game, x1,y1 - x2-y2 of the line
against a tile.

You could then use Bresenhams algorithm to make your sprites follow the line. First check if your sprite collides with the tile and then look up if it has a line segment attached to it then do an intersect test with the line , so you want to store the slope of the line because it will remain fixed and you can store that as well.

The other option is to supply a rough grid of rectangles overlaid on your tile map to "snap" your sprite to these spatially sorted rectangles. This would approximate the movement.

I wish I knew how to draw diagrams in this thing.






Advertisement
Ahh, so that''s how it''s done. I''ve had that problem in the back of my mind for weeks, but was planning to try and figure it out on my own instead of asking. My plan was to have a list of lines and check against those, but I guess tile-based would be faster, since most things won''t be slanted anyway.



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)
Yes and you can store multiple line segments against a tile as well.

I did a Moon Buggy clone once and the vehicle had to follow the terrain but only an approximation. The straight line approach worked well and gave the "illusion" that the buggy was following the terrain. The game did not check the tiles but another structure which supplemented the tiles. Think of it as an overlay structure

Basically...

_____..............______

....._____ .....______
......... _______

I just know this is not going to preserve the spaces!!! _ is
the line and . is well a space!!

So the buggy would snap to those lines. Phew!!!





Edited by - ancientcoder on May 10, 2001 7:16:34 PM
Hmm, I think I get it...
The way I was thinking about was to have a list of lines (sorted from the start to the end of the level, so I could just check their end points until I found one past the character, then check him against it and eevry other line until I got to one that started past him), which might actually work, but it would probably be faster just to use tile-based with line segments, to avoid the end-point checking process. Plus (once I make a map editor), it''d be harder to edit the line list instead of just clicking on a tile to make it an obstruction, and if needed, click add line segment, click the start and end points, and move on.
Hmm, or maybe not. The line list would be simpler to do big hills in, cause you could just click the start, then the end, which would be many tiles away instead of having to carefully pick the right pixel to start on each one to get a nice consistent slope.
..now I''m all confused on what to do...



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)
I would suggest storing the line against the tile. I did this for a platform game and it was easy creating maps.

Your mountain contains more or less the same slope blocks so
when you are punching tiles in the line is quickly there. Plus
if you make a modification to the base tile then the instantces
of all the other tiles in the map get that info.

So rapid changes through your level are propogated. Plus putting
things like block copy,cut and paste in your level make it easier as well.

I you wanted to shift your mountain over to the right then with an overlaid vector you would have a nightmare, however with a tile that has a collection of slopes you dont have to bother.

The collision speed up , as you have pointed out, is also a very big plus.


Advertisement
Before you start making a platform game make sure you study the greatest 2d platform games of all time first.

Super Mario World - 2d platform perfection

Yoshi''s Island (Super Mario World 2) - Wonderfully inventive childlike , card board cut out style graphics + artwork. Cool special effects and level design and a very unusual control system. There is more imagination in one level of this game than most platformers manage in the entire game.

Ghouls and Ghosts (arcade) Fantastic action platform game.

Sonic the Hedgehog
Super Mario 3
Revenge of Shinobi

Obviously there are many more but the important point is this. Great games always depend more on skill than luck. When you die in Super Mario World it is always you fault and that is why it''s so good. Games should be hard but fair. Please don''t have any ''leaps of faith'' in your game.
Good luck.



Before I knew how this was done by others, I made up my own way to handle this. I hard coded these "line segments" that people are talking about into the tile types. I only support 45-degree angles though. So I have 6 possible tile shapes: Solid, uphill (diagonal from lower left to upper right; lower right half filled), downhill, up ceiling (line from lower left corner to upper right corner; top left half filled), down ceiling and empty.

I have a function that returns whether an individual pixel in a tile is solid or not based on tile coordinates and the shape of the tile. 45-degree diagonal lines are pretty simple. There''s another function (possibly the most complicated and tweaked one I''ve ever written) that forces a rectangular sprite to react to this solidity. It can walk uphill and downhill, be pushed down sloped ceilings and catch onto ledges where only a one-tile-high space exists, while falling. This is all implemented in the open source project The Scrolling Game Development Kit which is also in the GameDev Showcase here.

"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"
If the game calculates tile collision to the pixel, instead of having lines preset for each tile, make it so whenever the character hits a pixel side on, test the pixel above it and if its not solid, move the character up one pixel whilst keeping its horizontal velocities. I havent actually coded it in my game yet but to me this seems the logical/easy way to do it.

My web page: www.geocities.com/neoseeka

  Downloads:  ZeroOne Realm

quote:
Original post by SikCiv
If the game calculates tile collision to the pixel, instead of having lines preset for each tile, make it so whenever the character hits a pixel side on, test the pixel above it and if its not solid, move the character up one pixel whilst keeping its horizontal velocities. I havent actually coded it in my game yet but to me this seems the logical/easy way to do it.



That''s kind of what *I* did, except if you know that you''re only dealing with 45-degree angles you can set the Y velocity equal to +/- X velocity when you encounter a slope. Otherwise, if your X velocity is 2, setting Y velocity to -1 won''t go up far enough. Also, I prefer to set the Y *velocity* and not just move the position up, because then you can do things like fly off of ramps in the right direction.


"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"

This topic is closed to new replies.

Advertisement