Welcome back. I have been running a little low on ideas to implement, but I finally thought of few. In this episode, we will set up jumping boards, spring boards, or whatever they are being called nowadays. The jumping board is going to be a simple block with an arrow on it, and if the player so happen to step or fall on it, the player is launched upwards. Aside from stepping on top of it, the jumpboard will behave as a wall, which makes the player unable to walk into it. The jumpboard will be capable of bouncing the player at a custom velocity defined within the board. For particularly big values (like -72), the player will go up quickly. The character would also fall quickly if it jumped from this block. So, adding a terminal velocity wouldn't hurt. Remember that the terminal velocity is the maximum velocity that our character will reach when falling. Since our character starts the jump at -32 (or -16 if you are using the old one), the terminal velocity would more than likely be bigger than this value... 50 or 45 might be good. I will use 45. Now, let's set up terminal velocity before we set up jumping boards. Of course, we will first have our terminal velocity constant value.
Const TERMINALVELOCITY As Integer = 45 'The maximum velocity that the character reaches while falling. |
PlayerVeloc += GRAVITY 'dV = (PlayerVeloc +=) A (GRAVITY) 'Moves the character according to its velocity, gravity, and location. If PlayerVeloc >= TERMINALVELOCITY Then 'We're in TV. PlayerVeloc = TERMINALVELOCITY 'Limit the velocity. End If |
Public Structure JumpingBoard Public Loc As Rectangle 'Location. Public ReboundVeloc As Integer 'The velocity at which the player will jump to when he lands on this board. Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal W As Integer, ByVal H As Integer, ByVal Rebound As Integer) 'Quickly set our jumping board. Loc = New Rectangle(X, Y, W, H) ReboundVeloc = Rebound End Sub End Structure |
Const JUMPBOARDSIZE As Integer = 16 'Size of the jumping board. |
Dim Jumpboards As ArrayList 'Holds all of the jump boards in the level. Dim Jumpboard As JumpingBoard 'A board that automatically boosts the player by giving him a large jumping speed. Dim Jumpbmp As Bitmap 'Holds the picture for the jumping board. |
Jumpbmp = New Bitmap(Application.StartupPath & "\..\Uonly.jpg") 'Picture of the jumping board, an up arrow. Jumpboards = New ArrayList(10) 'Initialize the jumping board arraylist. Jumpboards.Add(New JumpingBoard(1250, 224, JUMPBOARDSIZE, JUMPBOARDSIZE, -56)) 'Add this jumping board to the level. |
For Each Jumpboard In Jumpboards Jumpboard.Loc.Offset(-ScreenLeft, -ScreenTop) 'We did need to move it! GFX.DrawImage(Jumpbmp, Jumpboard.Loc) Jumpboard.Loc.Offset(ScreenLeft, ScreenTop) Next |
For Each Jumpboard In Jumpboards 'Check with each wall. If PlayerLoc.IntersectsWith(Jumpboard.Loc) Then PlayerLoc.Offset(Jumpboard.Loc.Right - PlayerLoc.Left, 0) 'Move the player to the edge of this jumping board. End If Next |
For Each Jumpboard In Jumpboards If PlayerLoc.IntersectsWith(Jumpboard.Loc) Then PlayerLoc.Offset(Jumpboard.Loc.Left - PlayerLoc.Right, 0) 'Move the player to the edge of this jumping board.. End If Next |
For Each Jumpboard In Jumpboards If PlayerLoc.IntersectsWith(Jumpboard.Loc) Then If IsJumping = False Then 'If the player has landed on a platform. IsJumping = True 'Knock the player off the platform and make the player PlayerLoc.Offset(0, Jumpboard.Loc.Bottom - PlayerLoc.Top + GRAVITYTH) 'Move the player to under the wall. We need GRAVITYTH so that the player climb up to the platform. PlayerVeloc = 0 'Make the player start falling. ElseIf PlayerVeloc > 0 Then 'If player is falling, then the player will land on the wall. PlayerVeloc = Jumpboard.ReboundVeloc 'Bounce the player off of this board. PlayerLoc.Offset(0, Jumpboard.Loc.Top - PlayerLoc.Bottom) 'Position the player to stand on this wall. Else 'The player has jumped up into the wall. PlayerLoc.Offset(0, Jumpboard.Loc.Bottom - PlayerLoc.Top) 'Move the player to under the wall. PlayerVeloc = 0 'Make the player start falling down. End If End If Next |
ElseIf e.KeyCode = Keys.J Then If Not IsMouseDown Then MDObject = "J"c End If |
Case "J"c Clock.Enabled = False 'Lighten processing until we're done. Dim Jb As JumpingBoard Jb.ReboundVeloc = -NumericBox.Show(32, 100) 'Note the negative. I wouldn't trust a trackbar to be negative. 'Gets a value that was input by the user. If Jb.ReboundVeloc = 1 Then 'If the cancel returns negative 1, negative -1 would be positive 1. Jb.ReboundVeloc = -65 'Let this be the default. These could stand as declared constants as well. End If Jb.Loc = New Rectangle(Mu.X + ScreenLeft, Mu.Y + ScreenTop, JUMPBOARDSIZE, JUMPBOARDSIZE) 'Fulfill the jumping board's position. Jumpboards.Insert(0, Jb) 'And insert the newly created jumpboard at the head of the jumpboard arraylist. Clock.Enabled = True 'Re enable the processing. |
<font color=#6699FF>'Jumping boards written to file.</font> BW.Write(Jumpboards.Count) <font color=#0000FF>For Each</font> Jumpboard <font color=#0000FF>In</font> Jumpboards BW.Write(Jumpboard.Loc.Left) BW.Write(Jumpboard.Loc.Top) BW.Write(Jumpboard.ReboundVeloc) <font color=#0000FF>Next</font> |
Jumpboards = New ArrayList(BR.ReadInt32()) For LV = 1 To Jumpboards.Capacity Jumpboards.Add(New JumpingBoard(BR.ReadInt32(), BR.ReadInt32(), JUMPBOARDSIZE, JUMPBOARDSIZE, BR.ReadInt32())) 'Read jump board from file. The width and height are determined by our constant. Next |
Jumpboards = New ArrayList(10) 'Initialize the jumping board arraylist. Jumpboards.Add(New JumpingBoard(1250, 224, JUMPBOARDSIZE, JUMPBOARDSIZE, -56)) 'Add this jumping board to the level. |