Advertisement
BigSHinyToys

modMaze

Apr 30th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. --Vars you need
  2. function load_vars()
  3.     sX = 1
  4.     sY = 1
  5.     bgcol = 2^math.random(0,15)
  6.     figcol = 2^math.random(0,15)
  7.     pos = {sX, sY}
  8. end
  9.  
  10. --Imgs you need
  11. function load_imgs()
  12.     lvl1 = paintutils.loadImage("lvl1")
  13. end
  14.  
  15. --Screen update
  16. function updating()
  17.     paintutils.drawImage(lvl1,1,1)
  18.     pos = {sX,sY}
  19.     term.setCursorPos(pos[1],pos[2])
  20. end
  21.  
  22. --simple clear function
  23. function clear()
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26. end
  27.  
  28. --rendering
  29. function rendering()
  30.     term.setBackgroundColor(bgcol)
  31.     clear()
  32.     updating()
  33.     term.setBackgroundColor(figcol)
  34.     term.write(" ")
  35. end
  36.  
  37. --button handling
  38. function buttons()
  39.     while true do
  40.     local sEvent, sKey = os.pullEvent("key")
  41.     local oldPosX = sX
  42.     local oldPosY = sY
  43.     if sKey == keys.left and sX >= 2 then
  44.         sX = sX - 1
  45.     end
  46.     if sKey == keys.right and sX <= 50 then
  47.         sX = sX + 1
  48.     end
  49.     if sKey == keys.up and sY >= 2 then
  50.         sY = sY - 1
  51.     end
  52.     if sKey == keys.down and sY <= 18 then
  53.         sY = sY + 1
  54.     end
  55.     if lvl1[sY][sX] ~= colors.blue then
  56.         sX = oldPosX
  57.         sY = oldPosY
  58.     end
  59.     rendering()
  60.     sleep(0)
  61.     end
  62.     sleep(0)
  63. end
  64.  
  65. --game starting
  66. function start_game()
  67.     load_vars()
  68.     load_imgs()
  69.     rendering()
  70.     buttons()
  71. end
  72.  
  73. start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement