Anchor code · arena
workspace/ code/ arena/ main.lua
build 0.42s tests 42 pass lsp lua_ls 3.7 14:23
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
22function player:update(dt) -- old: aim + move bundled
23timer_update(self.timer, dt)
24self.collider:sync()
25if 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)
27self: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
42self.collider:set_velocty(vx, vy) typo · expected set_velocity lua_ls · E232
43end
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
Problems 1 2
Terminal arena
Build ●0.42s
Tests 42 / 0
Output
~/anchor2/arena bash attached
~/anchor2/arena $ ./anchor.exe . --headless --verify
[engine] sdl init ok · audio ok · input ok
[engine] physics step 1/1 · entities 12 · colliders 13
[engine] render frame 1 · drawcalls 14 · 0.018s
[verify] all systems nominal · exit 0
~/anchor2/arena $ lua54 -e "loadfile('main.lua')"
main.lua:42: attempt to call a nil value (method 'set_velocty')
stack traceback:
main.lua:42: in function 'move'
main.lua:27: in function 'update'
~/anchor2/arena $