summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--worms.lua9
1 files changed, 6 insertions, 3 deletions
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