Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim ghostmove As Integer
- Dim foodgone As Boolean
- Dim lives As Integer
- Dim time As Integer
- Dim points As Integer
- Private Sub deadtime_Timer()
- time = time + 1
- If time > 4999 Then
- Timer3.Enabled = False
- End Sub
- Private Sub Form_KeyDown(Keycode As Integer, Shift As Integer)
- If Keycode = vbKeyUp Then
- PacmanR.Tag = "up"
- PacmanR.Picture = LoadPicture("Pacman up.ico")
- End If
- If Keycode = vbKeyDown Then
- PacmanR.Tag = "down"
- PacmanR.Picture = LoadPicture("Pacman down.ico")
- End If
- If Keycode = vbKeyLeft Then
- PacmanR.Tag = "left"
- PacmanR.Picture = LoadPicture("Pacman left.ico")
- End If
- If Keycode = vbKeyRight Then
- PacmanR.Tag = "right"
- PacmanR.Picture = LoadPicture("Pacman forward.ico")
- End If
- End Sub
- Public Function overlap(a As Shape, b As Image)
- 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
- overlap = True
- Else
- overlap = False
- End If
- End Function
- Public Function overlap2(a As Image, b As Image)
- 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
- overlap2 = True
- Else
- overlap2 = False
- End If
- End Function
- Private Sub Form_Load()
- ghostmove = 40
- lives = 3
- foodgone = False
- For x = 0 To 20
- Htrack(x).Visible = False
- Next
- For x = 0 To 24
- Vtrack(x).Visible = False
- Next
- End Sub
- Private Sub Timer1_Timer()
- Label1.Caption = points
- If PacmanR.Tag = "right" Then
- PacmanR.Left = PacmanR.Left + 50
- If PacmanR.Picture = Pacmanclosedleft.Picture Then
- PacmanR.Picture = Pacmanforward.Picture
- Else
- PacmanR.Picture = Pacmanclosedleft.Picture
- End If
- For x = 3 To 37
- If overlap(barrier(x), PacmanR) = True Then
- PacmanR.Left = PacmanR.Left - 50
- End If
- Next
- End If
- If PacmanR.Tag = "left" Then
- PacmanR.Left = PacmanR.Left - 50
- If PacmanR.Picture = Pacmanclosedleft.Picture Then
- PacmanR.Picture = PacmanL.Picture
- Else
- PacmanR.Picture = Pacmanclosedleft.Picture
- End If
- For x = 3 To 37
- If overlap(barrier(x), PacmanR) = True Then
- PacmanR.Left = PacmanR.Left + 50
- End If
- Next
- End If
- If PacmanR.Tag = "up" Then
- PacmanR.Top = PacmanR.Top - 50
- If PacmanR.Picture = Pacmanclosedup.Picture Then
- PacmanR.Picture = PacmanU.Picture
- Else
- PacmanR.Picture = Pacmanclosedup.Picture
- End If
- For x = 3 To 37
- If overlap(barrier(x), PacmanR) = True Then
- PacmanR.Top = PacmanR.Top + 50
- End If
- Next
- End If
- If PacmanR.Tag = "down" Then
- PacmanR.Top = PacmanR.Top + 50
- If PacmanR.Picture = Pacmanclosedup.Picture Then
- PacmanR.Picture = PacmanD.Picture
- Else
- PacmanR.Picture = Pacmanclosedup.Picture
- End If
- For x = 3 To 37
- If overlap(barrier(x), PacmanR) = True Then
- PacmanR.Top = PacmanR.Top - 50
- End If
- Next
- End If
- For y = 0 To 55
- If overlap(smallfood(y), PacmanR) = True Then
- smallfood(y).Visible = False
- smallfood(y).Left = smallfood(y).Left + 10000
- points = points + 1
- End If
- Next
- ' eating bigger food turns on timer and makes tag dead
- For z = 0 To 3
- If overlap(bigfood(z), PacmanR) = True Then
- For x = 0 To 3
- ghost(x).Tag = "dead"
- ghost(x).Picture = ghostdeadpt2.Picture
- Next
- ghostmove = -ghostmove
- Timer3.Enabled = True
- deadtime.Enabled = True
- bigfood(z).Visible = False
- points = points + 1
- bigfood(z).Left = bigfood(z).Left + 10000
- End If
- Next
- ' movement of horizontal track and when not to move
- For x = 0 To 3
- If ghost(x).Tag <> "timeout" Then
- For y = 0 To 20
- If overlap(Htrack(y), ghost(x)) = True Then
- If PacmanR.Left > ghost(x).Left Then
- ghost(x).Left = ghost(x).Left + ghostmove
- If overlap(Htrack(y), ghost(x)) = False Then
- ghost(x).Left = ghost(x).Left - ghostmove
- End If
- Else
- ghost(x).Left = ghost(x).Left - ghostmove
- If overlap(Htrack(y), ghost(x)) = False Then
- ghost(x).Left = ghost(x).Left + ghostmove
- End If
- End If
- End If
- Next
- End If
- Next
- Label3.Caption = ghost(2).Tag
- ' ghost bunching up and movement on tracks
- For x = 0 To 3
- If ghost(x).Tag <> "timeout" Then
- For y = 0 To 24
- If overlap(Vtrack(y), ghost(x)) = True Then
- If PacmanR.Top > ghost(x).Top Then
- ghost(x).Top = ghost(x).Top + ghostmove
- If overlap(Vtrack(y), ghost(x)) = False Then
- ghost(x).Top = ghost(x).Top - ghostmove
- End If
- Else
- ghost(x).Top = ghost(x).Top - ghostmove
- If overlap(Vtrack(y), ghost(x)) = False Then
- ghost(x).Top = ghost(x).Top + ghostmove
- End If
- End If
- End If
- Next
- End If
- Next
- 'overlapping ghosts so that they dont bunch up
- For x = 0 To 3
- For y = 0 To 3
- If overlap2(ghost(x), ghost(y)) = True And x <> y Then
- If ghost(x).Tag <> "timeout" Then
- ghost(y).Tag = "timeout"
- Timer2.Enabled = True
- End If
- End If
- Next
- Next
- 'overlapping of ghosts and pacman
- For x = 0 To 3
- If overlap2(ghost(x), PacmanR) = True And ghost(x).Tag <> "dead" Then
- ghost(x).Top = 3720
- ghost(x).Left = 8460
- lives = lives - 1
- End If
- Next
- 'when ghost attack pacman then he loses lives
- If overlap2(ghost(0), PacmanR) = True Then
- lives = lives - 1
- End If
- If lives = 2 Then
- alive3.Visible = False
- End If
- If lives = 1 Then
- alive2.Visible = False
- End If
- If lives = 0 Then
- alive1.Visible = False
- MsgBox " you lose"
- End
- End If
- 'sets lives and score to win game
- lives = 3
- If points = 60 Then
- MsgBox "you win"
- End
- End If
- End Sub
- ' controls the ghosts when they hit timeout
- Private Sub Timer2_Timer()
- For x = 0 To 3
- ghost(x).Tag = ""
- Next
- Timer2.Enabled = False
- End Sub
- 'when big pellet is eaten timer runs
- Private Sub Timer3_Timer()
- time = time + 1
- For x = 0 To 3
- 'loads all regular images after timer is done and replaces ghostmove
- ghost(x).Tag = ""
- Next
- ghost(0).Picture = LoadPicture("blue ghost.ico")
- ghost(1).Picture = LoadPicture("pink ghost.ico")
- ghost(2).Picture = LoadPicture("yellow ghost.ico")
- ghost(3).Picture = LoadPicture("red ghost.ico")
- Timer3.Enabled = False
- ghostmove = ghostmove - ghostmove - ghostmove
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement