Advertisement
Guest User

Pong V5 Re-Upload

a guest
Apr 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.92 KB | None | 0 0
  1. setscreen ("graphics:1024;768")
  2. View.Set ("title: Pong by Vince Lai")
  3. var chars : array char of boolean %delcaring player input variable
  4.  
  5. var xBall := 509 %delcaring all varibles for the ball
  6. var yBall := 384
  7. var xInc := 1
  8. var yInc := 1
  9.  
  10. var font1 : int %declaring all font variables
  11. var font2 : int
  12. var font3 : int
  13.  
  14. font1 := Font.New ("sans serif:28") %declaring all fonts
  15. font2 := Font.New ("sans serif:12")
  16. font3 := Font.New ("verdana bold:30")
  17.  
  18. var choice : string
  19.  
  20. var lpady1 := 340 %declaring all the variables for the paddles
  21. var lpady2 := 430
  22. var lpadx1 := 10
  23. var lpadx2 := 20
  24. var rpady1 := 340
  25. var rpady2 := 430
  26. var rpadx1 := 1009
  27. var rpadx2 := 1021
  28. var paddleInc := 1
  29. var paddleInc2 := 1
  30.  
  31. var player1score : int := 0 %declaring playerscore variables
  32. var player2score : int :=0
  33.  
  34. var player1 : string
  35. var player2 : string
  36.  
  37. View.Set ("offscreenonly")
  38.  
  39. var scoretable : array 0 .. 0 of string
  40. % var score : int
  41. % var topscore : string
  42. % open : stream, "topscore.txt", read
  43. % read : stream, score
  44. % write : stream, score
  45.  
  46. procedure Pong
  47. loop % a loop so the program does not end unless user closes it
  48. cls %clear screen to draw new animation
  49. drawfillbox (508, 0, 512, maxy, 3) % middle line
  50. drawfilloval (xBall, yBall, 8, 8, black) %drawing ball, paddles, mid line etc
  51. drawfillbox (lpadx1, lpady1, lpadx2, lpady2, blue)
  52. drawfillbox (rpadx1, rpady1, rpadx2, rpady2, red)
  53. drawfillbox (0, 700, maxx, maxy, 3) %top bar
  54.  
  55. drawoval (0, 384, 60, 80, blue) %ice rink graphics left and right circle
  56. drawoval (maxx, 384, 60, 80, red)
  57. drawoval (250, 576, 60, 60, blue) %ice rink circles
  58. drawfilloval (250, 576, 5, 5, blue)
  59. drawoval (768, 576, 60, 60, red)
  60. drawfilloval (768, 576, 5, 5, red)
  61. drawoval (250, 192, 60, 60, blue)
  62. drawfilloval (250, 192, 5, 5, blue)
  63. drawoval (250, 192, 60, 60, blue)
  64. drawfilloval (250, 192, 5, 5, blue)
  65. drawoval (768, 192, 60, 60, red)
  66. drawfilloval (768, 192, 5, 5, red)
  67. drawoval (511, 382, 60, 60, 3)
  68. drawfilloval (511, 382, 5, 5, 3)
  69.  
  70. Draw.Text (player1 + " Score: " + intstr (player1score), 25, 720, font1, white)
  71. Draw.Text (player2 + " Score: " + intstr (player2score), 525, 720, font1, white)
  72.  
  73. xBall += xInc
  74. yBall += yInc
  75.  
  76. if xBall <= 0 and yBall <= 462 and yBall >= 302 then %playerscore system
  77. player2score := player2score + 1 %if the xvalue of the xBall is smaller or equal to 0 then add a point to player 2
  78. xBall := 509
  79. yBall := 384
  80. xInc *= -1
  81. lpady1 := 340 %declaring all the variables for the paddles
  82. lpady2 := 430
  83. lpadx1 := 10
  84. lpadx2 := 20
  85. rpady1 := 340
  86. rpady2 := 430
  87. rpadx1 := 1009
  88. rpadx2 := 1021
  89. Time.Delay (1000)
  90. View.Update
  91. end if
  92. if xBall >= maxx and yBall <= 462 and yBall >= 302 then
  93. xBall := 509
  94. yBall := 384
  95. xInc *= -1
  96. player1score := player1score + 1 %if the xvalue of the xBall is bigger or equal to max x value then add a point to player 1
  97. lpady1 := 340 %declaring all the variables for the paddles
  98. lpady2 := 430
  99. lpadx1 := 10
  100. lpadx2 := 20
  101. rpady1 := 340
  102. rpady2 := 430
  103. rpadx1 := 1009
  104. rpadx2 := 1021
  105. Time.Delay (1000)
  106. View.Update
  107. end if
  108.  
  109. if xBall >= maxx or xBall <= 0 then %ball mechanics so ball does not bounce outside of the given parameters
  110. xInc *= -1
  111. end if
  112. if yBall >= 700 or yBall <= 0 then
  113. yInc *= -1
  114. end if
  115.  
  116. if yBall <= lpady2 and yBall >= lpady1 and xBall >= lpadx1 and xBall <= lpadx2 + 10 and xInc = -1 then
  117. %if the ball bounces on the paddle then it will reflect at an opposite direction isntead towards the same direction as previous
  118. yInc *= 1
  119. xInc *= -1
  120. end if
  121. if yBall <= lpady2 and yBall >= lpady1 and xBall >= lpadx1 - 10 and xBall <= lpadx2 and xInc = 1 then
  122. %if the ball bounces on the paddle then it will reflect at an opposite direction isntead towards the same direction as previous
  123. yInc *= 1
  124. xInc *= -1
  125. end if
  126.  
  127. if yBall <= rpady2 and yBall >= rpady1 and xBall >= rpadx1 - 10 and xBall <= rpadx2 and xInc = 1 then
  128. yInc *= 1
  129. xInc *= -1
  130. end if
  131. if yBall <= rpady2 and yBall >= rpady1 and xBall >= rpadx1 and xBall <= rpadx2 + 10 and xInc = -1 then
  132. yInc *= 1
  133. xInc *= -1
  134. end if
  135.  
  136. Input.KeyDown (chars) %all player input
  137. if chars (KEY_UP_ARROW) and rpady2 < 690 then %setting parameters so the paddles do not go outside of the parameters
  138. rpady1 := rpady1 + paddleInc
  139. rpady2 := rpady2 + paddleInc
  140. end if
  141. if chars (KEY_LEFT_ARROW) and rpadx1 > 516 then
  142. rpadx1 := rpadx1 - paddleInc2
  143. rpadx2 := rpadx2 - paddleInc2
  144. end if
  145. if chars (KEY_RIGHT_ARROW) and rpadx2 < maxx then
  146. rpadx1 := rpadx1 + paddleInc2
  147. rpadx2 := rpadx2 + paddleInc2
  148. end if
  149. if chars (KEY_DOWN_ARROW) and rpady1 > 0 then
  150. rpady1 := rpady1 - paddleInc
  151. rpady2 := rpady2 - paddleInc
  152. end if
  153. if chars ('w') and lpady2 < 690 then
  154. lpady1 := lpady1 + paddleInc
  155. lpady2 := lpady2 + paddleInc
  156. end if
  157. if chars ('a') and lpadx1 > 0 then
  158. lpadx1 := lpadx1 - paddleInc2
  159. lpadx2 := lpadx2 - paddleInc2
  160. end if
  161. if chars ('d') and lpadx2 < 505 then
  162. lpadx1 := lpadx1 + paddleInc
  163. lpadx2 := lpadx2 + paddleInc
  164. end if
  165. if chars ('s') and lpady1 > 0 then
  166. lpady1 := lpady1 - paddleInc2
  167. lpady2 := lpady2 - paddleInc2
  168. end if
  169.  
  170. if player1score = 10 then %win conditions
  171. Music.PlayFile ("Super Mario Bros. Music - Level Complete.mp3")
  172. Draw.Text ("Player 1 has won!", 25, 650, font1, red)
  173. View.Update
  174. Time.Delay (3000)
  175. exit
  176. end if
  177. if player2score = 10 then %win conditions
  178. Music.PlayFile("Super Mario Bros. Music - Level Complete.mp3")
  179. Draw.Text ("Player 2 has won!", 525, 650, font1, red)
  180. View.Update
  181. Time.Delay (3000)
  182. exit
  183. end if
  184. Time.Delay (1)
  185. View.Update
  186. end loop
  187. end Pong
  188.  
  189. procedure loading
  190. loop
  191. drawfillbox (0, 0, maxx, maxy, green)
  192. Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, blue) %intro screen text
  193. Draw.Text ("Get 10 points to win!", 290, 300, font3, blue)
  194. Time.Delay (300)
  195. cls
  196. drawfillbox (0, 0, maxx, maxy, yellow)
  197. Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, red) %intro screen text
  198. Draw.Text ("Get 10 points to win!", 290, 300, font3, red)
  199. View.Update
  200. Time.Delay (300)
  201. cls
  202. drawfillbox (0, 0, maxx, maxy, red)
  203. Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, yellow) %intro screen text
  204. Draw.Text ("Get 10 points to win!", 290, 300, font3, yellow)
  205. View.Update
  206. Time.Delay (300)
  207. cls
  208. drawfillbox (0, 0, maxx, maxy, blue)
  209. Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, green) %intro screen text
  210. Draw.Text ("Get 10 points to win!", 290, 300, font3, green)
  211. View.Update
  212. Time.Delay (300)
  213. cls
  214. View.Update
  215. Draw.Text ("What is player 1 name?", 250, 600, font3, blue) %intro screen text
  216. View.Update
  217. get player1
  218. Draw.Text ("Welcome! " + player1, 320, 500, font3, blue) %intro screen text
  219. View.Update
  220. Time.Delay (1000)
  221. cls
  222. Draw.Text ("What is player 2 name?", 250, 600, font3, blue) %intro screen text
  223. View.Update
  224. get player2
  225. Draw.Text ("Welcome! " + player2, 320, 500, font3, blue) %intro screen text
  226. View.Update
  227. Time.Delay (1000)
  228. exit
  229. end loop
  230. end loading
  231.  
  232.  
  233. loop
  234. Music.PlayFileLoop ("MACINTOSH420.mp3")
  235. loop
  236. player1score := 9
  237. player2score := 9
  238. loading
  239. Pong
  240. cls
  241. drawfillbox (0, 0, maxx, maxy, blue)
  242. Draw.Text ("Do you want to restart? Y/N", 200, 600, font3, white)
  243. View.Update
  244. get choice
  245. if choice = ('y') then
  246. player1score := 9
  247. player2score := 9
  248. loading
  249. Pong
  250. elsif choice = ('n') then
  251. Window.Close (defWinID)
  252. end if
  253. end loop
  254. Music.PlayFileStop
  255. end loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement