aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/objs/player.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
index 2595304..ffc9fde 100644
--- a/src/objs/player.lua
+++ b/src/objs/player.lua
@@ -4,12 +4,14 @@ local PLAYER_ACCEL = 30
local PLAYER_JUMP_FORCE = 350
local PLAYER_DASH_TIMER = 0.15
local PLAYER_DASH_COOLDOWN = 0.5
+local PLAYER_MAX_JUMPS = 2
local COYOTE = 0.1
register_comp("Player", function(player)
player.jump_input_timer = 0
player.grounded_timer = 0
+ player.jumps = 0
end)
local function player_normal_state_init(state)
@@ -36,11 +38,12 @@ local function player_normal_state_update(player, state, dt)
player.sprite:set_tag("idle")
end
- if player.grounded_timer > 0 then
+ if player.jumps > 0 then
if player.jump_input_timer > 0 then
player.grounded_timer = 0
player.jump_input_timer = 0
player.vy = -PLAYER_JUMP_FORCE
+ player.jumps = player.jumps - 1
new_speck_entity(player.x, player.y, "res/speck/test.speck.lua")
end
end
@@ -48,6 +51,15 @@ local function player_normal_state_update(player, state, dt)
player.vy = -100
end
+ if player.grounded_timer > 0 then
+ player.jumps = PLAYER_MAX_JUMPS
+ else
+ -- going off the ledge removes a jump
+ if player.jumps == PLAYER_MAX_JUMPS then
+ player.jumps = player.jumps - 1
+ end
+ end
+
if state.dash_cooldown <= 0 and is_input_just_pressed("Dash") then
set_state(player, "Dash")
state.dash_cooldown = PLAYER_DASH_COOLDOWN