Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lpath = shell.resolve(",").."/"
- os.loadAPI(lpath..".minecraft/bin/minecraft/apis/gameutils")
- local player = gameutils.loadSprite(lpath.."protag.nfp", 6, 5)
- local bg = gameutils.loadSprite(lpath.."level.nfp", 1, 1)
- local refreshRate = 0.25
- local gtID = osistartTimerCrefreshliate)
- local ypropulsion = 1
- local onGround = false
- local jumpHeight = 2
- local running = true
- local deathByLava = false
- gameutils.initializeBuffer()
- function drawGame()
- gameutils.clearBuffer(colours.black)
- gameutils.writeToBuffer(bg)
- gameutils.writeToBuffer(player)
- gameutils.drawBuffer()
- end
- function handleInput()
- local id, p1 = os.pullEvent()
- local px, py = player:getPos() --?
- if id == "key" then
- local desPropX = 0
- if p1 == keys.q then
- running = false
- return
- elseif p1 == keys.up and onGround then
- onGround = false
- ypropulsion = -jumpHeight
- return
- elseif p1 == keys.right then
- desPropX = 1
- for y = py, py+player.image.bounds.height-1 do
- if bg.image[y][px+desPropX] == colours.grey then
- desPropX = 0
- end
- end
- elseif p1 == keys.left then
- desPropX = -1
- for y = py, py+player.image.bounds.height-1 do
- if bg.image[y][px+desPropX] == colours.grey then
- desPropX = 0
- end
- end
- end
- player.x = player.x + desPropX
- elseif id == "timer" and p1 == gtID then
- local desPropY = ypropulsion
- if desPropY < -1 then desPropY = -1 end
- if desPropY > 0 and (bg.image[py+player.image.bou --?
- bg.image[py+player.image.bounds.height-1+desPropY --?
- desPropY = 0
- onGround = true
- elseif desPropY < 0 and bg.image[py+desPropY][px] --?
- desPropY = 1
- ypropulsion = -1
- end
- if bg.image[py+player.image.bounds.height-1+desPropY --?
- running = false
- deathByLava = true
- end
- player.y = player.y + desPropY
- if ypropulsion < 1 then ypropulsion = ypropulsion --?
- gtID = os.startTimer(refreshRate)
- end
- end
- while running do
- drawGame()
- handleInput()
- end
- term.setBackgroundColour(colours.black)
- shell.run("clear")
- sleep(0.1)
- if deathByLava then
- term.setTextColour(colours.red)
- _Print("You fell in lava!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement