From 49f249d9f278a2d65b93548ae0b7f8b7cac2ea4e Mon Sep 17 00:00:00 2001 From: rebecca Date: Sun, 1 Mar 2026 10:05:34 +0000 Subject: worms --- worms.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'worms.lua') diff --git a/worms.lua b/worms.lua index af4160a..429191c 100644 --- a/worms.lua +++ b/worms.lua @@ -6,11 +6,14 @@ local M = peripheral.find"monitor" local W,H = M.getSize() 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 worm = {x=5,y=5,food=0} +local function new_worm() + return {x=math.random(W),y=math.random(H),food=0,colour=2^math.random(0,14)} +end +local worms = {} +for i=1,NWORMS do worms[i] = new_worm() end -- lsup local function metricd(dx,dy) return math.max(math.abs(dx),math.abs(dy)) end @@ -42,15 +45,15 @@ end local function draw_worm(worm) M.setBackgroundColor(colors.black) - M.setTextColor(colors.green) + M.setTextColor(worm.colour) M.setCursorPos(worm.x,worm.y) M.write("@") end while true do - tick_worm(worm) + for _,w in ipairs(worms) do tick_worm(w) end M.setBackgroundColor(colors.black) M.clear() draw_fruits() - draw_worm(worm) + for _,w in ipairs(worms) do draw_worm(w) end os.sleep(0) end -- cgit v1.2.3