Guest User

PICO-8 code

a guest
Aug 9th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. // == purpose functions ==
  2.  
  3. function ball_distx(box_x)
  4. return box_x-ball_x
  5. end
  6. function ball_disty(box_y)
  7. return box_y-ball_y
  8. end
  9. function inrange(num,min,max)
  10. if num >= min and num <= max then
  11. flip()
  12. return true
  13. else
  14. return false
  15. end
  16. end
  17.  
  18. [ . . . ]
  19.  
  20. // == the update function ==
  21.  
  22. function _update60()
  23. [ . . . ]
  24. // move the ball based on the set speed
  25. ball_x+=ball_dx*ball_speed
  26. ball_y+=ball_dy*ball_speed
  27.  
  28. // if the ball is beyond the right/bottom of the screen...
  29. if ball_x>115 or ball_y>127
  30. // ...or the top/left...
  31. or ball_x<5 or ball_y<2
  32. then
  33. // reverse the direction
  34. ball_dx = -ball_dx
  35. ball_dy = -ball_dy
  36. ball_ang = rnd(4)
  37. // play the ball hit sound sound
  38. end
  39.  
  40. // ball collision
  41. if ball_disty(110) == 0 and ball_distx(pad_x) >= -4 and ball_distx(pad_x) <= 4 then
  42. // context: pad_dir is the direction the paddle is facing, which is controlled either by the Z and X buttons or by what direction the paddle is moving in
  43. if pad_dir == 0 then
  44. ball_dx = -1
  45. ball_dy = -1
  46. end
  47. if pad_dir == 1 then
  48. ball_dx = 0
  49. ball_dy = -1
  50. end
  51. if pad_dir == 2 then
  52. ball_dx = 1
  53. ball_dy = -1
  54. end
  55. //ball_speed += .1
  56. end
  57. end
  58.  
  59. // == the draw function ==
  60.  
  61. function _draw()
  62. // clear the screen
  63. cls()
  64. // print any test variables
  65. print(ball_distx(pad_x),20,0,7)
  66. print(ball_disty(110),50,0,7)
  67.  
  68. [ . . . ]
  69.  
  70. // draw the ball
  71. spr(ball_spr,ball_x,ball_y)
  72.  
  73. // draw the paddle
  74. spr(pad_spr,pad_x,110)
  75. // ball animation
  76. mn = ball_disty(110)
  77. if inrange(ball_distx(pad_x),-4,4) then
  78. if inrange(mn,-1,1) then ball_spr = pad_spr end
  79. if inrange(mn,-2,2) then ball_spr = 18 end
  80. if inrange(mn,-3,3) then ball_spr = 17 end
  81. if inrange(mn,-4,4) then ball_spr = 0 end
  82. else
  83. if ball_x==112 or ball_x==8 then flip() flip() ball_spr=0 end
  84. if ball_x==113 or ball_x==7 then flip() flip() ball_spr=1 end
  85. if ball_x==114 or ball_x==6 then flip() flip() ball_spr=2 end
  86. if ball_x==115 or ball_x==5 then flip() flip() ball_spr=3 end
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment