add hammered stuff

This commit is contained in:
LordMZTE 2022-03-08 23:14:25 +01:00
parent 0aa4c6a9e6
commit cf78e9bef3
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 122 additions and 0 deletions

View file

@ -0,0 +1,103 @@
local screen = peripheral.find "monitor"
rednet.open "top"
local cmd = commands.exec
local running = false
local timer = 1800 -- 30 mins
screen.setTextScale(3)
local function pad_digits(n)
if n < 10 then
return "0" .. n
else
return tostring(n)
end
end
local function format_timer()
return pad_digits(math.floor(timer / 60)) .. ":" .. pad_digits(timer % 60)
end
local function draw()
screen.setBackgroundColor(colors.black)
screen.clear()
screen.setCursorPos(9, 1)
screen.write "HAMMERED!"
screen.setCursorPos(11, 3)
screen.write(format_timer())
screen.setCursorPos(1, 5)
screen.setBackgroundColor(colors.lime)
screen.write "Start"
screen.setCursorPos(7, 5)
screen.setBackgroundColor(colors.orange)
screen.write "Reset"
screen.setCursorPos(13, 5)
screen.setBackgroundColor(colors.red)
screen.write "Place Chests"
screen.setCursorPos(7, 6)
screen.setBackgroundColor(colors.red)
screen.write "Clear Arena"
end
draw()
local function place_chests()
cmd "clone 997 62 971 997 62 971 1019 50 981"
cmd "clone 997 62 971 997 62 971 981 50 981"
cmd "clone 997 62 971 997 62 971 1019 50 1019"
cmd "clone 997 62 971 997 62 971 981 50 1019"
end
local function clear_arena()
cmd "fill 1013 50 975 1024 255 986 air"
cmd "fill 986 50 986 976 255 976 air"
cmd "fill 986 50 1024 976 255 1014 air"
cmd "fill 1024 50 1024 1014 255 1014 air"
cmd "kill @e[type=item]"
end
local function set_timer(n)
timer = n
rednet.broadcast(format_timer(n), "set_timer")
end
parallel.waitForAny(function()
while true do
local _, _, x, y = os.pullEvent "monitor_touch"
if y == 5 then
if x >= 1 and x <= 5 then -- start
running = true
elseif x >= 7 and x <= 11 then -- reset
set_timer(1800)
running = false
elseif x >= 13 and x <= 25 then -- place chests
place_chests()
end
elseif y == 6 then
if x >= 7 and x <= 18 then -- clear arena
clear_arena()
end
end
draw()
end
end, function()
while true do
if running then
if timer <= 0 then
cmd [[title @a title {"text": "Time's up!", "color": "red"}]]
rednet.broadcast(0, "sound_alarm")
running = false
else
set_timer(timer - 1)
end
end
draw()
os.sleep(1)
end
end)

View file

@ -0,0 +1,19 @@
local screen = peripheral.find "monitor"
rednet.open "top"
screen.setTextScale(5)
screen.write "30:00"
while true do
local _, t, proto = rednet.receive()
if proto == "set_timer" then
screen.clear()
screen.setCursorPos(1, 1)
screen.write(t)
elseif proto == "sound_alarm" then
rs.setOutput("bottom", true)
os.sleep(0.1)
rs.setOutput("bottom", false)
end
end