Log In  

Hey everyone,

I recently purchased Pico-8 and am loving it. I am breezing through the few tutorials there are on the internet and am starting to wonder how many of you have implemented physics engines to handle things such as gravity and the like.
I have been looking at other people's code and getting a bit of a clue but am feeling a little overwhelmed :<.

Any resources would be great as I want to learn how to do this for real so I can grow as a developer.

Thanks!

Edit: Just looking for something simple how when the player jumps, to have him come back down

P#26396 2016-08-03 16:38 ( Edited 2016-08-04 01:50)

A full physics system is sort of taking the properties and collision for the player in a normal game, and duplicating that for every single object in the physics system.

Most games tend to reserve that level of detail for the player object, using states to help categorize and limit what calculations are needed each frame. (and then use good-enough temporary systems for everything else, like particle debris that guesses where the floor might be, enemies that can't shoot each other, etc)

edit: The closest to a physics system I think I've seen so far is the (awesome) combo pool from jam #2.

reedit: check out the "Example Cartridges" section of the manual, and dig into good ol' Jelpi.

make_actor() sets up all of the basic variables that need to be tracked. (and is called by make_player(), which adds the more-special player-only variables to the mix) The unlabeled parts are X and Y (coordinates/location) and DX/DY which is short for delta x which means change in x, which is usually speed in pixels-per-update.

The bulk of the action happens in move_player() and move_actor(). Move_actor is pretty straightforward. Move_player is the one that grabs input, and also has all the extra effects and actions, so it takes a while to work through. (try commenting out entire sections to narrow down or identify what's what.)

example bare-bones code off the cuff:

player={x=64,y=64,dx=0,dy=0}
gravity=1
function _update()
--get keys
 if (btn(0)) player.dx=-2
 if (btn(1)) player.dx=2
 if (btn(5)) player.dy=-4 --not quite a jump, more a "hold button to fly upwards"
player.x+=player.dx
player.y+=player.dy
player.dy=min(player.dy+gravity,4) --max fall speed of 4
--hard-coded ground level collision:
if (player.y>64) player.y=64 player.dy=0
end
function _draw()
 cls()
 spr(1,player.x,player.y)
end
P#26397 2016-08-03 17:38 ( Edited 2016-08-03 23:24)
:: gigs

Thanks tyroney :3

P#26423 2016-08-03 21:50 ( Edited 2016-08-04 01:50)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-05-19 02:48:36 | 0.007s | Q:12