Collision Detection and Response for 2D Jump'n'Run - how?

Started by
1 comment, last by space_cadet 18 years, 11 months ago
Hi, I've coded a small engine for 2D games. It uses Direct3D to display 2D content on textured quads, and works very nicely. Now, all I need is a feasible way of managing collisions. Click here for a screenshot. The grey platform tiles you can see belong to a large "sprite" that consists of 32x24 tiles (meaning 32x24 textured quads). The main character is a sprite that consists of one single tile. Basically I'd like simple Giana Sisters / Super Mario - style gameplay. I'd love sloped tiles (like the one you see in the screenshot) very much. I'd prefer vector-based collision detection/response, but pixel-based is fine, if it works. Believe me, I've been breaking my head over this, PLEASE help ;-) Regards, Sebastian
Advertisement
Well the quick response would be to point you in the direction of jnrdev (jump'n'run dev). That site has a nice collection of tutorials covering exactly what you need, albeit using SDL.

However, I will add a few pointers. Firstly, it sounds like you are storing all your tiles in a single sprite class. This is counter-productive to the concept of a sprite class so I would suggest you create an appropriate classed such as a 'Map' class which could, in turn, contain lots of Tile objects or even Sprites acting as tiles. Furthermore, you probably don't want your player classed as a Tile. I would typically use something like the following for any small platformer.

An abstract CSprite class containing simple information that all players, enemies and pickups etc would use.

A CPlayer class to inherit from CSprite and to simply store the player specific information.

A CTile class to represent each individual tile. This could inherit from CSprite but some information within that class may be surplus to requirements

A CMap class which contains an array of all the Tile objects in your map.


Finally when it comes to the collision detection there is certainly no need for pixel based detection, a simple bounding box set-up (with some alterations for slopes) is perfectly do-able. So head over to jnrdev and I hope that is of some use.
I tried to make the post as short as possible, so I didn't go into my class structure. Your suggestions are already implemented :) I have a CSprite class, as well as a CMappedSprite class derived from CSprite. The tiles are represented by a CPanel class. The main character object is an extension of CSprite, and the platform object is an extension of CMappedSprite.

As to jnrdev: I had looked into this, but I didn't see the slope tutorial! This looks promising indeed. Thanks!

This topic is closed to new replies.

Advertisement