aboutsummaryrefslogtreecommitdiff
path: root/src/objs/player.lua
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-03-13 19:42:48 -0400
committeriamcheeseman <[email protected]>2026-03-13 19:42:48 -0400
commite09caf3cf41ac3e3ea7ec252a21a7ac5b7fbb52c (patch)
tree7053899ad3c29d1483661af224bb3edb8c48b9cb /src/objs/player.lua
parent6d5e3252b51b096f88945cdb77f46d1128801d1f (diff)
Side scrolling controller
Diffstat (limited to 'src/objs/player.lua')
-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"},
})