aboutsummaryrefslogtreecommitdiff
path: root/src/objs/player.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/objs/player.lua')
-rw-r--r--src/objs/player.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
index 84e42f0..7812486 100644
--- a/src/objs/player.lua
+++ b/src/objs/player.lua
@@ -5,7 +5,12 @@ local PLAYER_JUMP_FORCE = 350
local PLAYER_DASH_TIMER = 0.15
local PLAYER_DASH_COOLDOWN = 0.5
-register_comp("Player", TAGCOMP)
+local COYOTE = 0.1
+
+register_comp("Player", function(player)
+ player.jump_input_timer = 0
+ player.grounded_timer = 0
+end)
local function player_normal_state_init(state)
state.dash_cooldown = 0
@@ -31,14 +36,13 @@ local function player_normal_state_update(player, state, dt)
player.sprite:set_tag("idle")
end
- if player.box:touching_down() then
- if is_input_just_pressed("Jump") then
+ if player.grounded_timer > 0 then
+ if player.jump_input_timer > 0 then
player.vy = -PLAYER_JUMP_FORCE
end
- else
- if is_input_just_released("Jump") and player.vy < -100 then
- player.vy = -100
- end
+ end
+ if not is_input_pressed("Jump") and player.vy < -100 then
+ player.vy = -100
end
if state.dash_cooldown <= 0 and is_input_just_pressed("Dash") then
@@ -75,6 +79,16 @@ function player_update_sys(player, dt)
if player.vx ~= 0 then
player.scalex = sign(player.vx)
end
+
+ player.jump_input_timer = player.jump_input_timer - dt
+ if is_input_just_pressed("Jump") then
+ player.jump_input_timer = COYOTE
+ end
+
+ player.grounded_timer = player.grounded_timer - dt
+ if player.box:touching_down() then
+ player.grounded_timer = COYOTE
+ end
end
function new_player(x, y)
@@ -86,7 +100,7 @@ function new_player(x, y)
offsetx = -4,
offsety = -6,
layers = {},
- mask = {"Hard"},
+ mask = { "Hard" },
})
add_comp(ent, "Sprite", "res/img/player.ase", {
@@ -108,4 +122,3 @@ function new_player(x, y)
return ent
end
-