Advertisement
LazerAio

Astroids.lua

Jul 5th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. function reset()
  2. term.setBackgroundColor(colors.black)
  3. term.setTextColor(colors.green)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. end
  7.  
  8. function drawBG(type)
  9. if type == "space" then
  10. reset()
  11. for i=1,10 do
  12. print(" * * * * * * *")
  13. print("* * * * * ")
  14. print(" ' * * * ")
  15. print(" * * * * * * ")
  16. end
  17. elseif type == "earth" then
  18. reset()
  19. term.setCursorPos(1,1)
  20. print(" *---------------------------* ")
  21. print(" |//////// ////////////// | ")
  22. print(" |/////// ///// //////// | ")
  23. print(" |/////// //////////| ")
  24. print(" |/////// ///////////////| ")
  25. print(" |///// ////// //////| ")
  26. print(" | / ///// / //////| ")
  27. print(" | // / ////// / | ")
  28. print(" |// ////////// / / | ")
  29. print(" |/ /////// / | ")
  30. print(" | //// | ")
  31. print(" *---------------------------* ")
  32. end
  33. end
  34. function GameOver(score)
  35. reset()
  36. print("Game over!")
  37. print("Score:")
  38. print(score)
  39. textutils.slowPrint("Made by Aio in 2022")
  40. print("Thank you for playing!")
  41. sleep(0.5)
  42. end
  43. function play()
  44. reset()
  45. if math.random(0,100) < 50 then
  46. drawBG("earth")
  47. BG = "earth"
  48. else
  49. drawBG("space")
  50. BG = "space"
  51. end
  52. term.setCursorPos(1,1)
  53. term.setTextColor(colors.white)
  54. AiYs = {}
  55. AiXs = {}
  56. playerX = 16
  57. playerHP = 3
  58. fireTurn = 0
  59. score = 0
  60. time = 120
  61. timePenelty = false
  62. PR = 0
  63. while true do
  64. score = score + 1
  65. time = time - 1
  66. --Ai turn
  67. --Ai move
  68. if #AiXs == 0 then
  69. AiXs = {4,8,12,16}
  70. AiYs = {2,2,2,2}
  71. end
  72. for i=1,#AiXs do
  73. if AiXs[i] > 24 then
  74. AiXs[i] = 0
  75. AiYs[i] = AiYs[i] + 2
  76. end
  77. if AiYs[i] > 16 then
  78. sleep(1)
  79. GameOver(score)
  80. break
  81. end
  82. AiXs[i] = AiXs[i]+4
  83. end
  84. --Ai Fire
  85. if fireTurn == 3 then
  86. for i=1,#AiXs do
  87. if playerX == AiXs[i] then
  88. playerHP = playerHP - 1
  89. end
  90. end
  91. fireTurn = 0
  92. else
  93. fireTurn = fireTurn + 1
  94. end
  95. --Render
  96. reset()
  97. drawBG(BG)
  98. if playerHP < 0 then
  99. GameOver(score)
  100. break
  101. elseif time < 0 then
  102. GameOver(score)
  103. break
  104. end
  105. term.setCursorPos(playerX,16)
  106. term.setTextColor(colors.yellow)
  107. term.setBackgroundColor(colors.gray)
  108. print("@")
  109. for u=1,#AiXs do
  110. term.setCursorPos(AiXs[u],AiYs[u])
  111. term.setBackgroundColor(colors.red)
  112. print("V")
  113. for j=AiYs[u]+1,5 do
  114. term.setCursorPos(AiXs[u],j)
  115. print("|")
  116. end
  117. end
  118. term.setBackgroundColor(colors.black)
  119. term.setTextColor(colors.white)
  120. term.setCursorPos(1,1)
  121. print("Score:",score,"Turns:",time,"Health:",playerHP,"Foes:",#AiXs,"Weapon %",(PR/5)*100)
  122. print("Move quickly!")
  123. if timePenelty then
  124. print("TIME PENELTY")
  125. end
  126. if fireTurn == 3 then
  127. term.setTextColor(colors.red)
  128. print(">>>[ FIRE TURN ]<<<")
  129. end
  130. --Players turn
  131. --Player move
  132. i=os.time()
  133. E,K = os.pullEvent()
  134. term.setCursorPos(1,2)
  135. term.clearLine()
  136. print("WAIT!")
  137. timePenelty = false
  138. if os.time() - i > 0.5 then
  139. timePenelty = true
  140. playerHP = playerHP - 0.5
  141. end
  142. sleep(0.2)
  143. if E == "key" then
  144. if K == keys.a or K == keys.left then
  145. if playerX > 4 then
  146. playerX = playerX - 4
  147. end
  148. elseif K == keys.d or K == keys.right then
  149. if playerX < 24 then
  150. playerX = playerX + 4
  151. end
  152. elseif K == keys.w or K == keys.up or K == keys.space or K == keys.enter and PR > 5 then
  153. --PlayerFire
  154. if PR > 5 then
  155. PR = PR - 5
  156. for u=1,#AiXs do
  157. if playerX == AiXs[u] then
  158. playerHP = playerHP + 0.5
  159. AiXs[u] = 0
  160. AiYs[u] = 0
  161. score = score + 10
  162. end
  163. end
  164. else
  165. print("Weapon % too low!")
  166. sleep(0.5)
  167. end
  168. end
  169. PR = PR + 1
  170.  
  171. --end
  172. end
  173. end
  174. end
  175.  
  176. function mainMenu()
  177. reset()
  178. print("Astroids")
  179. print("Made by Aio on july the 5:th of 2022")
  180. print("Press any key to play")
  181. os.pullEvent("key")
  182. play()
  183. end
  184. mainMenu()
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement