diff options
| author | rebecca <ubq323@ubq323.website> | 2026-03-01 10:05:34 +0000 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-03-01 10:05:34 +0000 |
| commit | 49f249d9f278a2d65b93548ae0b7f8b7cac2ea4e (patch) | |
| tree | e338382f07fb68d84cb3b5ca047d4f5f81e599d8 | |
| parent | 022f0e94c522fcc6804fc08e04880926a44dc999 (diff) | |
worms
| -rw-r--r-- | worms.lua | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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 |
