Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. Dim ghostmove As Integer
  2. Dim foodgone As Boolean
  3. Dim lives As Integer
  4. Dim time As Integer
  5. Dim points As Integer
  6.  
  7.  
  8. Private Sub deadtime_Timer()
  9. time = time + 1
  10. If time > 4999 Then
  11. Timer3.Enabled = False
  12.  
  13. End Sub
  14.  
  15. Private Sub Form_KeyDown(Keycode As Integer, Shift As Integer)
  16. If Keycode = vbKeyUp Then
  17. PacmanR.Tag = "up"
  18. PacmanR.Picture = LoadPicture("Pacman up.ico")
  19. End If
  20.  
  21. If Keycode = vbKeyDown Then
  22. PacmanR.Tag = "down"
  23. PacmanR.Picture = LoadPicture("Pacman down.ico")
  24. End If
  25.  
  26. If Keycode = vbKeyLeft Then
  27. PacmanR.Tag = "left"
  28. PacmanR.Picture = LoadPicture("Pacman left.ico")
  29. End If
  30.  
  31. If Keycode = vbKeyRight Then
  32. PacmanR.Tag = "right"
  33. PacmanR.Picture = LoadPicture("Pacman forward.ico")
  34. End If
  35. End Sub
  36. Public Function overlap(a As Shape, b As Image)
  37.  
  38. If a.Left + a.Width > b.Left And a.Left < b.Left + b.Width And a.Top + a.Height > b.Top And a.Top < b.Top + b.Height Then
  39. overlap = True
  40. Else
  41. overlap = False
  42. End If
  43.  
  44.  
  45. End Function
  46.  
  47. Public Function overlap2(a As Image, b As Image)
  48.  
  49. If a.Left + a.Width > b.Left And a.Left < b.Left + b.Width And a.Top + a.Height > b.Top And a.Top < b.Top + b.Height Then
  50. overlap2 = True
  51. Else
  52. overlap2 = False
  53. End If
  54.  
  55.  
  56. End Function
  57.  
  58.  
  59. Private Sub Form_Load()
  60. ghostmove = 40
  61. lives = 3
  62. foodgone = False
  63. For x = 0 To 20
  64. Htrack(x).Visible = False
  65. Next
  66. For x = 0 To 24
  67. Vtrack(x).Visible = False
  68. Next
  69.  
  70. End Sub
  71.  
  72.  
  73.  
  74. Private Sub Timer1_Timer()
  75. Label1.Caption = points
  76. If PacmanR.Tag = "right" Then
  77. PacmanR.Left = PacmanR.Left + 50
  78. If PacmanR.Picture = Pacmanclosedleft.Picture Then
  79. PacmanR.Picture = Pacmanforward.Picture
  80. Else
  81. PacmanR.Picture = Pacmanclosedleft.Picture
  82. End If
  83.  
  84. For x = 3 To 37
  85. If overlap(barrier(x), PacmanR) = True Then
  86. PacmanR.Left = PacmanR.Left - 50
  87. End If
  88. Next
  89. End If
  90.  
  91. If PacmanR.Tag = "left" Then
  92. PacmanR.Left = PacmanR.Left - 50
  93. If PacmanR.Picture = Pacmanclosedleft.Picture Then
  94. PacmanR.Picture = PacmanL.Picture
  95. Else
  96. PacmanR.Picture = Pacmanclosedleft.Picture
  97. End If
  98.  
  99.  
  100. For x = 3 To 37
  101. If overlap(barrier(x), PacmanR) = True Then
  102. PacmanR.Left = PacmanR.Left + 50
  103. End If
  104. Next
  105. End If
  106.  
  107. If PacmanR.Tag = "up" Then
  108. PacmanR.Top = PacmanR.Top - 50
  109. If PacmanR.Picture = Pacmanclosedup.Picture Then
  110. PacmanR.Picture = PacmanU.Picture
  111. Else
  112. PacmanR.Picture = Pacmanclosedup.Picture
  113. End If
  114.  
  115.  
  116. For x = 3 To 37
  117. If overlap(barrier(x), PacmanR) = True Then
  118. PacmanR.Top = PacmanR.Top + 50
  119. End If
  120. Next
  121. End If
  122.  
  123. If PacmanR.Tag = "down" Then
  124. PacmanR.Top = PacmanR.Top + 50
  125. If PacmanR.Picture = Pacmanclosedup.Picture Then
  126. PacmanR.Picture = PacmanD.Picture
  127. Else
  128. PacmanR.Picture = Pacmanclosedup.Picture
  129. End If
  130.  
  131.  
  132. For x = 3 To 37
  133. If overlap(barrier(x), PacmanR) = True Then
  134. PacmanR.Top = PacmanR.Top - 50
  135. End If
  136. Next
  137. End If
  138.  
  139. For y = 0 To 55
  140. If overlap(smallfood(y), PacmanR) = True Then
  141. smallfood(y).Visible = False
  142. smallfood(y).Left = smallfood(y).Left + 10000
  143. points = points + 1
  144. End If
  145.  
  146.  
  147.  
  148. Next
  149. ' eating bigger food turns on timer and makes tag dead
  150. For z = 0 To 3
  151.  
  152. If overlap(bigfood(z), PacmanR) = True Then
  153. For x = 0 To 3
  154. ghost(x).Tag = "dead"
  155. ghost(x).Picture = ghostdeadpt2.Picture
  156. Next
  157.  
  158. ghostmove = -ghostmove
  159. Timer3.Enabled = True
  160. deadtime.Enabled = True
  161. bigfood(z).Visible = False
  162. points = points + 1
  163. bigfood(z).Left = bigfood(z).Left + 10000
  164. End If
  165. Next
  166.  
  167. ' movement of horizontal track and when not to move
  168. For x = 0 To 3
  169. If ghost(x).Tag <> "timeout" Then
  170. For y = 0 To 20
  171. If overlap(Htrack(y), ghost(x)) = True Then
  172. If PacmanR.Left > ghost(x).Left Then
  173. ghost(x).Left = ghost(x).Left + ghostmove
  174. If overlap(Htrack(y), ghost(x)) = False Then
  175. ghost(x).Left = ghost(x).Left - ghostmove
  176. End If
  177. Else
  178. ghost(x).Left = ghost(x).Left - ghostmove
  179. If overlap(Htrack(y), ghost(x)) = False Then
  180. ghost(x).Left = ghost(x).Left + ghostmove
  181. End If
  182. End If
  183. End If
  184.  
  185. Next
  186. End If
  187. Next
  188. Label3.Caption = ghost(2).Tag
  189.  
  190. ' ghost bunching up and movement on tracks
  191. For x = 0 To 3
  192. If ghost(x).Tag <> "timeout" Then
  193. For y = 0 To 24
  194. If overlap(Vtrack(y), ghost(x)) = True Then
  195. If PacmanR.Top > ghost(x).Top Then
  196. ghost(x).Top = ghost(x).Top + ghostmove
  197. If overlap(Vtrack(y), ghost(x)) = False Then
  198. ghost(x).Top = ghost(x).Top - ghostmove
  199. End If
  200. Else
  201. ghost(x).Top = ghost(x).Top - ghostmove
  202. If overlap(Vtrack(y), ghost(x)) = False Then
  203. ghost(x).Top = ghost(x).Top + ghostmove
  204. End If
  205. End If
  206. End If
  207.  
  208. Next
  209. End If
  210. Next
  211.  
  212. 'overlapping ghosts so that they dont bunch up
  213. For x = 0 To 3
  214. For y = 0 To 3
  215. If overlap2(ghost(x), ghost(y)) = True And x <> y Then
  216. If ghost(x).Tag <> "timeout" Then
  217. ghost(y).Tag = "timeout"
  218. Timer2.Enabled = True
  219. End If
  220. End If
  221. Next
  222. Next
  223. 'overlapping of ghosts and pacman
  224. For x = 0 To 3
  225. If overlap2(ghost(x), PacmanR) = True And ghost(x).Tag <> "dead" Then
  226. ghost(x).Top = 3720
  227. ghost(x).Left = 8460
  228. lives = lives - 1
  229. End If
  230.  
  231. Next
  232. 'when ghost attack pacman then he loses lives
  233. If overlap2(ghost(0), PacmanR) = True Then
  234.  
  235. lives = lives - 1
  236. End If
  237.  
  238.  
  239.  
  240. If lives = 2 Then
  241. alive3.Visible = False
  242. End If
  243.  
  244. If lives = 1 Then
  245. alive2.Visible = False
  246. End If
  247.  
  248. If lives = 0 Then
  249. alive1.Visible = False
  250. MsgBox " you lose"
  251. End
  252. End If
  253. 'sets lives and score to win game
  254. lives = 3
  255. If points = 60 Then
  256. MsgBox "you win"
  257. End
  258. End If
  259. End Sub
  260. ' controls the ghosts when they hit timeout
  261.  
  262. Private Sub Timer2_Timer()
  263. For x = 0 To 3
  264. ghost(x).Tag = ""
  265. Next
  266.  
  267. Timer2.Enabled = False
  268. End Sub
  269. 'when big pellet is eaten timer runs
  270. Private Sub Timer3_Timer()
  271.  
  272. time = time + 1
  273. For x = 0 To 3
  274. 'loads all regular images after timer is done and replaces ghostmove
  275. ghost(x).Tag = ""
  276. Next
  277. ghost(0).Picture = LoadPicture("blue ghost.ico")
  278. ghost(1).Picture = LoadPicture("pink ghost.ico")
  279. ghost(2).Picture = LoadPicture("yellow ghost.ico")
  280. ghost(3).Picture = LoadPicture("red ghost.ico")
  281. Timer3.Enabled = False
  282. ghostmove = ghostmove - ghostmove - ghostmove
  283. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement