Advertisement
jorn600

Untitled

Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. --
  2. player = {}
  3. player.x = 20
  4. player.y = 20
  5. player.sprite = 0
  6. player.speed = 1
  7. bounds = {}
  8. bounds.x = 120
  9. bounds.y = 120
  10.  
  11. powerup = {}
  12. powerup.sprite = 1
  13. powerup.x = 0
  14. powerup.y = 0
  15. powerup.active = true
  16.  
  17. function move()
  18. player.moving = true
  19. player.sprite += 1
  20. if player.sprite > 0 then
  21. player.sprite = 0
  22. end
  23. end
  24.  
  25. function _update()
  26. player.moving = true
  27. if btn(0) then
  28. left = true
  29. right = false
  30. up = false
  31. down = false
  32. end
  33. if btn(1) then
  34. right = true
  35. left = false
  36. up = false
  37. down = false
  38. end
  39. if btn(2) then
  40. up = true
  41. left = false
  42. right = false
  43. down = false
  44. end
  45. if btn(3) then
  46. down = true
  47. up = false
  48. right = false
  49. left = false
  50. end
  51. if not player.moving then
  52. player.sprite = 0
  53. end
  54. if left then
  55. if player.x <=0 then
  56. player.x = 0
  57. else
  58. player.x -= player.speed
  59. end
  60. move()
  61. end
  62. if right then
  63. if player.x > bounds.x then
  64. player.x = bounds.x
  65.  
  66. else
  67. player.x += player.speed
  68.  
  69. end
  70. move()
  71. end
  72. if down then
  73. if player.y >= bounds.y then
  74. player.y = bounds.y
  75. else
  76. player.y += player.speed
  77. end
  78. move()
  79. end
  80. if up then
  81. if player.y <= 0 then
  82. player.y = 0
  83. else
  84. player.y -= player.speed
  85. end
  86. move()
  87. end
  88. if powerup.active == false then
  89. powerup.active = true
  90. powerup.x = rnd(120)
  91. powerup.y = rnd(120)
  92. end
  93. if powerup.x == player.x then
  94. powerup.active = false
  95. end
  96. end
  97.  
  98. function _draw()
  99. cls()
  100. spr(player.sprite, player.x, player.y)
  101. spr(powerup.sprite, powerup.x, powerup.y)
  102.  
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement