aboutsummaryrefslogtreecommitdiff
path: root/src/objs
diff options
context:
space:
mode:
Diffstat (limited to 'src/objs')
-rw-r--r--src/objs/player.lua20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
index 58e5f3a..1d89f8a 100644
--- a/src/objs/player.lua
+++ b/src/objs/player.lua
@@ -1,4 +1,6 @@
PLAYER_SPEED = 100
+PLAYER_ACCEL = 30
+PLAYER_JUMP_FORCE = 350
register_comp("Body", function (ent, x, y, w, h, opts)
ent.vx = 0
@@ -15,17 +17,21 @@ function body_sys(ent, dt)
end
function player_movement_sys(player, dt)
- local inpx, inpy = input_direction("Left", "Right", "Up", "Down")
- inpx, inpy = normalize(inpx, inpy)
- player.vx = dlerp(player.vx, inpx * PLAYER_SPEED, 25 * dt)
- player.vy = dlerp(player.vy, inpy * PLAYER_SPEED, 25 * dt)
+ local inputx = bton(is_input_pressed("Right")) - bton(is_input_pressed("Left"))
+
+ player.vx = dlerp(player.vx, inputx * PLAYER_SPEED, PLAYER_ACCEL * dt)
+ player.vy = math.min(player.vy + GRAVITY * dt, TERMINAL_VELOCITY)
+
+ if player.box:touching_down() and is_input_just_pressed("Jump") then
+ player.vy = -PLAYER_JUMP_FORCE
+ end
end
function new_player(x, y)
local ent = new_entity()
- add_comp(ent, "Body", x, y, 16, 16, {
- offsetx = -8,
- offsety = -8,
+ add_comp(ent, "Body", x, y, 8, 14, {
+ offsetx = -4,
+ offsety = -6,
layers = {},
mask = {"hard"},
})