player.lua×
main.lua×
collider.lua×
test_player.lua×
arena.json×
+3
1-- arena/main.lua — top-down arena prototype.
2-- Procedural sub-modules as plain fields. IDs, not refs.
3
4local player = class()
5
6function player:new(x, y)
7self.x, self.y = x, y
8self.hp = 5
9self.speed = 120
10self.fire_cd = 0.18
11make_entity(self) -- assign id, register
12self.timer = timer_new()
13self.spring = spring_new()
14+spring_add(self.spring, 'hit', 1)
15self.collider = collider(self, 'player', 'dynamic', 'box', 12, 12)
16end
17
Architect
refactor · split aim from move · 4 lines
Tabaccept
Escreject
⌘.diff
22−function player:update(dt) -- old: aim + move bundled
23−timer_update(self.timer, dt)
24−self.collider:sync()
25−if pressed('fire') then self:shoot() end
22+function player:update(dt)
23+timer_update(self.timer, dt)
24+spring_update(self.spring, dt)
25+self.collider:sync()
26+self:aim(dt)
27●self:move(dt) · then guard against fall-off-edge
Mmove(dt)method · player
Mmove_to(x, y, t)tween
Fmove_toward(x, y, dt)framework
Vmovement_speedfield
28if pressed('shoot') then self:shoot() end
29end
30
31function player:aim(dt)
32local mx, my = mouse_position()
33self.aim_a = math.atan2(my - self.y, mx - self.x)
34end
35
36function player:move(dt)
37local vx, vy = 0, 0
38if down('left') then vx = -self.speed end
39if down('right') then vx = self.speed end
40if down('up') then vy = -self.speed end
41if down('down') then vy = self.speed end
42●self.collider:set_velocty(vx, vy)● typo · expected
set_velocity lua_ls · E23243end
44
45function player:shoot()
46if self.timer.cd['fire'] > 0 then return end
47timer_after(self.timer, self.fire_cd, 'fire')
48bullet(self.x, self.y, self.aim_a)
49end