diff options
| author | rebecca <ubq323@ubq323.website> | 2026-03-01 10:07:23 +0000 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-03-01 10:07:23 +0000 |
| commit | e6981eff8d0b59c94107d58575ffd6e4512e6081 (patch) | |
| tree | c1daeced64bc1219c26e826244edc81e1d5fff3d | |
| parent | 49f249d9f278a2d65b93548ae0b7f8b7cac2ea4e (diff) | |
worms
| -rw-r--r-- | worms.lua | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -9,9 +9,10 @@ local function new_fruit() return {math.random(W), math.random(H)} end local fruits = {} for i=1,NFRUITS do fruits[i] = new_fruit() end -local function new_worm() - return {x=math.random(W),y=math.random(H),food=0,colour=2^math.random(0,14)} -end +local function new_worm() return { + x=math.random(W),y=math.random(H), + colour=2^math.random(0,14), + food=0, timer=0} end local worms = {} for i=1,NWORMS do worms[i] = new_worm() end @@ -26,6 +27,7 @@ local function draw_fruits() for i,f in ipairs(fruits) do end end local function tick_worm(worm) + if worm.timer > 0 then worm.timer = worm.timer -1 return end local x,y = worm.x, worm.y for i,f in ipairs(fruits) do f.dist = metric(x,y, f[1],f[2]) end table.sort(fruits, function(f,g) return f.dist < g.dist end) @@ -34,6 +36,7 @@ local function tick_worm(worm) table.remove(fruits, 1) table.insert(fruits, new_fruit()) worm.food = worm.food + 1 + worm.timer = 7 else local dx,dy = 0,0 local tx,ty = target[1]-x,target[2]-y |
