yazdmich

Moving ball

Oct 11th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. % /////////////////////
  2. % // Michael Yazdani //
  3. % /////////////////////
  4. % // ICS 3U ///////////
  5. % /////////////////////
  6.  
  7. setscreen ("graphics:700;700")
  8.  
  9. % VARIABLE AND CONSTANT DECLARATIONS
  10.  
  11. var x, y : int
  12. const inc := 8
  13. const radius := 25
  14. var chars : array char of boolean
  15.  
  16. % FORWARD DECLARATIONS
  17.  
  18. forward procedure moveup
  19. forward procedure movedown
  20. forward procedure moveleft
  21. forward procedure moveright
  22.  
  23. % PROCEDURES
  24.  
  25. procedure keydown % determines what keys are being pressed
  26. Input.KeyDown (chars)
  27. end keydown
  28.  
  29. procedure circle % draws a circle at location x and y with radius "radius" then erases for next frame
  30. drawoval (x, y, radius, radius, 1)
  31. delay (16)
  32. drawoval (x, y, radius, radius, white)
  33. end circle
  34.  
  35. body procedure moveup % sets y to y + inc (5 pixels), if y is greater than the vertical resolution of the output window - radius, movedown is called
  36. loop
  37. keydown
  38. exit when chars (KEY_LEFT_ARROW) or chars (KEY_RIGHT_ARROW) or chars (KEY_DOWN_ARROW) or chars (KEY_ESC)
  39. y := y + inc
  40. if y > maxy - radius then
  41. movedown
  42. end if
  43. circle
  44. end loop
  45. end moveup
  46.  
  47. body procedure movedown % sets y to y - inc, if y is less than radius (in this case, 25 pixels), moveup is called
  48. loop
  49. keydown
  50. exit when chars (KEY_LEFT_ARROW) or chars (KEY_RIGHT_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_ESC)
  51. y := y - inc
  52. if y < radius then
  53. moveup
  54. end if
  55. circle
  56. end loop
  57. end movedown
  58.  
  59. body procedure moveright % sets x to x + inc, if x is greater than the horizontal resolution of the output window, moveleft is called
  60. loop
  61. keydown
  62. exit when chars (KEY_LEFT_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_DOWN_ARROW) or chars (KEY_ESC)
  63. x := x + inc
  64. if x > maxx - radius then
  65. moveleft
  66. end if
  67. circle
  68. end loop
  69. end moveright
  70.  
  71. body procedure moveleft % sets x to x - inc, if x is less than radius, moveright is called
  72. loop
  73. keydown
  74. exit when chars (KEY_RIGHT_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_DOWN_ARROW) or chars (KEY_ESC)
  75. x := x - inc
  76. if x < radius then
  77. moveright
  78. end if
  79. circle
  80. end loop
  81. end moveleft
  82.  
  83. % VARIABLE INITILIZATION
  84.  
  85. x := maxx div 2 % initializes x to center of output window
  86. y := maxy div 2 % initializes y to center of output window
  87.  
  88. % MAIN PROGRAM
  89.  
  90. loop
  91. keydown
  92. exit when chars (KEY_ESC) % exits main loop, terminates program
  93. if chars (KEY_LEFT_ARROW) then
  94. moveleft
  95. elsif chars (KEY_RIGHT_ARROW) then
  96. moveright
  97. elsif chars (KEY_DOWN_ARROW) then
  98. movedown
  99. elsif chars (KEY_UP_ARROW) then
  100. moveup
  101. end if
  102. moveup
  103. end loop
  104.  
  105. cls
  106. put "Program Terminated."
Advertisement
Add Comment
Please, Sign In to add comment