Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Vars you need
- function load_vars()
- sX = 1
- sY = 1
- bgcol = 2^math.random(0,15)
- figcol = 2^math.random(0,15)
- pos = {sX, sY}
- end
- --Imgs you need
- function load_imgs()
- lvl1 = paintutils.loadImage("lvl1")
- end
- --Screen update
- function updating()
- paintutils.drawImage(lvl1,1,1)
- pos = {sX,sY}
- term.setCursorPos(pos[1],pos[2])
- end
- --simple clear function
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --rendering
- function rendering()
- term.setBackgroundColor(bgcol)
- clear()
- updating()
- term.setBackgroundColor(figcol)
- term.write(" ")
- end
- --button handling
- function buttons()
- while true do
- local sEvent, sKey = os.pullEvent("key")
- local oldPosX = sX
- local oldPosY = sY
- if sKey == keys.left and sX >= 2 then
- sX = sX - 1
- end
- if sKey == keys.right and sX <= 50 then
- sX = sX + 1
- end
- if sKey == keys.up and sY >= 2 then
- sY = sY - 1
- end
- if sKey == keys.down and sY <= 18 then
- sY = sY + 1
- end
- if lvl1[sY][sX] ~= colors.blue then
- sX = oldPosX
- sY = oldPosY
- end
- rendering()
- sleep(0)
- end
- sleep(0)
- end
- --game starting
- function start_game()
- load_vars()
- load_imgs()
- rendering()
- buttons()
- end
- start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement