summaryrefslogtreecommitdiff
path: root/worms.lua
diff options
context:
space:
mode:
Diffstat (limited to 'worms.lua')
-rw-r--r--worms.lua13
1 files changed, 8 insertions, 5 deletions
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