Now, it's time to put some ice into our level. Ice can either function as a platform or a wall. We will do ice like a platform now, but we can always do another ice that functions as a wall. Of course, the most important part of ice is that it must be slippery. To simulate the slipperiness of ice, we will allow the player's horizontal velocity along the ice to change when the left or right button is located (for perfectly frictionless ice, i.e. no slowdown for long periods of time like real ice does). So, as with tradition, we'll set up a test ice platform and draw it first.
Declaration:
Dim IceBrsh As Brush 'How we'll draw the brush. Dim Ices As Integer 'Holds all of the ice platforms in the level. Dim Ice As Rectangle 'Holds the location of the ice. |
IceBrsh = New SolidBrush(Color.FromArgb(192, 32, 128, 255)) 'Translucent cold looking blue brush color. Ice = New Rectangle(1700, 350, 400, 160) 'Creates an ice. Ices = New ArrayList Ices.Add(Ice) 'Create the ices arraylist and add our ice rectangle to it. |
For Each Ice In Ices Ice.Offset(-ScreenLeft, -ScreenTop) GFX.FillRectangle(IceBrsh, Ice) GFX.DrawRectangle(Pens.DarkCyan, Ice) Ice.Offset(ScreenLeft, ScreenTop) 'Draws the ice. Next |
Dim HorizontVeloc As Integer 'How fast the player is moving left-right on surface such as ice. Dim OnIce As Boolean 'True if the player is walking on ice. |
For Each Ice In Ices 'Looking at each platform in the platform array. If PlayerVeloc > 0 AndAlso PlayerLoc.Bottom >= Ice.Top AndAlso PlayerLoc.Bottom - PlayerVeloc - GRAVITYTH <= Ice.Top Then If PlayerLoc.Left < Ice.Right AndAlso PlayerLoc.Right > Ice.Left Then 'The player has landed on this platform. He needs to be updated. 'See how many advantages there are to using a Rectangle. IsJumping = False 'Hit the ground, we are not jumping. OnIce = True 'Just landed on some ice. LeftEnd = Platform.Left : RightEnd = Platform.Right 'Set the endpoints for the platform. AnimCycler = 0 'Reset cycler. If GoLeft Then If GoFast Then HorizontVeloc = -MOVESPEED - (MOVESPEED >> 1) Else HorizontVeloc = -MOVESPEED End If ElseIf GoRight Then If GoFast Then HorizontVeloc = MOVESPEED + (MOVESPEED >> 1) Else HorizontVeloc = MOVESPEED End If End If 'The above lines set the initial movement speed when the player initially lands on the ice. PlayerLoc.Offset(0, Platform.Top - PlayerLoc.Bottom) 'Move the player onto this platform. End If End If Next |
Const ICEMAXSPEED As Integer = MOVESPEED * 2 'The maximum speed that the player can move on the ice - should be slightly larger than fast movement speed. |
If GoLeft Then If GoFast Then If OnIce Then HorizontVeloc -= (MOVESPEED + (MOVESPEED >> 1)) If -HorizontVeloc > ICEMAXSPEED Then HorizontVeloc = -ICEMAXSPEED End If Else PlayerLoc.Offset(-MOVESPEED - (MOVESPEED >> 1), 0) 'When Shift is pressed the player runs. 'Runs to the left. End If Else If OnIce Then HorizontVeloc -= MOVESPEED If -HorizontVeloc > ICEMAXSPEED Then HorizontVeloc = -ICEMAXSPEED End If Else PlayerLoc.Offset(-MOVESPEED, 0) 'Move player left. End If End If LeftMovementChecks() CharDirec = 0 'Look left. 'Now, update the animation cycler. AnimCycler = (AnimCycler + 1) Mod WALKINGFRAMECOUNT ElseIf GoRight Then If GoFast Then If OnIce Then HorizontVeloc += (MOVESPEED + (MOVESPEED >> 1)) If HorizontVeloc > ICEMAXSPEED Then HorizontVeloc = ICEMAXSPEED End If Else PlayerLoc.Offset(MOVESPEED + (MOVESPEED >> 1), 0) 'Runs to the right. End If Else If OnIce Then HorizontVeloc += MOVESPEED If HorizontVeloc > ICEMAXSPEED Then HorizontVeloc = ICEMAXSPEED End If Else PlayerLoc.Offset(MOVESPEED, 0) 'Move player right. End If End If RightMovementChecks() CharDirec = 1 'Look right. 'Now, update the animation cycler. AnimCycler = (AnimCycler + 1) Mod WALKINGFRAMECOUNT End If |
OnIce = False : HorizontVeloc = 0 'We are no longer on ice. |
If OnIce Then PlayerLoc.Offset(HorizontVeloc, 0) 'Slide to some direction. If HorizontVeloc < 0 Then LeftMovementChecks() 'Check if we went too far left while sliding. ElseIf HorizontVeloc > 0 Then RightMovementChecks() 'Check if we went too far right while sliding. End If If Not GoLeft OrElse Not GoRight Then AnimCycler = (AnimCycler + 1) Mod WALKINGFRAMECOUNT End If End If |
'Creates an ice. Ices = New ArrayList Ices.Add(New Rectangle(1500, 350, 400, 218)) Ices.Add(Rectangle.FromLTRB(1350, 150, 1520, LANDHEIGHT)) Ices.Add(Rectangle.FromLTRB(1620, 150, 1820, LANDHEIGHT)) 'Create the ices arraylist and add our ice rectangle to it. |
'Ice written to file. BW.Write(Ices.Count) 'Next, each platform is written to file. For Each Ice In Ices BW.Write(Ice.Left) BW.Write(Ice.Top) BW.Write(Ice.Right) BW.Write(Ice.Bottom) Next |
Ices = New ArrayList(BR.ReadInt32()) For LV = 1 To Ices.Capacity 'Capacity is the number that you've specified in the New arraylist's constructor. Ices.Add(Rectangle.FromLTRB(BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32())) 'Read four integers from the file and put it into a rectangle. Next |
ElseIf e.KeyCode = Keys.I Then If Not IsMouseDown Then MDObject = "I"c End If |
Case "I"c 'For ice. Ices.Insert(0, Placed) 'Add an ice platform. |
Else 'The player has jumped up into the wall. PlayerLoc.Offset(0, MobileWall.Loc.Bottom - PlayerLoc.Top) 'Move the player to under the wall. PlayerVeloc = MobileWall.dY '*************************BUG FIX********************** 'Make the player start falling down. |