Sign in to follow this  

2D Platform Mario game collision.

This topic is 3575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have worked with tile collision and that is easy but i want to make some movable objects that my character can jump on??? What kind of collision do i need to use??? i Use SDL by the way.

Share this post


Link to post
Share on other sites
AABB*'s should be just fine for detecting collisions in a mario style game, you might want to pass in some direction vectors for the collision resolution though.

EDIT:
*Axis Aligned Bounding Box, or rectangular collision

Share this post


Link to post
Share on other sites
It is not specific to SDL. If you really wanted to, you could do AABB simulations in the command console... So you really need to try to understand the concept rather than the implementation until you grasp it firmly. If you are having troubles with the concepts, maybe try learning some underlying 3D vector math, try this book: http://www.amazon.com/exec/obidos/tg/detail/-/1584502770

Share this post


Link to post
Share on other sites
I dont have to to read a book i ave a dead line for a game of mine, and all has worked until i had the need to implement moving object collision... sh*t i need some help with this... preferably a SDL example but that is too much to ask for, a good explanation will do.. AND dont give me the N tutorials i dont understand that..

Share this post


Link to post
Share on other sites
Quote:
Original post by somebodykulj
I dont have to to read a book i ave a dead line for a game of mine, and all has worked until i had the need to implement moving object collision... sh*t i need some help with this... preferably a SDL example but that is too much to ask for, a good explanation will do.. AND dont give me the N tutorials i dont understand that..


Well! Why didn't you say so?! I'll just drop everything and try to spoon feed it to you. Here, this site has LOADS of infos.

Seriously, I didn't say you had to read the friggin book, I simply suggested it because if you can't understand a concept such as AABB it is obvious that there are gaps in your learning experience and a common topic that people skip over / don't really pay attention to in the beginning of game programming is the 3D mathematics involved and instead tend to copy + paste tutorials (which is why you want an "SDL" geared AABB tutorial) code in hopes that that will one day make them understand it.

Excuse me for trying to give you advice on how to better yourself and your understanding of core 3D concepts.

Share this post


Link to post
Share on other sites
Why do you come down so hard on me i said it is too much to ask for.. damn I know i have gaps in my knowledge i havent even started learning vectors and trigonometry in school how the hell should i know this sh*t...

Share this post


Link to post
Share on other sites
Nobody is going to give you the code you need. That's not what we're here for. We're here to point you in the right direction. Once we've done that, you're on your own. Besides, if you can't understand AABB collisions you're in over your head on this assignment. [sad]

Share this post


Link to post
Share on other sites
Ladies and gentleman i have been officialy fu*ked, i know AABB collision dont you worry about that, i was thinking about another type of collision that is implemented using vector projections and is used for both squares and all other shapes,it is a special type of colision that in the same function has a responce too... not the typical AABB function. I have writen that same function myself and it has not worked, doo to stuff beyond my controle and that is why i was hoping for some C++ code to see where i screwed up, but no matter now i have thought of a way of making this a little easyer by usign the rectangles center to make a good responce and the AABB system to check the collision.

Share this post


Link to post
Share on other sites
Yes something like that... but i was way over my head with that i will just use the standard AABB collision test.

Share this post


Link to post
Share on other sites
Well when doing rectangular box collision no specific API or library is need it's just a programming technique like a search, sort, or tree.

But if ya want some code that I guess this won't hurt.


//2 images we'll do check for colliision
SDL_Surface* mario;
SDL_Surface* mushroom;

//2 Rectangles holding the 2 image attributes of width, height, x, and y
SL_Rect* m_box;
SDL_Rect* mush_box;

//Get the attributes of the mario image store them in the pertaining rectangle.
m_box.x = 150;
m_box.y = 300;
m_box.width = 30;
m_box.height = 30;

//get the attributes of the mushroom image store them in the pertaining rectangle.
mush_box.x = 180;
mush_box.y = 300;
mush_box.width = 30;
mush_box.height = 30;

//Check to see if either (through rectangular collision) has hit.

//check to see if mario from the left is hitting mushroom from the right or vise versa
if(m_box.x + m_box.width >= mush_box.x)
if(mush_box.x + mush_box.width >= m_box.x)





Now instead of finishing my code just draw 2 rectangles on a piece of paper hitting from the left to the right vise versa, and from top to bottom and vise versa and logically analyze what it is saying using images with a given x, y, width and height.

Good Luck!

Share this post


Link to post
Share on other sites
Thanks, i wrota a function myself...

here it is but it doesent work :( WHY???

int check_cool_collision( SDL_Rect &A, SDL_Rect &B )
{

int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;

leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y + A.h;

leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;


if( bottomA <= topB )
{
return -23;
} else return 7;

if( topA >= bottomB )
{
return -23;
} else return 8;

if( rightA <= leftB )
{
return -23;
} else return 9;

if( leftA >= rightB )
{
return -23;
} else return 10;
}

i need this kind of collision that will tell me from which side did i hit the other rectangle.

Share this post


Link to post
Share on other sites
The concept of motion and direction will not be found from the coordinates of 2 simple rectangles. Think about this. If I made one piece of paper (rectangles) overlap another on a desk while you were out of the room and then you came into the room and I asked which piece of paper was moving and which direction did I move it from you would have no idea. In other words, this function you are using detects if a collision has happened, that is all you can and or should get from it.

In a rectangle collision scenario you should know the relative position and direction of the objects prior to collision. When an object collides with another object, what direction was it traveling in? What was the relative position of the other object right before they collided? With rectangle collision this is pretty simple when dealing with the 4 cardinal directions. For example, if the object was moving to the right and it collided with something, it more than likely hit it on the left side. This gets slightly more complicated when you move towards jumping in arcs or at non 90 degree angles but the concept is the same.

For an example of how to do "mario" style collision take a look here. That is about as simple as they come for this type of issue.

Share this post


Link to post
Share on other sites
Sign in to follow this