aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent6d5e3252b51b096f88945cdb77f46d1128801d1f (diff)
Side scrolling controller
Diffstat (limited to 'src')
-rw-r--r--src/init.lua5
-rw-r--r--src/objs/player.lua20
2 files changed, 16 insertions, 9 deletions
diff --git a/src/init.lua b/src/init.lua
index 246147a..18299fd 100644
--- a/src/init.lua
+++ b/src/init.lua
@@ -10,12 +10,13 @@ require "src.room_editor"
SCR_WIDTH = 320
SCR_HEIGHT = 180
+GRAVITY = 1000
+TERMINAL_VELOCITY = 900
WindowScale = 1
register_input("Left", {{"key", "left"}, {"key", "a"}})
register_input("Right", {{"key", "right"}, {"key", "d"}})
-register_input("Down", {{"key", "down"}, {"key", "s"}})
-register_input("Up", {{"key", "up"}, {"key", "w"}})
+register_input("Jump", {{"key", "space"}})
register_input("Right_Click", {{"mouse", 2}})
register_input("Left_Click", {{"mouse", 1}})
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"},
})