Advertisement
DanielLaby99

Code

Jul 16th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. local lpath = shell.resolve(",").."/"
  2. os.loadAPI(lpath..".minecraft/bin/minecraft/apis/gameutils")
  3.  
  4. local player = gameutils.loadSprite(lpath.."protag.nfp", 6, 5)
  5. local bg = gameutils.loadSprite(lpath.."level.nfp", 1, 1)
  6.  
  7.  
  8. local refreshRate = 0.25
  9. local gtID = osistartTimerCrefreshliate)
  10. local ypropulsion = 1
  11. local onGround = false
  12. local jumpHeight = 2
  13. local running = true
  14. local deathByLava = false
  15.  
  16. gameutils.initializeBuffer()
  17.  
  18. function drawGame()
  19. gameutils.clearBuffer(colours.black)
  20. gameutils.writeToBuffer(bg)
  21. gameutils.writeToBuffer(player)
  22. gameutils.drawBuffer()
  23. end
  24.  
  25. function handleInput()
  26.  
  27. local id, p1 = os.pullEvent()
  28.  
  29. local px, py = player:getPos() --?
  30.  
  31. if id == "key" then
  32. local desPropX = 0
  33.  
  34. if p1 == keys.q then
  35. running = false
  36. return
  37.  
  38. elseif p1 == keys.up and onGround then
  39. onGround = false
  40. ypropulsion = -jumpHeight
  41. return
  42. elseif p1 == keys.right then
  43. desPropX = 1
  44. for y = py, py+player.image.bounds.height-1 do
  45. if bg.image[y][px+desPropX] == colours.grey then
  46. desPropX = 0
  47. end
  48. end
  49. elseif p1 == keys.left then
  50. desPropX = -1
  51. for y = py, py+player.image.bounds.height-1 do
  52. if bg.image[y][px+desPropX] == colours.grey then
  53. desPropX = 0
  54. end
  55. end
  56. end
  57. player.x = player.x + desPropX
  58. elseif id == "timer" and p1 == gtID then
  59. local desPropY = ypropulsion
  60. if desPropY < -1 then desPropY = -1 end
  61.  
  62. if desPropY > 0 and (bg.image[py+player.image.bou --?
  63.  
  64. bg.image[py+player.image.bounds.height-1+desPropY --?
  65. desPropY = 0
  66. onGround = true
  67. elseif desPropY < 0 and bg.image[py+desPropY][px] --?
  68. desPropY = 1
  69. ypropulsion = -1
  70. end
  71.  
  72. if bg.image[py+player.image.bounds.height-1+desPropY --?
  73. running = false
  74. deathByLava = true
  75. end
  76.  
  77. player.y = player.y + desPropY
  78. if ypropulsion < 1 then ypropulsion = ypropulsion --?
  79.  
  80. gtID = os.startTimer(refreshRate)
  81. end
  82. end
  83.  
  84. while running do
  85. drawGame()
  86. handleInput()
  87. end
  88.  
  89. term.setBackgroundColour(colours.black)
  90. shell.run("clear")
  91. sleep(0.1)
  92.  
  93. if deathByLava then
  94. term.setTextColour(colours.red)
  95. _Print("You fell in lava!")
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement