Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Main "Engine"
- --Completely Written by Piorjade
- --You a free to edit/extend the code for your own purposes...
- --GET THE LEVELEDITOR HERE: pastebin get ESPY1FUz editor
- --(Though I'm really shitty at programming)
- --Variablen
- _ver = 0.1
- _verstr = "0.1"
- lvlLocation = "/game/levels/"
- lvlData = {}
- currentLevel = ""
- xPos = 1
- yPos = 1
- --Funktionen
- function clear(bg, fg)
- term.setCursorPos(1,1)
- term.setBackgroundColor(bg)
- term.setTextColor(fg)
- term.clear()
- end
- function menu()
- clear(colors.black, colors.white)
- term.setCursorPos(24,6)
- term.setBackgroundColor(colors.lime)
- term.write("Start")
- term.setCursorPos(24,8)
- term.write("Exit")
- menu = true
- while menu do
- local event, button, x, y = os.pullEventRaw("mouse_click")
- if button == 1 and x >= 24 and x <= 28 and y == 6 then
- menu = false
- loadLevel("tutorial")
- break
- elseif button == 1 and x >= 24 and x <= 27 and y == 8 then
- clear(colors.black, colors.white)
- print("Thanks for playing!")
- break
- end
- end
- end
- function getLevelData(level)
- local file = fs.open(lvlLocation..level..".lvlDat","r")
- local inhalt = file.readAll()
- lvlData = textutils.unserialize(inhalt)
- file.close()
- end
- function drawEntities()
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.black)
- xPos = tonumber(lvlData.spawnPosX)
- yPos = tonumber(lvlData.spawnPosY)
- term.setCursorPos(xPos, yPos)
- term.write("P")
- playing = true
- game()
- end
- function game()
- while playing do
- local event, key = os.pullEventRaw("key")
- if key == keys.left and xPos > 1 then
- local blocktrue = false
- for _, block in ipairs(lvlData.blocksX) do
- local x = tonumber(block)
- local y = tonumber(lvlData.blocksY[_])
- if xPos == x+1 and yPos == y then
- blocktrue = true
- end
- end
- if blocktrue then
- else
- xPos = xPos-1
- gravity()
- redrawLvl()
- end
- elseif key == keys.right and xPos < 51 then
- local block = false
- for _,block in ipairs(lvlData.blocksX) do
- local x = tonumber(block)
- local y = tonumber(lvlData.blocksY[_])
- if xPos == x-1 and yPos == y then
- blocktrue = true
- end
- end
- if blocktrue then
- else
- xPos = xPos+1
- gravity()
- redrawLvl()
- end
- end
- end
- end
- function gravity()
- for _, block in ipairs(lvlData.blocksX) do
- local x = tonumber(block)
- local y = tonumber(lvlData.blocksY[_])
- if xPos == x and yPos+1 == y then
- break
- elseif xPos == x and yPos+2 <= y then
- yPos = yPos+1
- gravity()
- end
- end
- end
- function redrawLvl()
- clear(colors.black, colors.white)
- lvl = paintutils.loadImage(lvlLocation..currentLevel..".lvl")
- paintutils.drawImage(lvl, 1, 1)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.black)
- term.setCursorPos(xPos, yPos)
- term.write("P")
- end
- function loadLevel(level)
- getLevelData(level)
- lvl = paintutils.loadImage(lvlLocation..level..".lvl")
- clear(colors.black, colors.white)
- paintutils.drawImage(lvl, 1, 1)
- currentLevel = level
- drawEntities()
- end
- --Code
- local args = {...}
- if #args < 1 then
- clear(colors.black, colors.white)
- menu()
- elseif #args == 2 then
- if fs.exists(args[1]) and fs.exists(args[1]..args[2]..".lvl") then
- lvlLocation = args[1]
- currentLevel = args[2]
- loadLevel(args[2])
- else
- print("File does not exist. Please make sure")
- print("that you wrote it like this:")
- term.setTextColor(colors.yellow)
- print("thisfile <folder/to/the> <level>")
- term.setTextColor(colors.red)
- print("AND WITHOUT THE .lvl ENDING!")
- term.setTextColor(colors.white)
- end
- else
- print("Too many arguments. Please make sure")
- print("that you wrote it like this:")
- term.setTextColor(colors.yellow)
- print("thisfile <folder/to/the> <level>")
- term.setTextColor(colors.red)
- print("AND WITHOUT THE .lvl ENDING!")
- term.setTextColor(colors.white)
- end
Add Comment
Please, Sign In to add comment