Advertisement
TermSpar

2D Platformer

Apr 23rd, 2016
1,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.33 KB | None | 0 0
  1. Public Class frm2DPlatformer
  2.     Dim moveSpeed As Integer = 15
  3.     Dim isJumping As Boolean
  4.  
  5.     Private Sub frm2DPlatformer_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  6.         Select Case e.KeyCode
  7.             Case Keys.Right
  8.                 tmrRight.Start()
  9.             Case Keys.Left
  10.                 tmrLeft.Start()
  11.             Case Keys.Up
  12.                 tmrUp.Start()
  13.                 isJumping = True
  14.         End Select
  15.     End Sub
  16.  
  17.     Private Sub tmrRight_Tick(sender As System.Object, e As System.EventArgs) Handles tmrRight.Tick
  18.         picPlayer.Left += moveSpeed
  19.     End Sub
  20.  
  21.     Private Sub frm2DPlatformer_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  22.         Select Case e.KeyCode
  23.             Case Keys.Right
  24.                 tmrRight.Stop()
  25.             Case Keys.Left
  26.                 tmrLeft.Stop()
  27.             Case Keys.Up
  28.                 tmrUp.Stop()
  29.                 isJumping = False
  30.         End Select
  31.     End Sub
  32.  
  33.     Private Sub tmrLeft_Tick(sender As System.Object, e As System.EventArgs) Handles tmrLeft.Tick
  34.         picPlayer.Left -= moveSpeed
  35.     End Sub
  36.  
  37.     Private Sub tmrUp_Tick(sender As System.Object, e As System.EventArgs) Handles tmrUp.Tick
  38.         picPlayer.Top -= moveSpeed
  39.     End Sub
  40.  
  41.     Private Sub frm2DPlatformer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  42.         tmrGameLogic.Start()
  43.     End Sub
  44.  
  45.     Private Sub tmrGameLogic_Tick(sender As System.Object, e As System.EventArgs) Handles tmrGameLogic.Tick
  46.         If picPlayer.Bounds.IntersectsWith(picAir.Bounds) Then
  47.             If isJumping = False Then
  48.                 tmrGravity.Start()
  49.             End If
  50.         ElseIf picPlayer.Bounds.IntersectsWith(picGround.Bounds) Then
  51.             tmrGravity.Stop()
  52.         End If
  53.  
  54.         For Each b As Control In Me.Controls
  55.             If TypeOf b Is PictureBox Then
  56.                 If b.Tag = "bound" Then
  57.                     If picPlayer.Bounds.IntersectsWith(b.Bounds) Then
  58.                         tmrGravity.Stop()
  59.                     End If
  60.                 End If
  61.             End If
  62.         Next
  63.  
  64.     End Sub
  65.  
  66.     Private Sub tmrGravity_Tick(sender As System.Object, e As System.EventArgs) Handles tmrGravity.Tick
  67.         picPlayer.Top += moveSpeed
  68.     End Sub
  69. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement