Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411275 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 08:17:32 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogs"I don't know yet" - 2D platformer
Pages: [1] 2
Print
Author Topic: "I don't know yet" - 2D platformer  (Read 6141 times)
vittorioromeo
Level 2
**



View Profile WWW
« on: June 28, 2011, 01:36:40 PM »

2D Platformer engine
AABB collision detection and resolving

Written in C#, using .NET Framework 4.0 and SFML.NET



Latest video







Youtube playlist

http://www.youtube.com/playlist?p=PLCBC4F0E90130D819

The playlist contains:
  • First prototype with lo-fi graphics
  • Super crate box clone
  • Newest unnamed game



Screenshots








Current features

  • AABB collision detection
  • AABB collision resolving (specific for platformers)
  • Quad-tree to speed up collision detection
« Last Edit: July 21, 2011, 04:36:49 PM by SuperV » Logged

BomberTREE
Level 9
****



View Profile
« Reply #1 on: June 28, 2011, 05:07:12 PM »

Oh boy! Intense knight fighting scene  Angry  Evil
Logged
Daniel Seabra
Level 1
*



View Profile WWW
« Reply #2 on: June 28, 2011, 07:40:43 PM »

I can't relate the first screenshot to the second at all. However, it is a pretty good gif you got going there :D

I need to get myself to bed so I didn't watch the video but keep updating! I'll be back  Ninja
Logged

I'm just some bloke. Going to go to Pasadena, CA, for four years so if you're over there gimme a shout-out. Will be cool to get to know some people.
vittorioromeo
Level 2
**



View Profile WWW
« Reply #3 on: June 29, 2011, 05:21:26 AM »

I can't relate the first screenshot to the second at all. However, it is a pretty good gif you got going there :D

The gif was just a prototype to test the physics Tongue
The "real game" is the one in the video and the screenshot
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #4 on: June 30, 2011, 06:05:26 AM »

Today I rewrote the physics engine. Now you can assign a collision group to every body, and ignore collision detection or ignore collision resolution with particular groups or even particular bodies.
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #5 on: June 30, 2011, 11:46:53 AM »

Switched to a quad-tree from a spatial hash. I've noticed performance increments! It also removes the width/height limitation of the spatial hash. I could have infinitely big maps in theory.
Added a cool looking background, debug zooming, large maps, scrolling.



Logged

vinheim3
Level 5
*****



View Profile
« Reply #6 on: June 30, 2011, 02:31:11 PM »

Flashing effect looks cool too, but what happened with the collision with the blob enemies? Looks like you can no longer use them as platforms.
Logged
vittorioromeo
Level 2
**



View Profile WWW
« Reply #7 on: June 30, 2011, 02:49:37 PM »

Flashing effect looks cool too, but what happened with the collision with the blob enemies? Looks like you can no longer use them as platforms.

That was unintended, so I removed it. It's easy to restore though.
Going to bed now. Created a simple level editor, implemented level saving/loading.

Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #8 on: July 01, 2011, 08:13:15 AM »





Video of the editor :D
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #9 on: July 02, 2011, 07:15:42 AM »

Made a lot of progress:
*Editor now supports all the tiles
*Tile preview in the editor greatly improved
*Editor is now layer-based (can place multiple objects on the same tile)
*Added decorations (fast-rendering entities without physical bodies)

The flickering sprites in the video have been fixed right after uploading.






EDIT:

I'm not done for today :D
Added a dynamic system that lets you add a list of arguments to any object in the editor. Maximum flexibility for any future in-game entity.

And to test that, I created a customizable text banner.



« Last Edit: July 02, 2011, 11:42:16 AM by SuperV » Logged

jeffrobot
Level 1
*



View Profile
« Reply #10 on: July 02, 2011, 08:45:52 PM »

Hey SuperV,

I really like your level editor. It looks pretty great. Making that level in like, under a minute is pretty sweet.

Did you use a tutorial or anything to learn the basics of making an editor? Or just figure it out for yourself? Or use a book? I'm looking for a way to learn how to do those. I'd like to make one for my own game.

Logged
vittorioromeo
Level 2
**



View Profile WWW
« Reply #11 on: July 03, 2011, 02:51:02 AM »

Hey SuperV,

I really like your level editor. It looks pretty great. Making that level in like, under a minute is pretty sweet.

Did you use a tutorial or anything to learn the basics of making an editor? Or just figure it out for yourself? Or use a book? I'm looking for a way to learn how to do those. I'd like to make one for my own game.

I figured it out myself. Here is how the editor works:

I have an hashtable that stores a single entity at a (X, Y, Layer).
By left clicking I place the selected entity in the hashtable at (X, Y, Layer).
By right clicking I remove any entity in the hashtable at (X, Y, Layer).

To find X and Y, I simply divide mouse coordinates by tile size.

I have a very long and inefficient switch{} that contains all the possible tiles. It's not elegant but it works. Every tile type as a specific ID number.

Every entity can also have an infinite amount of arguments.

To save, I loop through all entities, write number of arguments, write one argument per line, write x, y, layer.

To load, the same thing in reverse.

To load in the real game, I have another switch{} that converts a specific tile type ID to a game entity.
Logged

vinheim3
Level 5
*****



View Profile
« Reply #12 on: July 03, 2011, 03:57:41 AM »

I know of a more elegant solution where you won't need switch statements, but I'd need to know the reason behind the infinite number of arguments. What do you mean an entity can have these arguments?
Logged
vittorioromeo
Level 2
**



View Profile WWW
« Reply #13 on: July 03, 2011, 12:16:52 PM »

I know of a more elegant solution where you won't need switch statements, but I'd need to know the reason behind the infinite number of arguments. What do you mean an entity can have these arguments?

I totally removed the switch from the editor and I now use an external text file that holds data.

Arguments are additional "parameters" you give to entities. Some entities need 1 argument, some need 2, some can have infinite arguments.

I have a bid problem with the physics right now, you can check it out here if you want to help Sad http://www.facepunch.com/threads/1092921-What-do-you-need-help-with-V.-3.0?p=30869050&viewfull=1#post30869050
Logged

vinheim3
Level 5
*****



View Profile
« Reply #14 on: July 03, 2011, 04:51:32 PM »

How do you manage things now with the external file? Like how do you save, load, play in real game, place a tile onto the editor? etc. Also, still not getting the use of these parameters. Can you give an example?

About your collision problem, there's currently 2 things that are being handled wrongly. One is the fact that when you are on an object and the object drops, how you drop is handled by gravity rather than change in the object's x and y values. This means that it will look messy when your character is riding a platform downwards. It also means you will have to add additional unnecessary code for handling platforms that move from side to side, or in the case of Super Mario Bros 3, platforms that move diagonally or in curves.

The second might not be handled wrongly, but you might not be using the ideal collision technique that would prevent all sorts of weird effects if you are being crushed from 4 sides by spikes.

Here's how I would fix both:
1. a. Every step, see if there's an object below you and take note of its id or unique identifier.
b. Next step, calculate the difference between the object's previous co-ordinates and its current co-ordinates, if the player hasn't changed its vertical position (jumped or fallen off the platform). If it had changed its vertical position, reset the variable holding the id and do not perform step c. Apply gravity as required.
c. Check if the character can move in the same direction, if that spot is free from collision. If not, do not move it horizontally and check if it can slide down vertically the same amount as the platform (the platform would normally move the character into the left or right wall, do not move it horizontally, but allow it to drop). If not, do not move the character at all (even if the platform would move you into the bottom wall and horizontally some amount, you wouldn't slide the character horizontally, he would stay put, also if the wall you're checking is the upper wall, you might want to kill the character for being crushed between the upper wall and the platform).
d. Since you'll always be on top of the platform, gravity is only applied when there was no object now and you changed your vertical position.

2. When objects are colliding with you, take note of ALL the objects colliding with you, the difference between their previous co-ordinates and current co-ordinates, and total it. Attempt to move the character in that direction, applying sliding physics as before. If it can't slide, stay put. Mix with 1. Keep note if there is an object below you.

NOTE: When I say "the object below you", what if there are multiple objects below you moving in different directions? Choose the object whose midpoint is closest to the character's midpoint. If the 2 platforms have the same midpoint, choose any. The player will decide anyway when s/he moves by his/herself. All of this does take into account the character moving at the same time.

Hope it helps!
Logged
jeffrobot
Level 1
*



View Profile
« Reply #15 on: July 03, 2011, 10:26:14 PM »

Cool, thanks for taking the time to write that out for me. Sounds doable.
Logged
vittorioromeo
Level 2
**



View Profile WWW
« Reply #16 on: July 04, 2011, 07:08:24 AM »

How do you manage things now with the external file? Like how do you save, load, play in real game, place a tile onto the editor? etc. Also, still not getting the use of these parameters. Can you give an example?

I have a text file and every line contains the tile ID, tile name and description and the tileset sprite x/y. When I start up the editor, it creates an hashtable where all the information written in the text file is stored. So instead of having a switch, I simply look in the hashtable for an ID, and get the information I need. To save I simply write the ID and position of every tile. To load I take the ID from the saved map and look it up in the hashtable.



About your collision problem, there's currently 2 things that are being handled wrongly. One is the fact that when you are on an object and the object drops, how you drop is handled by gravity rather than change in the object's x and y values. This means that it will look messy when your character is riding a platform downwards. It also means you will have to add additional unnecessary code for handling platforms that move from side to side, or in the case of Super Mario Bros 3, platforms that move diagonally or in curves.

Correct. How would you solve this? I believe Box2D uses the gravity approach and a completely different type of bodies (kinematic) to create moving platforms.



The second might not be handled wrongly, but you might not be using the ideal collision technique that would prevent all sorts of weird effects if you are being crushed from 4 sides by spikes.

Here's how I would fix both:
1. a. Every step, see if there's an object below you and take note of its id or unique identifier.
b. Next step, calculate the difference between the object's previous co-ordinates and its current co-ordinates, if the player hasn't changed its vertical position (jumped or fallen off the platform). If it had changed its vertical position, reset the variable holding the id and do not perform step c. Apply gravity as required.
c. Check if the character can move in the same direction, if that spot is free from collision. If not, do not move it horizontally and check if it can slide down vertically the same amount as the platform (the platform would normally move the character into the left or right wall, do not move it horizontally, but allow it to drop). If not, do not move the character at all (even if the platform would move you into the bottom wall and horizontally some amount, you wouldn't slide the character horizontally, he would stay put, also if the wall you're checking is the upper wall, you might want to kill the character for being crushed between the upper wall and the platform).
d. Since you'll always be on top of the platform, gravity is only applied when there was no object now and you changed your vertical position.

2. When objects are colliding with you, take note of ALL the objects colliding with you, the difference between their previous co-ordinates and current co-ordinates, and total it. Attempt to move the character in that direction, applying sliding physics as before. If it can't slide, stay put. Mix with 1. Keep note if there is an object below you.

NOTE: When I say "the object below you", what if there are multiple objects below you moving in different directions? Choose the object whose midpoint is closest to the character's midpoint. If the 2 platforms have the same midpoint, choose any. The player will decide anyway when s/he moves by his/herself. All of this does take into account the character moving at the same time.

Hope it helps!

Sounds interesting. I will try this when I come back home and reply with results.
It sure helped! Thank you a lot Wink
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #17 on: July 05, 2011, 07:41:36 AM »

Before giving vinheim's method a try I've posted a recap of all the collision problems in this stackoverflow page

http://gamedev.stackexchange.com/questions/14486/2d-platformer-aabb-collision-problems/

Could someone take a look at it?
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #18 on: July 10, 2011, 03:17:00 PM »

Found a good workaround for the collision problems!





This is my first time adding a voice over to the video.
I'm Italian. My pronunciation is absolute crap. I tried my best to explain how I fixed the collision system but it's hard to understand.

Basically I'm using a new system that still has the "wall-jump/wall-stuck" bug. The bug doesn't occur if we test collisions with other bodies ordered by the Y position. This is an "hacky" solution but so far it works well with lifts, spikes and any moving object. Watch the video to see the result.
Logged

vittorioromeo
Level 2
**



View Profile WWW
« Reply #19 on: July 11, 2011, 12:16:27 PM »

Added a spring and made some minor changes. Collision is still not perfect (there are some minor bugs) but it's good enough for now.




[voiceover]
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic