Skip to content

Instantly share code, notes, and snippets.

@Kaiochao
Created September 9, 2015 09:55
Show Gist options
  • Save Kaiochao/0c7f47f5d37a28067f2d to your computer and use it in GitHub Desktop.
Save Kaiochao/0c7f47f5d37a28067f2d to your computer and use it in GitHub Desktop.
entity/platformer
var
max_speed
axis_smoothing
gravity = 2
jump_speed = 10
jump_time = 3
fall_jump_time = 2 // time after leaving the ground that you can still jump
tmp
axis_x = 0
velocity_x = 0
velocity_y = 0
last_ground_time = -1#INF
jumping = FALSE
Update()
/// horizontal
axis_x = lerp(axis_x, client.GetAxis("d", "a"), axis_smoothing)
if(velocity_x)
if(!Translate(velocity_x, 0))
velocity_x = 0
if(axis_x)
Translate(max_speed * axis_x, 0)
/// vertical
if(IsGrounded())
velocity_y = 0
last_ground_time = world.time
else
velocity_y -= gravity
var jump_input = client.IsKeyDown("space")
if(jump_input)
if(world.time - last_ground_time < fall_jump_time)
jumping = TRUE
else if(world.time - last_ground_time > jump_time)
jumping = FALSE
else
jumping = FALSE
if(jumping)
velocity_y = jump_speed
if(velocity_y)
if(!Translate(0, velocity_y))
velocity_y = 0
jumping = FALSE
proc
IsGrounded()
// check row of pixels directly below bounds for uncrossable atoms
for(var/atom/a in obounds(src, 0, -1, 0, 1-bound_height))
if(isturf(a))
if(!a.Enter(src, loc))
return TRUE
else if(istype(a, /atom/movable))
if(!a:Cross(src))
return TRUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment