aboutsummaryrefslogtreecommitdiff
path: root/src/objs
diff options
context:
space:
mode:
authorne_mene <[email protected]>2026-03-08 22:21:42 +0100
committerne_mene <[email protected]>2026-03-08 22:21:42 +0100
commitb744faa2e42ed37459fe3edb69c1149146233e5b (patch)
tree25f238d3e467c7cf43e619b579e0df89762b1cca /src/objs
parent95d50b15634bf4799a2005e381d82c110fbff39b (diff)
let there be light
Diffstat (limited to 'src/objs')
-rw-r--r--src/objs/player.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
new file mode 100644
index 0000000..229dac9
--- /dev/null
+++ b/src/objs/player.lua
@@ -0,0 +1,32 @@
+PLAYER_SPEED = 100
+
+register_comp("Body", function (ent, x, y)
+ ent.x = x
+ ent.y = y
+ ent.vx = 0
+ ent.vy = 0
+end)
+
+register_comp("Player", TAGCOMP)
+
+function body_sys(ent, dt)
+ ent.x = ent.x + ent.vx * dt
+ ent.y = ent.y + ent.vy * dt
+end
+
+function draw_sys(ent)
+ love.graphics.circle("fill", ent.x, ent.y, 8)
+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)
+end
+
+function new_player(x, y)
+ local ent = new_entity()
+ add_comp(ent, "Body", x, y)
+ add_comp(ent, "Player")
+end