Guest User

Platformer

a guest
Jul 24th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. k = 0
  2. local pixels = {}
  3.  
  4. pixels[1] = {}
  5. pixels[1].x = 1
  6. pixels[1].y = 6
  7. pixels[1].color = colors.green
  8.  
  9. _cX = 1
  10. _cY = 1
  11. function Render()
  12.   term.setBackgroundColor(colors.black)
  13.   term.clear()
  14.   for i=1, #pixels do
  15.     paintutils.drawPixel(pixels[i].x, pixels[i].y, pixels[i].color)
  16.   end
  17.   paintutils.drawPixel(_cX, _cY, colors.red)
  18. end
  19.  
  20. function Gameloop()
  21.   ev, key = os.pullEvent("key")
  22.   if key == keys.up then
  23.   _cY = _cY - 1
  24.   elseif key == keys.left then
  25.   _cX = _cX - 1
  26.   elseif key == keys.right then
  27.   _cX = _cX + 1
  28.   end
  29.   Render()
  30.   sleep(0.1)
  31.   Gameloop()
  32. end
  33.  
  34. function Otherloop()
  35. for i = 1, #pixels do
  36.   if pixels[i].y == _cY+1 and pixels[i].x == _cX then
  37.   k = 1
  38.   else
  39.   k = 0
  40.   end
  41. end
  42. if k == 0 then
  43. _cY = _cY + 1
  44. end
  45. Render()
  46. sleep(0.1)
  47. Otherloop()
  48. end
  49.  
  50. Render()
  51. parallel.waitForAll(Gameloop(), Otherloop())
Advertisement
Add Comment
Please, Sign In to add comment