Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim bool_isfalling, bool_isjumping As Boolean ' true or false for jumping or falling
- Dim bool_onaplank As Boolean ' mario is safe on a plank
- Dim i As Integer ' loop variable
- Dim jumpspeed As Integer
- Private Sub fallingtimer_Timer()
- 'loop through and check to see if mario collides with any planks
- mario.Top = mario.Top - 5
- For i = 0 To plank.Count - 1
- 'mario's right side, plank's left
- If mario.Left + mario.Width >= plank(i).Left Then
- 'mario's left side, plank's right
- If mario.Left <= plank(i).Left + plank(i).Width Then
- 'mario bottom vs plank top
- If mario.Top + mario.Height >= plank(i).Top Then
- 'mario bottom vs plank bottom
- If mario.Top + mario.Height <= plank(i).Top + plank(i).Height Then
- 'mario is touching this plank, but him on top
- 'of it, and stop falling
- mario.Top = plank(i).Top - mario.Height
- bool_onaplank = False
- End If
- End If
- End If
- End If
- Next i
- 'if bool_isfalling is true now, that means mario isn't touching
- 'any planks, so make him fall
- If bool_onaplank = False Then
- mario.Top = mario.Top + 50
- 'check to see if he fell off of screen
- If mario.Top >= Form1.Height Then
- MsgBox "Mario died"
- End
- fallingtimer.Enabled = False
- End If
- bool_isfalling = True
- Else
- bool_isfalling = True
- End If
- End Sub
- Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
- If KeyCode = 65 Then
- mleft.Enabled = True
- End If
- If KeyCode = 68 Then
- mright.Enabled = True
- End If
- If KeyCode = 32 Then
- 'If bool_isfalling = False And bool_isjumping = True Then
- jumptimer.Enabled = True
- fallingtimer.Enabled = False
- 'End If
- End If
- End Sub
- Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
- If KeyCode = 65 Then
- mleft.Enabled = False
- End If
- If KeyCode = 68 Then
- mright.Enabled = False
- End If
- If KeyCode = 32 Then
- 'If bool_isfalling = True And bool_isjumping = False Then
- jumptimer.Enabled = False
- fallingtimer.Enabled = True
- 'End If
- End If
- End Sub
- Private Sub Form_Load()
- bool_isfalling = False ' initializing variable -- good technique change this code to describe to variable
- bool_isjumping = False ' initializing variable -- good technique change this code to describe to variable
- bool_onaplank = False ' initializing variable -- good technique change this code to describe to variable
- jumpspeed = 125
- End Sub
- Private Sub jumptimer_Timer()
- bool_isjumping = True
- mario.Top = mario.Top - jumpspeed
- 'slow down the jump every time timer is triggered to make it look like gravity is slowing mario down
- jumpspeed = jumpspeed - 8
- fallingtimer.Enabled = False
- jumptimer.Enabled = True
- If jumpspeed <= 0 Then
- 'finished the jump- start falling again, stop jump, reset
- jumpspeed = 125
- fallingtimer.Enabled = True
- jumptimer.Enabled = False
- bool_isjumping = False
- bool_onaplank = False
- End If
- If mario.Top >= Form1.Height Then
- mario.Top = Form1.Top - 100
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement