Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("If can read this, then something has proborbly gone wrong!") --Oh look a easter egg code comment!!
- --HEY CODE READER!
- --Wanna try modding this program?
- --To add items please look for comments starting with @!
- --When you are done modding the program please
- --do not forget to creddit me (Aio)
- --Tip: there should be 7 comments marked @!
- --Lets say you want to make the world infinate, that's quite difficult
- --but if you are going to try it, then look for the comment saying "WORLD GEN HERE!"
- --Globals
- G_WIDTH , G_HEIGHT = term.getSize()
- --Items [color,icon]
- --@! Define items here!
- I_Grass = {colors.lime,{"^^^","###","###"}}
- I_Plank = {colors.orange,{"///","///","///"}}
- I_Dirt = {colors.brown,{"---","|*|","---"}}
- I_Stone = {colors.lightGray,{"---","###","---"}}
- I_Air = {colors.lightBlue,{" ","AIR"," "}}
- --Functions
- function drawFG(ITEMS)
- term.setCursorPos(1,G_HEIGHT-3)
- for i = 1,3 do
- term.clearLine()
- print(" | 1 | 2 | 3 | 4 | 5 |")
- --@! To add 'inventory' items please follow the pattern above
- end
- for i = 1,#ITEMS do
- term.setBackgroundColor(ITEMS[i][1])
- for u = 1,#ITEMS[i][2] do
- term.setCursorPos(i*4,(G_HEIGHT-4)+u)
- print(ITEMS[i][2][u])
- end
- end
- end
- --Example usage: drawFG({I_Dirt,I_Stone})
- WORLD = {}
- --WORLD GEN HERE!
- maxX = G_WIDTH
- maxY = 10
- function createNewWorld()
- MaxX = G_WIDTH
- --@! change MaxY so that your new items can generate!
- MaxY = 7
- --@! Add items to the world gen here
- WORLD = {{I_Air,I_Air,I_Air,I_Air,I_Air,I_Air,I_Grass,I_Dirt,I_Stone,I_Stone,I_Stone}}
- for i=1,MaxX do
- --@! and here
- WORLD[i] = {I_Air,I_Air,I_Air,I_Air,I_Air,I_Air,I_Grass,I_Dirt,I_Stone,I_Stone,I_Stone}
- end
- end
- --Helpfull ASCII image
- -- Y
- -- |
- -- |
- -- *--X
- function modifyWorld(WORLD,ModTo,ModX,ModY)
- WORLD[ModX][ModY] = ModTo
- end
- function drawBG(ITEMS,playerX,playerY,WORLD)
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- drawFG(ITEMS)
- for i=1,#WORLD do
- for u=1,#WORLD[i] do
- for z=1,#WORLD[i][u] do
- term.setCursorPos(i,u)
- term.setBackgroundColor(WORLD[i][u][1])
- print(" ")
- end
- end
- end
- term.setCursorPos(playerX,playerY)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.yellow)
- print("@")
- term.setCursorPos(1,G_HEIGHT-6)
- term.setTextColor(colors.white)
- print("W/A/S/D - move | H - help | ALT - exit")
- print("TETRA, made by Aio in 2022/07/09")
- end
- --Game loop logic!
- function gameLoop(ITEMS)
- playerX = 1
- playerY = 1
- while true do
- tick(ITEMS)
- end
- end
- function createNew()
- print("Creating new world!")
- createNewWorld()
- --@! Add the items to the inventory here
- ITEMS = {I_Dirt,I_Stone,I_Air,I_Grass,I_Plank}
- print("Starting new world!")
- gameLoop(ITEMS)
- end
- function mainMenu()
- nOption = 1
- while true do
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos((G_WIDTH/2)-3,2)
- print("TETRA!")
- if nOption == 1 then
- print("PLAY! <<")
- print("CREDDITS ")
- print("EXIT ")
- elseif nOption == 2 then
- print("PLAY! ")
- print("CREDDITS <<")
- print("EXIT ")
- elseif nOption == 3 then
- print("PLAY! ")
- print("CREDDITS ")
- print("EXIT ]: <<")
- end
- E,K = os.pullEvent("key")
- if K == keys.w or K == keys.up then
- nOption = nOption - 1
- elseif K == keys.s or K == keys.down then
- nOption = nOption + 1
- elseif K == keys.enter then
- term.clear()
- if nOption == 1 then
- createNew()
- elseif nOption == 2 then
- term.clear()
- print("Made by AIO")
- print("on 2022/07/09")
- sleep(2)
- else
- print("Thanks for playing!","the time is now")
- print(os.date())
- print("")
- print("Exiting (crashing) the game")
- term.setTextColor(colors.green)
- print(i/nil)
- break
- end
- end
- if nOption > 3 then
- nOption = 1
- elseif nOption < 1 then
- nOption = 3
- end
- end
- end
- function tick(ITEMS)
- drawBG(ITEMS,playerX,playerY,WORLD)
- E,K = os.pullEvent("key")
- if E == "key" then
- if K == keys.a then
- playerX = playerX - 1
- elseif K == keys.d then
- playerX = playerX + 1
- elseif K == keys.s then
- playerY = playerY + 1
- elseif K == keys.w then
- playerY = playerY - 1
- elseif K == keys.one then
- SEL_ITEM = ITEMS[1]
- elseif K == keys.two then
- SEL_ITEM = ITEMS[2]
- elseif K == keys.three then
- SEL_ITEM = ITEMS[3]
- elseif K == keys.four then
- SEL_ITEM = ITEMS[4]
- elseif K == keys.five then
- SEL_ITEM = ITEMS[5]
- --@! To add more inventory follow the above pattern!
- elseif K == keys.h then
- print("WELCOME TO TETRA")
- print("use A and D to move")
- print("change item with 1-5")
- print("build with b or enter")
- print("exit using alt")
- print("The game will continue in 10 seconds")
- sleep(10)
- elseif K == keys.leftAlt then
- print("Exiting world")
- mainMenu()
- elseif K == keys.b or K == keys.enter then
- term.clear()
- modifyWorld(WORLD,SEL_ITEM,playerX,playerY+1)
- end
- if playerX > maxX then
- playerX = playerX - 1
- elseif playerX < 1 then
- playerX = 1
- end
- if playerY > maxY then
- playerY = playerY - 1
- elseif playerY < 1 then
- playerY = playerY + 1
- end
- end
- end
- mainMenu()
- --Made by Aio in 2022
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement