Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmLevel5
- Dim diseaseCount As Integer = 1 'Player animation
- Dim jumpCount As Integer = 1 'Jump animation
- Dim moveSpeed As Integer = 25 'Player speed
- Dim infectCount As Integer = 1 'Enemy animation
- Dim isJumping As Boolean = False 'Check if player is jumping
- Dim jumpSpeed As Integer = 20 'Player jump speed
- Dim moveBoundSpeed As Integer = 20 'Speed that bounds move at
- #Region "Enemy Movement Variables"
- Dim rnd1 As Integer
- Dim rnd2 As Integer
- Dim rnd3 As Integer
- Dim rnd4 As Integer
- Dim rnd5 As Integer
- Dim rnd6 As Integer
- Dim rnd7 As Integer
- Dim rnd8 As Integer
- Dim rnd9 As Integer
- Dim rnd10 As Integer
- Dim rnd11 As Integer
- #End Region
- Dim goingLeft As Boolean 'Check if player is going left
- Dim leftSpeed As Integer = 3 'Enemy back movement speed
- Dim enemySpeed As Integer = 9 'Speed enemies move
- Dim killCount As Integer = 0 'Count how many enemies are killed
- Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
- Select Case diseaseCount
- Case 1
- picPlayer.Image = My.Resources.disease1
- diseaseCount += 1
- Case 2
- picPlayer.Image = My.Resources.disease2
- diseaseCount += 1
- Case 3
- picPlayer.Image = My.Resources.disease3
- diseaseCount += 1
- Case 4
- picPlayer.Image = My.Resources.disease4
- diseaseCount += 1
- Case 5
- picPlayer.Image = My.Resources.disease5
- diseaseCount = 1
- End Select
- End Sub
- Private Sub tmrJump_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrJump.Tick
- 'Jump animation
- Select Case jumpCount
- Case 1
- picPlayer.Image = My.Resources.jump1
- jumpCount += 1
- Case 2
- picPlayer.Image = My.Resources.jump2
- jumpCount += 1
- Case 3
- picPlayer.Image = My.Resources.jump3
- jumpCount += 1
- Case 4
- picPlayer.Image = My.Resources.jump4
- jumpCount += 1
- Case 5
- picPlayer.Image = My.Resources.jump5
- jumpCount = 1
- End Select
- End Sub
- Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
- 'Movement keys
- Select Case e.KeyCode
- Case Keys.Right
- tmrRight.Start()
- tmrMove.Start()
- Case Keys.Left
- tmrLeft.Start()
- goingLeft = True
- tmrMoveBack.Start()
- Case Keys.Up
- isJumping = True
- If infectCount <= 10 Then
- tmrActualJump.Start()
- tmrJump.Start()
- tmrMove.Stop()
- Else
- tmrActualJump.Stop()
- tmrJump.Stop()
- End If
- End Select
- End Sub
- Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
- 'Stop moving on key release
- Select Case e.KeyCode
- Case Keys.Right
- tmrRight.Stop()
- diseaseCount = 1
- tmrMove.Stop()
- Case Keys.Left
- tmrLeft.Stop()
- goingLeft = False
- tmrMoveBack.Stop()
- Case Keys.Up
- tmrActualJump.Stop()
- isJumping = False
- picPlayer.Image = My.Resources.disease1
- tmrJump.Stop()
- tmrMove.Stop()
- End Select
- End Sub
- Private Sub tmrRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRight.Tick
- picPlayer.Left += moveSpeed
- End Sub
- Private Sub tmrActualJump_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrActualJump.Tick
- picPlayer.Top -= jumpSpeed
- End Sub
- Private Sub tmrGameLogic_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGameLogic.Tick
- '↓↓↓↓ yay physics ↓↓↓↓
- 'If player hits bound, reset position
- For Each p As PictureBox In Me.Controls
- If p.Tag = "end" Or p.Tag = "bound" Then
- If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
- picPlayer.Location = New Point(67, 654)
- End If
- End If
- Next
- 'Gravity logic (if player isn't jumping then fall)
- If picPlayer.Bounds.IntersectsWith(picGravity.Bounds) And isJumping = False Then
- tmrGravity.Start()
- ElseIf picPlayer.Bounds.IntersectsWith(picGround.Bounds) Then
- tmrGravity.Stop()
- End If
- 'If player collides with enemy
- For Each en As PictureBox In Me.Controls
- If en.Tag = "enemy" Then
- If picPlayer.Bounds.IntersectsWith(en.Bounds) Then
- If isJumping <> True Then 'If player isn't jumping then reset their position and move enemies forward + 20
- picPlayer.Location = New Point(67, 579)
- For Each enemy As PictureBox In Me.Controls
- If enemy.Tag = "enemy" Then
- enemySpeed += 0.5
- End If
- Next
- Else 'If player is jumping "kill" enemy
- en.Location = New Point(423423, 42342) 'easier to reset position than to destroy :D
- en.Visible = False
- killCount += 1
- My.Computer.Audio.Play(My.Resources.Just_Gore_Expansion_Gore_Splatter_Sound_Effect, AudioPlayMode.Background)
- End If
- End If
- End If
- Next
- 'If player hits moving bound
- For Each m As PictureBox In Me.Controls
- If m.Tag = "moveBound" Then
- If picPlayer.Bounds.IntersectsWith(m.Bounds) Then
- picPlayer.Location = New Point(556, 601)
- For Each enemy As PictureBox In Me.Controls
- If enemy.Tag = "enemy" Then
- enemy.Left -= 20
- End If
- Next
- End If
- End If
- Next
- 'Check how many enemies have been killed
- Select Case killCount
- Case 1
- picBad1.Visible = False
- Case 2
- picBad2.Visible = False
- Case 3
- picbad3.Visible = False
- Case 4
- picBad4.Visible = False
- Case 5
- picBad5.Visible = False
- Case 6
- picBad6.Visible = False
- Case 7
- picBad7.Visible = False
- Case 8
- picBad8.Visible = False
- Case 9
- picBad9.Visible = False
- Case 10
- picBad10.Visible = False
- Case 11
- picBad11.Visible = False
- frmLevel6.Show()
- Me.Close()
- End Select
- 'Set random enemy movement
- rnd1 = Int(Rnd() * 4) + 1
- rnd2 = Int(Rnd() * 4) + 1
- rnd3 = Int(Rnd() * 4) + 1
- rnd4 = Int(Rnd() * 4) + 1
- rnd5 = Int(Rnd() * 4) + 1
- rnd6 = Int(Rnd() * 4) + 1
- rnd7 = Int(Rnd() * 4) + 1
- rnd8 = Int(Rnd() * 4) + 1
- rnd9 = Int(Rnd() * 4) + 1
- rnd10 = Int(Rnd() * 4) + 1
- rnd11 = Int(Rnd() * 4) + 1
- 'Random movement logic
- enemyMovement()
- 'Reset enemy position if they hit lower or upper boundary
- For Each p As PictureBox In Me.Controls
- If p.Tag = "enemy" Then
- For Each b As PictureBox In Me.Controls
- If b.Tag = "bound" Then
- If p.Bounds.IntersectsWith(b.Bounds) Then
- p.Location = New Point(1220, 543)
- End If
- End If
- Next
- End If
- Next
- 'Player loses if a disease gets passed
- For Each p As PictureBox In Me.Controls
- If p.Tag = "enemy" Then
- For Each b As PictureBox In Me.Controls
- If b.Tag = "end" Then
- If p.Bounds.IntersectsWith(b.Bounds) Then
- frmGameOver.Show()
- Me.Close()
- End If
- End If
- Next
- End If
- Next
- End Sub
- Private Sub frmLevel1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- tmrMoveBound2.Start()
- tmrMoveBound.Start()
- My.Settings.currentLevel = 1
- tmrEnemy.Start()
- tmrGameLogic.Start()
- End Sub
- Private Sub tmrEnemy_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrEnemy.Tick
- For Each p As PictureBox In Me.Controls
- If p.Tag = "enemy" Then
- Select Case infectCount
- Case 1
- p.Image = My.Resources.enemy1
- infectCount += 1
- Case 2
- p.Image = My.Resources.enemy2
- infectCount += 1
- Case 3
- p.Image = My.Resources.enemy3
- infectCount += 1
- Case 4
- p.Image = My.Resources.enemy4
- infectCount += 1
- Case 5
- p.Image = My.Resources.enemy5
- infectCount = 1
- End Select
- End If
- Next
- End Sub
- Private Sub tmrGravity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGravity.Tick
- picPlayer.Top += 25
- End Sub
- Private Sub tmrLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLeft.Tick
- picPlayer.Left -= 25
- End Sub
- #Region "Enemy Movement"
- Sub enemyMovement()
- 'Random movement logic
- If rnd1 = 1 Then
- picEnemy.Left += leftSpeed
- ElseIf rnd1 = 2 Then
- picEnemy.Top += enemySpeed
- picEnemy.Left -= enemySpeed
- ElseIf rnd1 = 3 Then
- picEnemy.Top -= enemySpeed
- picEnemy.Left -= enemySpeed
- ElseIf rnd1 = 4 Then
- picEnemy.Left -= enemySpeed
- End If
- If rnd2 = 1 Then
- picEnemy2.Left += leftSpeed
- ElseIf rnd2 = 2 Then
- picEnemy2.Top += enemySpeed
- picEnemy2.Left -= enemySpeed
- ElseIf rnd2 = 3 Then
- picEnemy2.Top -= enemySpeed
- picEnemy2.Left -= enemySpeed
- ElseIf rnd2 = 4 Then
- picEnemy2.Left -= enemySpeed
- End If
- If rnd3 = 1 Then
- picEnemy3.Left += leftSpeed
- ElseIf rnd3 = 2 Then
- picEnemy3.Top += enemySpeed
- picEnemy3.Left -= enemySpeed
- ElseIf rnd3 = 3 Then
- picEnemy3.Top -= enemySpeed
- picEnemy3.Left -= enemySpeed
- ElseIf rnd3 = 4 Then
- picEnemy3.Left -= enemySpeed
- End If
- If rnd4 = 1 Then
- picEnemy4.Left += leftSpeed
- ElseIf rnd4 = 2 Then
- picEnemy4.Top += enemySpeed
- picEnemy4.Left -= enemySpeed
- ElseIf rnd4 = 3 Then
- picEnemy4.Top -= enemySpeed
- picEnemy4.Left -= enemySpeed
- ElseIf rnd4 = 4 Then
- picEnemy4.Left -= enemySpeed
- End If
- If rnd5 = 1 Then
- picEnemy5.Left += leftSpeed
- ElseIf rnd5 = 2 Then
- picEnemy5.Top += enemySpeed
- picEnemy5.Left -= enemySpeed
- ElseIf rnd5 = 3 Then
- picEnemy5.Top -= enemySpeed
- picEnemy5.Left -= enemySpeed
- ElseIf rnd5 = 4 Then
- picEnemy5.Left -= enemySpeed
- End If
- If rnd6 = 1 Then
- picEnemy6.Left += leftSpeed
- ElseIf rnd6 = 2 Then
- picEnemy6.Top += enemySpeed
- picEnemy6.Left -= enemySpeed
- ElseIf rnd6 = 3 Then
- picEnemy6.Top -= enemySpeed
- picEnemy6.Left -= enemySpeed
- ElseIf rnd6 = 4 Then
- picEnemy6.Left -= enemySpeed
- End If
- If rnd7 = 1 Then
- picEnemy7.Left += leftSpeed
- ElseIf rnd7 = 2 Then
- picEnemy7.Top += enemySpeed
- picEnemy7.Left -= enemySpeed
- ElseIf rnd7 = 3 Then
- picEnemy7.Top -= enemySpeed
- picEnemy7.Left -= enemySpeed
- ElseIf rnd7 = 4 Then
- picEnemy7.Left -= enemySpeed
- End If
- If rnd8 = 1 Then
- picEnemy8.Left += leftSpeed
- ElseIf rnd8 = 2 Then
- picEnemy8.Top += enemySpeed
- picEnemy8.Left -= enemySpeed
- ElseIf rnd8 = 3 Then
- picEnemy8.Top -= enemySpeed
- picEnemy8.Left -= enemySpeed
- ElseIf rnd8 = 4 Then
- picEnemy8.Left -= enemySpeed
- End If
- If rnd9 = 1 Then
- picEnemy9.Left += leftSpeed
- ElseIf rnd9 = 2 Then
- picEnemy9.Top += enemySpeed
- picEnemy9.Left -= enemySpeed
- ElseIf rnd9 = 3 Then
- picEnemy9.Top -= enemySpeed
- picEnemy9.Left -= enemySpeed
- ElseIf rnd9 = 4 Then
- picEnemy9.Left -= enemySpeed
- End If
- If rnd10 = 1 Then
- picEnemy10.Left += leftSpeed
- ElseIf rnd10 = 2 Then
- picEnemy10.Top += enemySpeed
- picEnemy10.Left -= enemySpeed
- ElseIf rnd10 = 3 Then
- picEnemy10.Top -= enemySpeed
- picEnemy10.Left -= enemySpeed
- ElseIf rnd10 = 4 Then
- picEnemy10.Left -= enemySpeed
- End If
- If rnd11 = 1 Then
- picEnemy11.Left += leftSpeed
- ElseIf rnd11 = 2 Then
- picEnemy11.Top += enemySpeed
- picEnemy11.Left -= enemySpeed
- ElseIf rnd11 = 3 Then
- picEnemy11.Top -= enemySpeed
- picEnemy11.Left -= enemySpeed
- ElseIf rnd11 = 4 Then
- picEnemy11.Left -= enemySpeed
- End If
- End Sub
- #End Region
- Private Sub tmrMoveBound_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBound.Tick
- If picMove.Bounds.IntersectsWith(picBounds.Bounds) Then
- tmrBoundRight.Start()
- tmrBoundLeft.Stop()
- ElseIf picMove.Bounds.IntersectsWith(picBound2.Bounds) Then
- tmrBoundRight.Stop()
- tmrBoundLeft.Start()
- End If
- End Sub
- Private Sub tmrBoundRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundRight.Tick
- picMove.Left += moveBoundSpeed
- End Sub
- Private Sub tmrBoundLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundLeft.Tick
- picMove.Left -= moveBoundSpeed
- End Sub
- Private Sub tmrMoveBound2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBound2.Tick
- If picMove2.Bounds.IntersectsWith(picBounds.Bounds) Then
- tmrBoundRight2.Start()
- tmrBoundLeft2.Stop()
- ElseIf picMove2.Bounds.IntersectsWith(picBound2.Bounds) Then
- tmrBoundRight2.Stop()
- tmrBoundLeft2.Start()
- End If
- End Sub
- Private Sub tmrBoundLeft2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundLeft2.Tick
- picMove2.Left -= moveBoundSpeed
- End Sub
- Private Sub tmrBoundRight2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundRight2.Tick
- picMove2.Left += moveBoundSpeed
- End Sub
- 'Move player in reverse
- Private Sub tmrMoveBack_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBack.Tick
- Select Case diseaseCount
- Case 1
- picPlayer.Image = My.Resources.disease1
- picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
- diseaseCount += 1
- Case 2
- picPlayer.Image = My.Resources.disease2
- picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
- diseaseCount += 1
- Case 3
- picPlayer.Image = My.Resources.disease3
- picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
- diseaseCount += 1
- Case 4
- picPlayer.Image = My.Resources.disease4
- picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
- diseaseCount += 1
- Case 5
- picPlayer.Image = My.Resources.disease5
- picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
- diseaseCount = 1
- End Select
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement