Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local targetPos = {}
- local score = 0
- local hits = 0
- local misses = 0
- local maxX, maxY = term.getSize()
- local startTime = os.clock()
- local difficulty = 1
- local chain = 0
- local function getDifficulty()
- local function printButton(x,y,text)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(x,y)
- for i=1, string.len(text)+2 do
- write(" ")
- end
- term.setCursorPos(x,y+1)
- term.write(" ")
- term.write(text)
- term.write(" ")
- term.setCursorPos(x,y+2)
- for i=1, string.len(text)+2 do
- write(" ")
- end
- term.setBackgroundColor(colors.black)
- return
- end
- local function Button_pointCollideCheck(x,y,button)
- for i,v in ipairs(button) do
- local currentX, currentY = unpack(v)
- if x == currentX and y == currentY then
- return i
- end
- end
- return false
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- local buttons = {}
- term.setCursorPos(1,1)
- print("T A R G E T S H O O T I N G")
- print("")
- print("DIFFICULTY: ")
- print("")
- printButton(2, 5, "HARD")
- printButton(2, 9, "MEDIUM")
- printButton(2, 13, "EASY")
- while true do
- local event, button, x, y = os.pullEvent()
- if event == "mouse_click" then
- if (x >= 2 and x <=6) and (y >= 5 and y <= 9) then -- the lower, the harder
- difficulty = 0.75
- return
- elseif (x >= 2 and x <= 8) and (y >= 9 and y <= 13) then
- difficulty = 1
- return
- else
- difficulty = 1.25
- return
- end
- end
- end
- end
- getDifficulty()
- local function pointCollideCheck(x,y)
- for i,v in ipairs(targetPos) do
- local currentX, currentY = unpack(v)
- if x == currentX and y == currentY then
- return i
- end
- end
- return false
- end
- local function setTarget(x,y)
- targetPos = {
- {x,y}, {x+1,y}, {x+2,y},
- {x,y+1}, {x+1,y+1}, {x+2,y+1},
- {x,y+2}, {x+1,y+2}, {x+2,y+2},
- }
- for i,v in ipairs(targetPos) do
- local x,y = unpack(v)
- if x > maxX then
- return false
- elseif y > maxY-1 then
- return false
- end
- end
- return true
- end
- local function drawScreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- for i,v in ipairs(targetPos) do
- term.setCursorPos(unpack(v))
- if i == 5 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.white)
- end
- term.write(" ")
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, maxY)
- term.write("Score: "..score.." Hits: "..hits.." Misses: "..misses.." Accuracy: "..math.floor((hits/(hits+misses))*100).."%")
- term.setCursorPos(1,1)
- local multi = (chain/10)*1.5
- term.write("Chain: "..chain.." Multiplier: "..multi.." Playtime: "..(math.floor((os.clock()-startTime)*10)/10).."s")
- end
- local function game_logicThread()
- math.randomseed(os.clock())
- local firstX = math.random(1, maxX-3)
- local firstY = math.random(2, maxY-3)
- setTarget(firstX, firstY)
- local timer = os.startTimer(difficulty)
- while true do
- local event, param1, param2, param3 = os.pullEvent()
- if event == "mouse_click" then
- term.setCursorPos(param2, param3)
- local x = param2
- local y = param3
- local collide = pointCollideCheck(x,y)
- if collide then
- if collide == 5 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.white)
- end
- term.setTextColor(colors.orange)
- term.write("*")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- chain = chain+1
- hits = hits+1
- local multi = (chain/10)*1.5
- if collide == 5 then
- if multi >= 1 then
- score = score+(multi*2)
- else
- score = score+2
- end
- else
- if multi >= 1 then
- score = score+multi
- else
- score = score+1
- end
- end
- targetPosTable = {}
- math.randomseed(os.clock())
- local newX = math.random(1, maxX-3)
- local newY = math.random(2, maxY-3)
- setTarget(newX, newY)
- timer = os.startTimer(difficulty)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.orange)
- term.write("*")
- term.setTextColor(colors.white)
- score = score-1
- misses = misses+1
- chain = 0
- end
- elseif event == "timer" and param1 == timer then
- score = score-1
- chain = 0
- targetPosTable = {}
- math.randomseed(os.clock())
- local newX = math.random(1, maxX-3)
- local newY = math.random(2, maxY-3)
- setTarget(newX, newY)
- timer = os.startTimer(difficulty)
- end
- end
- end
- local function game_drawThread()
- while true do
- drawScreen()
- os.sleep(0)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- parallel.waitForAll(game_logicThread, game_drawThread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement