Log In  


Cart #eniplatformsample-0 | 2019-11-01 | Code ▽ | Embed ▽ | No License
29

Made a sample platformer, mostly to show how to do things like collisions, camera, jump buffering, and slopes. I wrote this to be clear rather than to save tokens, and it has no real gameplay to keep the core of the engine as clear as possible.

The code for this cart can also be found on github and is MIT licensed.

Features:

  • Movement and jumping
  • Collision checking and resolution
  • Jump buffering
  • Slopes
  • Platforming camera
29


Your camera is good. The ability to not track the vertical camera until the player has landed on an upper or lower solid surface is the right way to do it.

You might add a 45-degree angle slope where the player slides down with gravity.


This is a great reference. Code is really readable which is key.

Also had never thought about the camera tracking thing - something else learned!


The platforming camera is a really neat effect.


iT'S paC-MAn


cool


Like it


Great resource! I was struggling with collision glitches in my platformer. I didn't want to believe that breaking the physics update into sub-frame steps was necessary (or even practical in PICO-8), but you demonstrated a very intuitive way to do it and helped me get over my mental block. Thank you so much!

For the slopes, I found what appears to be a bug. Well it would be a bug, if it weren't for a typo that undoes it lol. Take a look at Line 217:
if entity.y < tiletop and not wasonground and not jumping then
jumping isn't referenced anywhere else in the code, so it's always nil. player does contain a variable called jumping, but that's not what you're referencing here. To confirm, if you change it to entity.jumping like this:
if entity.y < tiletop and not wasonground and not entity.jumping then
then the character is sometimes unable to jump while standing on a slope. Also, if you remove that condition like this:
if entity.y < tiletop and not wasonground then
then it appears to work exactly the same as it did originally.
In other words, since 'jumping' is always nil (falsy), 'not jumping' is always true, meaning and-ing it with any other condition just returns the other condition.

I know this post is 6 years old and you probably haven't thought about it since then, and sorry if I over explained. I had 'player.jumping' in my code, which of course doesn't work, so I spent several hours banging my head trying to figure out why my code doesn't work when yours does. So I just wanted to point this out in case anyone else uses this wonderful example.

Anyway, thanks again! The way you wrote the code is very intuitive and showed me Lua techniques I'd never even heard of. Great job!

Edit: forgot to mention, but using multiple colliders on the player to distinguish wall collisions from floor and ceiling collisions is absolutely genius!



[Please log in to post a comment]