Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reset()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.clear()
- term.setCursorPos(1,1)
- end
- function drawBG(type)
- if type == "space" then
- reset()
- for i=1,10 do
- print(" * * * * * * *")
- print("* * * * * ")
- print(" ' * * * ")
- print(" * * * * * * ")
- end
- elseif type == "earth" then
- reset()
- term.setCursorPos(1,1)
- print(" *---------------------------* ")
- print(" |//////// ////////////// | ")
- print(" |/////// ///// //////// | ")
- print(" |/////// //////////| ")
- print(" |/////// ///////////////| ")
- print(" |///// ////// //////| ")
- print(" | / ///// / //////| ")
- print(" | // / ////// / | ")
- print(" |// ////////// / / | ")
- print(" |/ /////// / | ")
- print(" | //// | ")
- print(" *---------------------------* ")
- end
- end
- function GameOver(score)
- reset()
- print("Game over!")
- print("Score:")
- print(score)
- textutils.slowPrint("Made by Aio in 2022")
- print("Thank you for playing!")
- sleep(0.5)
- end
- function play()
- reset()
- if math.random(0,100) < 50 then
- drawBG("earth")
- BG = "earth"
- else
- drawBG("space")
- BG = "space"
- end
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- AiYs = {}
- AiXs = {}
- playerX = 16
- playerHP = 3
- fireTurn = 0
- score = 0
- time = 120
- timePenelty = false
- PR = 0
- while true do
- score = score + 1
- time = time - 1
- --Ai turn
- --Ai move
- if #AiXs == 0 then
- AiXs = {4,8,12,16}
- AiYs = {2,2,2,2}
- end
- for i=1,#AiXs do
- if AiXs[i] > 24 then
- AiXs[i] = 0
- AiYs[i] = AiYs[i] + 2
- end
- if AiYs[i] > 16 then
- sleep(1)
- GameOver(score)
- break
- end
- AiXs[i] = AiXs[i]+4
- end
- --Ai Fire
- if fireTurn == 3 then
- for i=1,#AiXs do
- if playerX == AiXs[i] then
- playerHP = playerHP - 1
- end
- end
- fireTurn = 0
- else
- fireTurn = fireTurn + 1
- end
- --Render
- reset()
- drawBG(BG)
- if playerHP < 0 then
- GameOver(score)
- break
- elseif time < 0 then
- GameOver(score)
- break
- end
- term.setCursorPos(playerX,16)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.gray)
- print("@")
- for u=1,#AiXs do
- term.setCursorPos(AiXs[u],AiYs[u])
- term.setBackgroundColor(colors.red)
- print("V")
- for j=AiYs[u]+1,5 do
- term.setCursorPos(AiXs[u],j)
- print("|")
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("Score:",score,"Turns:",time,"Health:",playerHP,"Foes:",#AiXs,"Weapon %",(PR/5)*100)
- print("Move quickly!")
- if timePenelty then
- print("TIME PENELTY")
- end
- if fireTurn == 3 then
- term.setTextColor(colors.red)
- print(">>>[ FIRE TURN ]<<<")
- end
- --Players turn
- --Player move
- i=os.time()
- E,K = os.pullEvent()
- term.setCursorPos(1,2)
- term.clearLine()
- print("WAIT!")
- timePenelty = false
- if os.time() - i > 0.5 then
- timePenelty = true
- playerHP = playerHP - 0.5
- end
- sleep(0.2)
- if E == "key" then
- if K == keys.a or K == keys.left then
- if playerX > 4 then
- playerX = playerX - 4
- end
- elseif K == keys.d or K == keys.right then
- if playerX < 24 then
- playerX = playerX + 4
- end
- elseif K == keys.w or K == keys.up or K == keys.space or K == keys.enter and PR > 5 then
- --PlayerFire
- if PR > 5 then
- PR = PR - 5
- for u=1,#AiXs do
- if playerX == AiXs[u] then
- playerHP = playerHP + 0.5
- AiXs[u] = 0
- AiYs[u] = 0
- score = score + 10
- end
- end
- else
- print("Weapon % too low!")
- sleep(0.5)
- end
- end
- PR = PR + 1
- --end
- end
- end
- end
- function mainMenu()
- reset()
- print("Astroids")
- print("Made by Aio on july the 5:th of 2022")
- print("Press any key to play")
- os.pullEvent("key")
- play()
- end
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement