From e6981eff8d0b59c94107d58575ffd6e4512e6081 Mon Sep 17 00:00:00 2001 From: rebecca Date: Sun, 1 Mar 2026 10:07:23 +0000 Subject: worms --- worms.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'worms.lua') diff --git a/worms.lua b/worms.lua index 429191c..c4f6a8d 100644 --- a/worms.lua +++ b/worms.lua @@ -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 -- cgit v1.2.3