Advertisement
LazerAio

TETRA.lua

Jul 9th, 2022
2,304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. print("If can read this, then something has proborbly gone wrong!") --Oh look a easter egg code comment!!
  2.  
  3. --HEY CODE READER!
  4. --Wanna try modding this program?
  5. --To add items please look for comments starting with @!
  6. --When you are done modding the program please
  7. --do not forget to creddit me (Aio)
  8. --Tip: there should be 7 comments marked @!
  9. --Lets say you want to make the world infinate, that's quite difficult
  10. --but if you are going to try it, then look for the comment saying "WORLD GEN HERE!"
  11.  
  12. --Globals
  13. G_WIDTH , G_HEIGHT = term.getSize()
  14.  
  15. --Items [color,icon]
  16. --@! Define items here!
  17. I_Grass = {colors.lime,{"^^^","###","###"}}
  18. I_Plank = {colors.orange,{"///","///","///"}}
  19. I_Dirt = {colors.brown,{"---","|*|","---"}}
  20. I_Stone = {colors.lightGray,{"---","###","---"}}
  21. I_Air = {colors.lightBlue,{" ","AIR"," "}}
  22.  
  23. --Functions
  24. function drawFG(ITEMS)
  25. term.setCursorPos(1,G_HEIGHT-3)
  26. for i = 1,3 do
  27. term.clearLine()
  28. print(" | 1 | 2 | 3 | 4 | 5 |")
  29. --@! To add 'inventory' items please follow the pattern above
  30. end
  31. for i = 1,#ITEMS do
  32. term.setBackgroundColor(ITEMS[i][1])
  33. for u = 1,#ITEMS[i][2] do
  34. term.setCursorPos(i*4,(G_HEIGHT-4)+u)
  35. print(ITEMS[i][2][u])
  36. end
  37. end
  38. end
  39. --Example usage: drawFG({I_Dirt,I_Stone})
  40. WORLD = {}
  41. --WORLD GEN HERE!
  42. maxX = G_WIDTH
  43. maxY = 10
  44. function createNewWorld()
  45. MaxX = G_WIDTH
  46. --@! change MaxY so that your new items can generate!
  47. MaxY = 7
  48. --@! Add items to the world gen here
  49. WORLD = {{I_Air,I_Air,I_Air,I_Air,I_Air,I_Air,I_Grass,I_Dirt,I_Stone,I_Stone,I_Stone}}
  50. for i=1,MaxX do
  51. --@! and here
  52. WORLD[i] = {I_Air,I_Air,I_Air,I_Air,I_Air,I_Air,I_Grass,I_Dirt,I_Stone,I_Stone,I_Stone}
  53. end
  54. end
  55. --Helpfull ASCII image
  56. -- Y
  57. -- |
  58. -- |
  59. -- *--X
  60. function modifyWorld(WORLD,ModTo,ModX,ModY)
  61. WORLD[ModX][ModY] = ModTo
  62. end
  63. function drawBG(ITEMS,playerX,playerY,WORLD)
  64. term.setBackgroundColor(colors.lightBlue)
  65. term.clear()
  66. drawFG(ITEMS)
  67. for i=1,#WORLD do
  68. for u=1,#WORLD[i] do
  69. for z=1,#WORLD[i][u] do
  70. term.setCursorPos(i,u)
  71. term.setBackgroundColor(WORLD[i][u][1])
  72. print(" ")
  73. end
  74. end
  75. end
  76. term.setCursorPos(playerX,playerY)
  77. term.setBackgroundColor(colors.black)
  78. term.setTextColor(colors.yellow)
  79. print("@")
  80. term.setCursorPos(1,G_HEIGHT-6)
  81. term.setTextColor(colors.white)
  82. print("W/A/S/D - move | H - help | ALT - exit")
  83. print("TETRA, made by Aio in 2022/07/09")
  84. end
  85. --Game loop logic!
  86. function gameLoop(ITEMS)
  87. playerX = 1
  88. playerY = 1
  89. while true do
  90. tick(ITEMS)
  91. end
  92. end
  93. function createNew()
  94. print("Creating new world!")
  95. createNewWorld()
  96. --@! Add the items to the inventory here
  97. ITEMS = {I_Dirt,I_Stone,I_Air,I_Grass,I_Plank}
  98. print("Starting new world!")
  99. gameLoop(ITEMS)
  100. end
  101. function mainMenu()
  102. nOption = 1
  103. while true do
  104. term.setBackgroundColor(colors.lightBlue)
  105. term.clear()
  106. term.setTextColor(colors.white)
  107. term.setBackgroundColor(colors.black)
  108. term.setCursorPos((G_WIDTH/2)-3,2)
  109. print("TETRA!")
  110. if nOption == 1 then
  111. print("PLAY! <<")
  112. print("CREDDITS ")
  113. print("EXIT ")
  114. elseif nOption == 2 then
  115. print("PLAY! ")
  116. print("CREDDITS <<")
  117. print("EXIT ")
  118. elseif nOption == 3 then
  119. print("PLAY! ")
  120. print("CREDDITS ")
  121. print("EXIT ]: <<")
  122. end
  123. E,K = os.pullEvent("key")
  124. if K == keys.w or K == keys.up then
  125. nOption = nOption - 1
  126. elseif K == keys.s or K == keys.down then
  127. nOption = nOption + 1
  128. elseif K == keys.enter then
  129. term.clear()
  130. if nOption == 1 then
  131. createNew()
  132. elseif nOption == 2 then
  133. term.clear()
  134. print("Made by AIO")
  135. print("on 2022/07/09")
  136. sleep(2)
  137. else
  138. print("Thanks for playing!","the time is now")
  139. print(os.date())
  140. print("")
  141. print("Exiting (crashing) the game")
  142. term.setTextColor(colors.green)
  143. print(i/nil)
  144. break
  145. end
  146. end
  147. if nOption > 3 then
  148. nOption = 1
  149. elseif nOption < 1 then
  150. nOption = 3
  151. end
  152. end
  153. end
  154. function tick(ITEMS)
  155. drawBG(ITEMS,playerX,playerY,WORLD)
  156. E,K = os.pullEvent("key")
  157. if E == "key" then
  158. if K == keys.a then
  159. playerX = playerX - 1
  160. elseif K == keys.d then
  161. playerX = playerX + 1
  162. elseif K == keys.s then
  163. playerY = playerY + 1
  164. elseif K == keys.w then
  165. playerY = playerY - 1
  166. elseif K == keys.one then
  167. SEL_ITEM = ITEMS[1]
  168. elseif K == keys.two then
  169. SEL_ITEM = ITEMS[2]
  170. elseif K == keys.three then
  171. SEL_ITEM = ITEMS[3]
  172. elseif K == keys.four then
  173. SEL_ITEM = ITEMS[4]
  174. elseif K == keys.five then
  175. SEL_ITEM = ITEMS[5]
  176. --@! To add more inventory follow the above pattern!
  177. elseif K == keys.h then
  178. print("WELCOME TO TETRA")
  179. print("use A and D to move")
  180. print("change item with 1-5")
  181. print("build with b or enter")
  182. print("exit using alt")
  183. print("The game will continue in 10 seconds")
  184. sleep(10)
  185. elseif K == keys.leftAlt then
  186. print("Exiting world")
  187. mainMenu()
  188. elseif K == keys.b or K == keys.enter then
  189. term.clear()
  190. modifyWorld(WORLD,SEL_ITEM,playerX,playerY+1)
  191. end
  192. if playerX > maxX then
  193. playerX = playerX - 1
  194. elseif playerX < 1 then
  195. playerX = 1
  196. end
  197. if playerY > maxY then
  198. playerY = playerY - 1
  199. elseif playerY < 1 then
  200. playerY = playerY + 1
  201. end
  202. end
  203. end
  204. mainMenu()
  205. --Made by Aio in 2022
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement