Advertisement
Guest User

mario code for allan

a guest
Jan 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1.  
  2. Dim bool_isfalling, bool_isjumping As Boolean ' true or false for jumping or falling
  3.  
  4. Dim bool_onaplank As Boolean ' mario is safe on a plank
  5.  
  6. Dim i As Integer ' loop variable
  7.  
  8. Dim jumpspeed As Integer
  9.  
  10.  
  11. Private Sub fallingtimer_Timer()
  12. 'loop through and check to see if mario collides with any planks
  13.  
  14. mario.Top = mario.Top - 5
  15.  
  16. For i = 0 To plank.Count - 1
  17.  
  18. 'mario's right side, plank's left
  19.  
  20. If mario.Left + mario.Width >= plank(i).Left Then
  21.  
  22. 'mario's left side, plank's right
  23.  
  24. If mario.Left <= plank(i).Left + plank(i).Width Then
  25.  
  26. 'mario bottom vs plank top
  27.  
  28. If mario.Top + mario.Height >= plank(i).Top Then
  29.  
  30. 'mario bottom vs plank bottom
  31.  
  32. If mario.Top + mario.Height <= plank(i).Top + plank(i).Height Then
  33.  
  34. 'mario is touching this plank, but him on top
  35.  
  36. 'of it, and stop falling
  37.  
  38. mario.Top = plank(i).Top - mario.Height
  39.  
  40. bool_onaplank = False
  41.  
  42. End If
  43.  
  44. End If
  45.  
  46. End If
  47.  
  48. End If
  49.  
  50. Next i
  51.  
  52.  
  53.  
  54. 'if bool_isfalling is true now, that means mario isn't touching
  55.  
  56. 'any planks, so make him fall
  57.  
  58. If bool_onaplank = False Then
  59.  
  60. mario.Top = mario.Top + 50
  61.  
  62. 'check to see if he fell off of screen
  63.  
  64. If mario.Top >= Form1.Height Then
  65.  
  66. MsgBox "Mario died"
  67. End
  68.  
  69. fallingtimer.Enabled = False
  70.  
  71. End If
  72.  
  73. bool_isfalling = True
  74.  
  75. Else
  76.  
  77. bool_isfalling = True
  78.  
  79. End If
  80.  
  81. End Sub
  82.  
  83. Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
  84.  
  85. If KeyCode = 65 Then
  86.  
  87. mleft.Enabled = True
  88.  
  89. End If
  90.  
  91. If KeyCode = 68 Then
  92.  
  93. mright.Enabled = True
  94.  
  95. End If
  96.  
  97. If KeyCode = 32 Then
  98.  
  99. 'If bool_isfalling = False And bool_isjumping = True Then
  100.  
  101. jumptimer.Enabled = True
  102. fallingtimer.Enabled = False
  103.  
  104. 'End If
  105.  
  106. End If
  107.  
  108. End Sub
  109.  
  110. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  111.  
  112. If KeyCode = 65 Then
  113.  
  114. mleft.Enabled = False
  115.  
  116. End If
  117.  
  118. If KeyCode = 68 Then
  119.  
  120. mright.Enabled = False
  121.  
  122. End If
  123.  
  124. If KeyCode = 32 Then
  125.  
  126. 'If bool_isfalling = True And bool_isjumping = False Then
  127.  
  128. jumptimer.Enabled = False
  129. fallingtimer.Enabled = True
  130.  
  131. 'End If
  132.  
  133. End If
  134.  
  135. End Sub
  136.  
  137. Private Sub Form_Load()
  138.  
  139. bool_isfalling = False ' initializing variable -- good technique change this code to describe to variable
  140. bool_isjumping = False ' initializing variable -- good technique change this code to describe to variable
  141.  
  142. bool_onaplank = False ' initializing variable -- good technique change this code to describe to variable
  143.  
  144. jumpspeed = 125
  145.  
  146. End Sub
  147.  
  148. Private Sub jumptimer_Timer()
  149.  
  150. bool_isjumping = True
  151. mario.Top = mario.Top - jumpspeed
  152.  
  153. 'slow down the jump every time timer is triggered to make it look like gravity is slowing mario down
  154.  
  155. jumpspeed = jumpspeed - 8
  156. fallingtimer.Enabled = False
  157. jumptimer.Enabled = True
  158.  
  159. If jumpspeed <= 0 Then
  160.  
  161. 'finished the jump- start falling again, stop jump, reset
  162.  
  163. jumpspeed = 125
  164. fallingtimer.Enabled = True
  165. jumptimer.Enabled = False
  166. bool_isjumping = False
  167. bool_onaplank = False
  168.  
  169. End If
  170.  
  171. If mario.Top >= Form1.Height Then
  172.  
  173. mario.Top = Form1.Top - 100
  174.  
  175. End If
  176.  
  177.  
  178. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement