Sign in to follow this  
AniMerrill

Help with Platforming game?

Recommended Posts

AniMerrill    227
Alright, I'm going to come across as a total noob, but I just wanna say I'm really not. I can competently code in a variety of languages- C++, C#, Python, PHP, etc. -and understand a LOT of theory behind game design. However, for some reason, making the beginnings of a platforming game are kicking my ass. Now, I didn't search the forums here too thoroughly (although, a lot of the top results didn't seem to helpful) but I have searched the internet as a whole and cannot find ONE good example of how to create a very basic, barebones engine for an old school platformer game. I understand so much of the theory and concept, but when it comes to implementation... idk. It always bugs out on me, and I have to restart from scratch.

What I'm basically just trying to do is make a single screen, tile based platform engine that allows a player to navigate the stage just by walking and jumping. Usually where I get hung up is how to resolve a collision between the player and the tiles. I can usually handle walking into a wall, say, but when I have to start accounting for gravity and jumping, I often get a character that gets stuck in blocks, falls below the stage limit, will no longer be able to jump, etc.

I'm using XNA to make this game, which means C# is the language I'm writing this in, but I'm more concerned with learning the basic structure of this system rather than specific code.

Can anyone help? Please?

[b]EDIT: [/b]When I said "resolve collision" I didn't mean collision detection in general. I know how to check for a positive or negative AABB collision. My question is AFTER deciding that YES COLLISION HAS OCCURRED, I have no idea how to reconcile the player so they are not stuck inside a tile, and being able to automatically detect whether the character is falling onto the ground, hitting their head on a block, or running into a wall.

Share this post


Link to post
Share on other sites
boogyman19946    1487
This is kind of what coding is about isn't it? Turning problem solutions into code. Is there something particular you're stuck on? Try making a game instead of an engine. A platformer engine is a rather vague description of a program

Share this post


Link to post
Share on other sites
AniMerrill    227
[quote name='boogyman19946' timestamp='1307662772' post='4821525']
This is kind of what coding is about isn't it? Turning problem solutions into code. Is there something particular you're stuck on? Try making a game instead of an engine. A platformer engine is a rather vague description of a program
[/quote]

I'm just sort of surprised there's not one good tutorial for a basic platforming game out there. The specific problem I have is resolving a collision between the player and tile such that the player cannot get stuck inside a tile. That's basically it. I understand programming involves problem solving, I'm just sort of flustered after about three weeks of not even being able to make a basic, functioning character.

Share this post


Link to post
Share on other sites
boogyman19946    1487
Hah, don't worry, I'm the same way. I get stuck all the time.

Collision detection is a weird matter. I never really thought too hard about it. A common way to handle it is AABB collision detection (Axis-Aligned Bounding Box). Basically you surround your objects with bounding boxes and check if they overlap on any of the axes. It's hard for me to summarize the process as I haven't really read any articles. I remember just seeing a picture showing the technique and getting the light bulb.

EDIT: I believe it was [url="http://www.metanetsoftware.com/technique/tutorialA.html"]this tutorial[/url] that I was talking about.

Share this post


Link to post
Share on other sites
AniMerrill    227
[quote name='boogyman19946' timestamp='1307664790' post='4821535']
Hah, don't worry, I'm the same way. I get stuck all the time.

Collision detection is a weird matter. I never really thought too hard about it. A common way to handle it is AABB collision detection (Axis-Aligned Bounding Box). Basically you surround your objects with bounding boxes and check if they overlap on any of the axes. It's hard for me to summarize the process as I haven't really read any articles. I remember just seeing a picture showing the technique and getting the light bulb.
[/quote]

No no, I get collision detection, especially the whole AABB theory. What I want to know is basically how do you resolve it? How do you decide whether the character has fallen onto the top, hit one of the sides, or bumped his head on the bottom and then move him without him getting stuck or anything inside that tile (or another one)?

The one theory I heard (and liked quite a bit, until it broke) was one where you basically took the rectangle created by the two boxes colliding, found out whether the penetration was deeper height-wise or width-wise, and then move the character in the direction it was most shallow. The problem with that was the force of gravity usually made a deeper impact than walking did, which would cause the character to get stuck on the edge of blocks.

And that was the best system I found. Most everything else has been crap.

Share this post


Link to post
Share on other sites
Dr1fter    128
Can't really help too much without seeing the code, but if it's just basic rectangle collision your doing are you making sure when you detect a collision that the players position is moved to the position before the collision so you aren't stuck with the game thinking your constantly colliding therefor the players stuck.

e.g if you were walking right and hit into a tile:

if player intersects rectangle2
playerPosition.X = rect2Position.x - playerTextureWidth

//do whatever happens for collision

Share this post


Link to post
Share on other sites
AniMerrill    227
[quote name='Dr1fter' timestamp='1307665242' post='4821538']
//do whatever happens for collision
[/quote]

Obviously I've worded my question horribly. This is basically the part I'm looking for.

Share this post


Link to post
Share on other sites
boogyman19946    1487
I don't know what happened to the site, but it seems I lack any kind of CSS or javascript that was here before.

I had a similar problem. I happened to resolve it by taking the change in x and y and apply them separately to the objects. So take say, the change in x for the elapsed time, apply it, check collision. If collided, move up the objects to a position just before collision (snug it up to the colliding object). Then take change in y, rinse and repeat. I don't know a more efficient way.

Share this post


Link to post
Share on other sites
AniMerrill    227
[quote name='boogyman19946' timestamp='1307666021' post='4821544']
I don't know what happened to the site, but it seems I lack any kind of CSS or javascript that was here before.

I had a similar problem. I happened to resolve it by taking the change in x and y and apply them separately to the objects. So take say, the change in x for the elapsed time, apply it, check collision. If collided, move up the objects to a position just before collision (snug it up to the colliding object). Then take change in y, rinse and repeat. I don't know a more efficient way.
[/quote]

This seems to have worked to some degree. Thanks~

Share this post


Link to post
Share on other sites
shadowisadog    3217
One way I have done this in the past (at least for the vertical axis) is to create a loop in which I check if my player is overlapping a platform and then move the character up one pixel until the check fails to detect a collision. This is probably the least efficient way but it has the advantage of resolving the collision no matter how far the player is penetrating the platform (which in my experience can vary quite a bit!). I assume you could do similar for left/right/top edge cases too.

Here is some of the GML script I use for my GameMaker game:

[code]
{
test_obj = argument0;
temp_y = test_obj.y;
col_id = check_platform_collision(test_obj,temp_y,1);

if(col_id >= 0 && test_obj.vy > 0)
{
test_obj.vy = 0;
while(check_platform_collision(test_obj,temp_y,-1)>=0)
{
temp_y = temp_y - 1;
}
test_obj.jump = 0;
}

return temp_y;
}
[/code]

It's not the cleanist code in the world (it was made as an example for my middle school students, but more a demo rather than an open source project). You can follow similar logic for colliding with the top part of a platform:

[code]
collide_top = false;
while(!climb && collision_rectangle(x,y, x + sprite_width, y + 2, platform_base, false, true) > 0)
{
y += 1;
vy = abs(vy);
collide_top = true;
}
[/code]

Share this post


Link to post
Share on other sites
Zeophlite    144
I'd recommend this [url="http://wiki.allegro.cc/index.php?title=Pixelate:Issue_13/jnrdev"]http://wiki.allegro.cc/index.php?title=Pixelate:Issue_13/jnrdev[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this