Advertisement
TermSpar

Jump Cubes Level Code

Mar 13th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.01 KB | None | 0 0
  1. Public Class frmLevel1
  2.     Dim isJumping As Boolean = False
  3.     Dim gravitySpeed As Integer = 0
  4.     Dim moveSpeed As Integer = 10
  5.     Dim points As Integer
  6.     Dim pause As Boolean
  7.     Public deathCount As Integer
  8.     Private Sub frmLevel1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  9.         My.Settings.continuePlaying = Me
  10.     End Sub
  11.     Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  12.         Select Case e.KeyCode
  13.  
  14.             Case Keys.Up
  15.                 For Each p As Control In Me.Controls
  16.                     If TypeOf p Is PictureBox Then
  17.                         If p.Tag = "vine" Then
  18.                             If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  19.                                 My.Computer.Audio.Play(My.Resources.jumpPad, AudioPlayMode.Background)
  20.                                 tmrUp.Start()
  21.                                 isJumping = False
  22.                                 tmrGravity.Stop()
  23.                             End If
  24.                         End If
  25.                         End If
  26.                 Next
  27.             Case Keys.Right
  28.                 tmrRight.Start()
  29.             Case Keys.Left
  30.                 tmrLeft.Start()
  31.         End Select
  32.     End Sub
  33.  
  34.     Private Sub tmrUp_Tick(sender As System.Object, e As System.EventArgs) Handles tmrUp.Tick
  35.         picPlayer.Top -= moveSpeed
  36.         isJumping = True
  37.     End Sub
  38.  
  39.     Private Sub tmrLeft_Tick(sender As System.Object, e As System.EventArgs) Handles tmrLeft.Tick
  40.         picPlayer.Left -= moveSpeed
  41.     End Sub
  42.  
  43.     Private Sub tmrRight_Tick(sender As System.Object, e As System.EventArgs) Handles tmrRight.Tick
  44.         picPlayer.Left += moveSpeed
  45.     End Sub
  46.  
  47.     Private Sub tmrGameLoop_Tick(sender As System.Object, e As System.EventArgs) Handles tmrGameLoop.Tick
  48.         If picPlayer.Bounds.IntersectsWith(picAir.Bounds) Then
  49.             If isJumping = False Then
  50.                 tmrGravity.Start()
  51.             End If
  52.  
  53.         ElseIf picPlayer.Bounds.IntersectsWith(picGround.Bounds) Then
  54.             tmrGravity.Stop()
  55.  
  56.         ElseIf picPlayer.Bounds.Top < 0 Then
  57.             tmrGravity.Start()
  58.             isJumping = False
  59.         End If
  60.  
  61.         For Each p As Control In Me.Controls
  62.             If TypeOf p Is PictureBox Then
  63.                 If p.Tag = "platform" Then
  64.                     If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  65.                         tmrGravity.Stop()
  66.                     End If
  67.  
  68.                 ElseIf p.Tag = "invisBound" Then
  69.                     If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  70.                         tmrGravity.Start()
  71.                         picCoin1.Location = New Point(291, 86)
  72.                         picCoin2.Location = New Point(452, 86)
  73.                         picCoint3.Location = New Point(1055, 86)
  74.                         picPlayer.Location = New Point(841, 567)
  75.                         picFinish.BackColor = Color.Lime
  76.                         points = 0
  77.                         deathCount += 1
  78.                         Me.Text = "Level 1 (Keys: 0)"
  79.                         isJumping = False
  80.                     End If
  81.  
  82.                 ElseIf p.Tag = "checkPoint" Then
  83.                     If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  84.                         If points = 3 Then
  85.                             My.Computer.Audio.Play(My.Resources.levelUp, AudioPlayMode.Background)
  86.                             frmLevel2.Show()
  87.                             Me.Close()
  88.                         Else
  89.                             My.Computer.Audio.Play(My.Resources.deniedAccess, AudioPlayMode.Background)
  90.                             picFinish.BackColor = Color.Red
  91.                         End If
  92.                     End If
  93.  
  94.                 ElseIf p.Tag = "coin" Then
  95.                     If picPlayer.Bounds.IntersectsWith(p.Bounds) Then
  96.                         points += 1
  97.                         Me.Text = "Level 1 (Keys: " & points & ")"
  98.                         p.Location = New Point(132132, 3213)
  99.                         My.Computer.Audio.Play(My.Resources.coinSound, AudioPlayMode.Background)
  100.                     End If
  101.                 End If
  102.             End If
  103.         Next
  104.     End Sub
  105.  
  106.     Private Sub tmrGravity_Tick(sender As System.Object, e As System.EventArgs) Handles tmrGravity.Tick
  107.         gravitySpeed = 15
  108.         picPlayer.Top += gravitySpeed
  109.     End Sub
  110.  
  111.     Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  112.         Select Case e.KeyCode
  113.             Case Keys.Up
  114.                 isJumping = False
  115.                 tmrUp.Stop()
  116.  
  117.             Case Keys.Right
  118.                 tmrRight.Stop()
  119.  
  120.             Case Keys.Left
  121.                 tmrLeft.Stop()
  122.         End Select
  123.     End Sub
  124.  
  125.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  126.         lblResume.Hide()
  127.         tmrGameLoop.Start()
  128.     End Sub
  129.  
  130.     Private Sub lblSettings_Click(sender As System.Object, e As System.EventArgs) Handles lblSettings.Click
  131.         lblResume.Show()
  132.         tmrPause.Start()
  133.         frmSettings.Show()
  134.     End Sub
  135.  
  136.     Private Sub lblResume_Click(sender As System.Object, e As System.EventArgs) Handles lblResume.Click
  137.         tmrGameLoop.Start()
  138.         tmrGravity.Start()
  139.         tmrPause.Stop()
  140.         picPlayer.Top -= 15
  141.         lblResume.Hide()
  142.     End Sub
  143.  
  144.     Private Sub lblResume_MouseEnter(sender As Object, e As System.EventArgs) Handles lblResume.MouseEnter
  145.         lblResume.BackColor = Color.DarkTurquoise
  146.     End Sub
  147.  
  148.     Private Sub lblResume_MouseLeave(sender As Object, e As System.EventArgs) Handles lblResume.MouseLeave
  149.         lblResume.BackColor = Color.Cyan
  150.     End Sub
  151.  
  152.     Private Sub tmrPause_Tick(sender As System.Object, e As System.EventArgs) Handles tmrPause.Tick
  153.         tmrGameLoop.Stop()
  154.         tmrGravity.Stop()
  155.         tmrUp.Stop()
  156.         tmrLeft.Stop()
  157.         tmrRight.Stop()
  158.     End Sub
  159. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement