Advertisement
TermSpar

Operation: Humanity Level 5

Apr 25th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.28 KB | None | 0 0
  1. Public Class frmLevel5
  2.     Dim diseaseCount As Integer = 1 'Player animation
  3.     Dim jumpCount As Integer = 1 'Jump animation
  4.     Dim moveSpeed As Integer = 25 'Player speed
  5.     Dim infectCount As Integer = 1 'Enemy animation
  6.     Dim isJumping As Boolean = False 'Check if player is jumping
  7.     Dim jumpSpeed As Integer = 20 'Player jump speed
  8.     Dim moveBoundSpeed As Integer = 20 'Speed that bounds move at
  9.  
  10. #Region "Enemy Movement Variables"
  11.     Dim rnd1 As Integer
  12.     Dim rnd2 As Integer
  13.     Dim rnd3 As Integer
  14.     Dim rnd4 As Integer
  15.     Dim rnd5 As Integer
  16.     Dim rnd6 As Integer
  17.     Dim rnd7 As Integer
  18.     Dim rnd8 As Integer
  19.     Dim rnd9 As Integer
  20.     Dim rnd10 As Integer
  21.     Dim rnd11 As Integer
  22. #End Region
  23.  
  24.     Dim goingLeft As Boolean 'Check if player is going left
  25.     Dim leftSpeed As Integer = 3 'Enemy back movement speed
  26.     Dim enemySpeed As Integer = 9 'Speed enemies move
  27.     Dim killCount As Integer = 0 'Count how many enemies are killed
  28.  
  29.     Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
  30.         Select Case diseaseCount
  31.             Case 1
  32.                 picPlayer.Image = My.Resources.disease1
  33.                 diseaseCount += 1
  34.             Case 2
  35.                 picPlayer.Image = My.Resources.disease2
  36.                 diseaseCount += 1
  37.             Case 3
  38.                 picPlayer.Image = My.Resources.disease3
  39.                 diseaseCount += 1
  40.             Case 4
  41.                 picPlayer.Image = My.Resources.disease4
  42.                 diseaseCount += 1
  43.             Case 5
  44.                 picPlayer.Image = My.Resources.disease5
  45.                 diseaseCount = 1
  46.         End Select
  47.     End Sub
  48.  
  49.     Private Sub tmrJump_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrJump.Tick
  50.         'Jump animation
  51.         Select Case jumpCount
  52.             Case 1
  53.                 picPlayer.Image = My.Resources.jump1
  54.                 jumpCount += 1
  55.             Case 2
  56.                 picPlayer.Image = My.Resources.jump2
  57.                 jumpCount += 1
  58.             Case 3
  59.                 picPlayer.Image = My.Resources.jump3
  60.                 jumpCount += 1
  61.             Case 4
  62.                 picPlayer.Image = My.Resources.jump4
  63.                 jumpCount += 1
  64.             Case 5
  65.                 picPlayer.Image = My.Resources.jump5
  66.                 jumpCount = 1
  67.         End Select
  68.     End Sub
  69.  
  70.     Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  71.         'Movement keys
  72.         Select Case e.KeyCode
  73.             Case Keys.Right
  74.                 tmrRight.Start()
  75.                 tmrMove.Start()
  76.             Case Keys.Left
  77.                 tmrLeft.Start()
  78.                 goingLeft = True
  79.                 tmrMoveBack.Start()
  80.             Case Keys.Up
  81.                 isJumping = True
  82.                 If infectCount <= 10 Then
  83.                     tmrActualJump.Start()
  84.                     tmrJump.Start()
  85.                     tmrMove.Stop()
  86.                 Else
  87.                     tmrActualJump.Stop()
  88.                     tmrJump.Stop()
  89.                 End If
  90.         End Select
  91.     End Sub
  92.  
  93.     Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  94.         'Stop moving on key release
  95.         Select Case e.KeyCode
  96.             Case Keys.Right
  97.                 tmrRight.Stop()
  98.                 diseaseCount = 1
  99.                 tmrMove.Stop()
  100.             Case Keys.Left
  101.                 tmrLeft.Stop()
  102.                 goingLeft = False
  103.                 tmrMoveBack.Stop()
  104.             Case Keys.Up
  105.                 tmrActualJump.Stop()
  106.                 isJumping = False
  107.                 picPlayer.Image = My.Resources.disease1
  108.                 tmrJump.Stop()
  109.                 tmrMove.Stop()
  110.         End Select
  111.     End Sub
  112.  
  113.     Private Sub tmrRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRight.Tick
  114.         picPlayer.Left += moveSpeed
  115.     End Sub
  116.  
  117.     Private Sub tmrActualJump_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrActualJump.Tick
  118.         picPlayer.Top -= jumpSpeed
  119.     End Sub
  120.  
  121.     Private Sub tmrGameLogic_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGameLogic.Tick
  122.  
  123.         '↓↓↓↓ yay physics ↓↓↓↓
  124.  
  125.         'If player hits bound, reset position
  126.         For Each p As PictureBox In Me.Controls
  127.             If p.Tag = "end" Or p.Tag = "bound" Then
  128.                 If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  129.                     picPlayer.Location = New Point(67, 654)
  130.                 End If
  131.             End If
  132.         Next
  133.  
  134.         'Gravity logic (if player isn't jumping  then fall)
  135.         If picPlayer.Bounds.IntersectsWith(picGravity.Bounds) And isJumping = False Then
  136.             tmrGravity.Start()
  137.         ElseIf picPlayer.Bounds.IntersectsWith(picGround.Bounds) Then
  138.             tmrGravity.Stop()
  139.         End If
  140.  
  141.         'If player collides with enemy
  142.         For Each en As PictureBox In Me.Controls
  143.             If en.Tag = "enemy" Then
  144.                 If picPlayer.Bounds.IntersectsWith(en.Bounds) Then
  145.                     If isJumping <> True Then 'If player isn't jumping then reset their position and move enemies forward + 20
  146.                         picPlayer.Location = New Point(67, 579)
  147.                         For Each enemy As PictureBox In Me.Controls
  148.                             If enemy.Tag = "enemy" Then
  149.                                 enemySpeed += 0.5
  150.                             End If
  151.                         Next
  152.                     Else 'If player is jumping "kill" enemy
  153.                         en.Location = New Point(423423, 42342) 'easier to reset position than to destroy :D
  154.                         en.Visible = False
  155.                         killCount += 1
  156.                         My.Computer.Audio.Play(My.Resources.Just_Gore_Expansion_Gore_Splatter_Sound_Effect, AudioPlayMode.Background)
  157.                     End If
  158.                 End If
  159.             End If
  160.         Next
  161.  
  162.         'If player hits moving bound
  163.         For Each m As PictureBox In Me.Controls
  164.             If m.Tag = "moveBound" Then
  165.                 If picPlayer.Bounds.IntersectsWith(m.Bounds) Then
  166.                     picPlayer.Location = New Point(556, 601)
  167.                     For Each enemy As PictureBox In Me.Controls
  168.                         If enemy.Tag = "enemy" Then
  169.                             enemy.Left -= 20
  170.                         End If
  171.                     Next
  172.                 End If
  173.             End If
  174.         Next
  175.  
  176.         'Check how many enemies have been killed
  177.         Select Case killCount
  178.             Case 1
  179.                 picBad1.Visible = False
  180.             Case 2
  181.                 picBad2.Visible = False
  182.             Case 3
  183.                 picbad3.Visible = False
  184.             Case 4
  185.                 picBad4.Visible = False
  186.             Case 5
  187.                 picBad5.Visible = False
  188.             Case 6
  189.                 picBad6.Visible = False
  190.             Case 7
  191.                 picBad7.Visible = False
  192.             Case 8
  193.                 picBad8.Visible = False
  194.             Case 9
  195.                 picBad9.Visible = False
  196.             Case 10
  197.                 picBad10.Visible = False
  198.             Case 11
  199.                 picBad11.Visible = False
  200.                 frmLevel6.Show()
  201.                 Me.Close()
  202.         End Select
  203.  
  204.         'Set random enemy movement
  205.         rnd1 = Int(Rnd() * 4) + 1
  206.         rnd2 = Int(Rnd() * 4) + 1
  207.         rnd3 = Int(Rnd() * 4) + 1
  208.         rnd4 = Int(Rnd() * 4) + 1
  209.         rnd5 = Int(Rnd() * 4) + 1
  210.         rnd6 = Int(Rnd() * 4) + 1
  211.         rnd7 = Int(Rnd() * 4) + 1
  212.         rnd8 = Int(Rnd() * 4) + 1
  213.         rnd9 = Int(Rnd() * 4) + 1
  214.         rnd10 = Int(Rnd() * 4) + 1
  215.         rnd11 = Int(Rnd() * 4) + 1
  216.  
  217.  
  218.         'Random movement logic
  219.         enemyMovement()
  220.  
  221.         'Reset enemy position if they hit lower or upper boundary
  222.         For Each p As PictureBox In Me.Controls
  223.             If p.Tag = "enemy" Then
  224.                 For Each b As PictureBox In Me.Controls
  225.                     If b.Tag = "bound" Then
  226.                         If p.Bounds.IntersectsWith(b.Bounds) Then
  227.                             p.Location = New Point(1220, 543)
  228.                         End If
  229.                     End If
  230.                 Next
  231.             End If
  232.         Next
  233.  
  234.         'Player loses if a disease gets passed
  235.         For Each p As PictureBox In Me.Controls
  236.             If p.Tag = "enemy" Then
  237.                 For Each b As PictureBox In Me.Controls
  238.                     If b.Tag = "end" Then
  239.                         If p.Bounds.IntersectsWith(b.Bounds) Then
  240.                             frmGameOver.Show()
  241.                             Me.Close()
  242.                         End If
  243.                     End If
  244.                 Next
  245.             End If
  246.         Next
  247.     End Sub
  248.  
  249.     Private Sub frmLevel1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  250.         tmrMoveBound2.Start()
  251.         tmrMoveBound.Start()
  252.         My.Settings.currentLevel = 1
  253.         tmrEnemy.Start()
  254.         tmrGameLogic.Start()
  255.     End Sub
  256.  
  257.     Private Sub tmrEnemy_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrEnemy.Tick
  258.         For Each p As PictureBox In Me.Controls
  259.             If p.Tag = "enemy" Then
  260.                 Select Case infectCount
  261.                     Case 1
  262.                         p.Image = My.Resources.enemy1
  263.                         infectCount += 1
  264.                     Case 2
  265.                         p.Image = My.Resources.enemy2
  266.                         infectCount += 1
  267.                     Case 3
  268.                         p.Image = My.Resources.enemy3
  269.                         infectCount += 1
  270.                     Case 4
  271.                         p.Image = My.Resources.enemy4
  272.                         infectCount += 1
  273.                     Case 5
  274.                         p.Image = My.Resources.enemy5
  275.                         infectCount = 1
  276.                 End Select
  277.             End If
  278.         Next
  279.     End Sub
  280.  
  281.     Private Sub tmrGravity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGravity.Tick
  282.         picPlayer.Top += 25
  283.     End Sub
  284.  
  285.     Private Sub tmrLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLeft.Tick
  286.         picPlayer.Left -= 25
  287.     End Sub
  288.  
  289. #Region "Enemy Movement"
  290.     Sub enemyMovement()
  291.         'Random movement logic
  292.         If rnd1 = 1 Then
  293.             picEnemy.Left += leftSpeed
  294.         ElseIf rnd1 = 2 Then
  295.             picEnemy.Top += enemySpeed
  296.             picEnemy.Left -= enemySpeed
  297.         ElseIf rnd1 = 3 Then
  298.             picEnemy.Top -= enemySpeed
  299.             picEnemy.Left -= enemySpeed
  300.         ElseIf rnd1 = 4 Then
  301.             picEnemy.Left -= enemySpeed
  302.         End If
  303.  
  304.         If rnd2 = 1 Then
  305.             picEnemy2.Left += leftSpeed
  306.         ElseIf rnd2 = 2 Then
  307.             picEnemy2.Top += enemySpeed
  308.             picEnemy2.Left -= enemySpeed
  309.         ElseIf rnd2 = 3 Then
  310.             picEnemy2.Top -= enemySpeed
  311.             picEnemy2.Left -= enemySpeed
  312.         ElseIf rnd2 = 4 Then
  313.             picEnemy2.Left -= enemySpeed
  314.         End If
  315.  
  316.         If rnd3 = 1 Then
  317.             picEnemy3.Left += leftSpeed
  318.         ElseIf rnd3 = 2 Then
  319.             picEnemy3.Top += enemySpeed
  320.             picEnemy3.Left -= enemySpeed
  321.         ElseIf rnd3 = 3 Then
  322.             picEnemy3.Top -= enemySpeed
  323.             picEnemy3.Left -= enemySpeed
  324.         ElseIf rnd3 = 4 Then
  325.             picEnemy3.Left -= enemySpeed
  326.         End If
  327.  
  328.         If rnd4 = 1 Then
  329.             picEnemy4.Left += leftSpeed
  330.         ElseIf rnd4 = 2 Then
  331.             picEnemy4.Top += enemySpeed
  332.             picEnemy4.Left -= enemySpeed
  333.         ElseIf rnd4 = 3 Then
  334.             picEnemy4.Top -= enemySpeed
  335.             picEnemy4.Left -= enemySpeed
  336.         ElseIf rnd4 = 4 Then
  337.             picEnemy4.Left -= enemySpeed
  338.         End If
  339.  
  340.         If rnd5 = 1 Then
  341.             picEnemy5.Left += leftSpeed
  342.         ElseIf rnd5 = 2 Then
  343.             picEnemy5.Top += enemySpeed
  344.             picEnemy5.Left -= enemySpeed
  345.         ElseIf rnd5 = 3 Then
  346.             picEnemy5.Top -= enemySpeed
  347.             picEnemy5.Left -= enemySpeed
  348.         ElseIf rnd5 = 4 Then
  349.             picEnemy5.Left -= enemySpeed
  350.         End If
  351.  
  352.         If rnd6 = 1 Then
  353.             picEnemy6.Left += leftSpeed
  354.         ElseIf rnd6 = 2 Then
  355.             picEnemy6.Top += enemySpeed
  356.             picEnemy6.Left -= enemySpeed
  357.         ElseIf rnd6 = 3 Then
  358.             picEnemy6.Top -= enemySpeed
  359.             picEnemy6.Left -= enemySpeed
  360.         ElseIf rnd6 = 4 Then
  361.             picEnemy6.Left -= enemySpeed
  362.         End If
  363.  
  364.         If rnd7 = 1 Then
  365.             picEnemy7.Left += leftSpeed
  366.         ElseIf rnd7 = 2 Then
  367.             picEnemy7.Top += enemySpeed
  368.             picEnemy7.Left -= enemySpeed
  369.         ElseIf rnd7 = 3 Then
  370.             picEnemy7.Top -= enemySpeed
  371.             picEnemy7.Left -= enemySpeed
  372.         ElseIf rnd7 = 4 Then
  373.             picEnemy7.Left -= enemySpeed
  374.         End If
  375.  
  376.         If rnd8 = 1 Then
  377.             picEnemy8.Left += leftSpeed
  378.         ElseIf rnd8 = 2 Then
  379.             picEnemy8.Top += enemySpeed
  380.             picEnemy8.Left -= enemySpeed
  381.         ElseIf rnd8 = 3 Then
  382.             picEnemy8.Top -= enemySpeed
  383.             picEnemy8.Left -= enemySpeed
  384.         ElseIf rnd8 = 4 Then
  385.             picEnemy8.Left -= enemySpeed
  386.         End If
  387.  
  388.         If rnd9 = 1 Then
  389.             picEnemy9.Left += leftSpeed
  390.         ElseIf rnd9 = 2 Then
  391.             picEnemy9.Top += enemySpeed
  392.             picEnemy9.Left -= enemySpeed
  393.         ElseIf rnd9 = 3 Then
  394.             picEnemy9.Top -= enemySpeed
  395.             picEnemy9.Left -= enemySpeed
  396.         ElseIf rnd9 = 4 Then
  397.             picEnemy9.Left -= enemySpeed
  398.         End If
  399.  
  400.         If rnd10 = 1 Then
  401.             picEnemy10.Left += leftSpeed
  402.         ElseIf rnd10 = 2 Then
  403.             picEnemy10.Top += enemySpeed
  404.             picEnemy10.Left -= enemySpeed
  405.         ElseIf rnd10 = 3 Then
  406.             picEnemy10.Top -= enemySpeed
  407.             picEnemy10.Left -= enemySpeed
  408.         ElseIf rnd10 = 4 Then
  409.             picEnemy10.Left -= enemySpeed
  410.         End If
  411.  
  412.         If rnd11 = 1 Then
  413.             picEnemy11.Left += leftSpeed
  414.         ElseIf rnd11 = 2 Then
  415.             picEnemy11.Top += enemySpeed
  416.             picEnemy11.Left -= enemySpeed
  417.         ElseIf rnd11 = 3 Then
  418.             picEnemy11.Top -= enemySpeed
  419.             picEnemy11.Left -= enemySpeed
  420.         ElseIf rnd11 = 4 Then
  421.             picEnemy11.Left -= enemySpeed
  422.         End If
  423.     End Sub
  424. #End Region
  425.  
  426.     Private Sub tmrMoveBound_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBound.Tick
  427.         If picMove.Bounds.IntersectsWith(picBounds.Bounds) Then
  428.             tmrBoundRight.Start()
  429.             tmrBoundLeft.Stop()
  430.         ElseIf picMove.Bounds.IntersectsWith(picBound2.Bounds) Then
  431.             tmrBoundRight.Stop()
  432.             tmrBoundLeft.Start()
  433.         End If
  434.     End Sub
  435.  
  436.     Private Sub tmrBoundRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundRight.Tick
  437.         picMove.Left += moveBoundSpeed
  438.     End Sub
  439.  
  440.     Private Sub tmrBoundLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundLeft.Tick
  441.         picMove.Left -= moveBoundSpeed
  442.     End Sub
  443.  
  444.     Private Sub tmrMoveBound2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBound2.Tick
  445.         If picMove2.Bounds.IntersectsWith(picBounds.Bounds) Then
  446.             tmrBoundRight2.Start()
  447.             tmrBoundLeft2.Stop()
  448.         ElseIf picMove2.Bounds.IntersectsWith(picBound2.Bounds) Then
  449.             tmrBoundRight2.Stop()
  450.             tmrBoundLeft2.Start()
  451.         End If
  452.     End Sub
  453.  
  454.     Private Sub tmrBoundLeft2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundLeft2.Tick
  455.         picMove2.Left -= moveBoundSpeed
  456.     End Sub
  457.  
  458.     Private Sub tmrBoundRight2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBoundRight2.Tick
  459.         picMove2.Left += moveBoundSpeed
  460.     End Sub
  461.  
  462.     'Move player in reverse
  463.     Private Sub tmrMoveBack_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMoveBack.Tick
  464.         Select Case diseaseCount
  465.             Case 1
  466.                 picPlayer.Image = My.Resources.disease1
  467.                 picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
  468.                 diseaseCount += 1
  469.             Case 2
  470.                 picPlayer.Image = My.Resources.disease2
  471.                 picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
  472.                 diseaseCount += 1
  473.             Case 3
  474.                 picPlayer.Image = My.Resources.disease3
  475.                 picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
  476.                 diseaseCount += 1
  477.             Case 4
  478.                 picPlayer.Image = My.Resources.disease4
  479.                 picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
  480.                 diseaseCount += 1
  481.             Case 5
  482.                 picPlayer.Image = My.Resources.disease5
  483.                 picPlayer.Image.RotateFlip(RotateFlipType.Rotate180FlipY)
  484.                 diseaseCount = 1
  485.         End Select
  486.     End Sub
  487. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement