Previously, I talked about adding a platform to the form. Now, we want to add more than one platform. Let's face it: you can only do so much with one platform (circus acts come to mind, but then, you need a flaming hoop). So, we need more platforms. Ideally, we will have an undetermined number of platforms in each level. Each level will be on the same form, and we'll just tweak the variables on it. Since the number of platforms is unknown, we can just store them into an ArrayList, the .NET version of the I-don't-know-how-big-my-storage-is-going-to-be storage. Let's declare our ArrayList.
Dim Platforms As ArrayList 'This will store the platforms that are in this level. |
Platforms = New ArrayList(3) 'Initialize/instantiate the platforms arraylist. Platforms.Add(Rectangle.FromLTRB(50, 415, 160, LANDHEIGHT)) Platforms.Add(Rectangle.FromLTRB(100, 465, 185, LANDHEIGHT)) Platforms.Add(Rectangle.FromLTRB(150, 515, 210, LANDHEIGHT)) 'Create three platforms. |
Platform = Rectangle.FromLTRB(150, 515, 210, LANDHEIGHT) 'Instantiate our platform |
GFX.FillRectangle(Brushes.Tan, Platform) GFX.DrawRectangle(Pens.RosyBrown, Platform) 'I'm not into interior decorating, so the only thing I can say about these colors is that 'they'd better be a light brown persuasion. This draws the platform. |
For Each Platform In Platforms 'Loop through each platform in the arraylist. GFX.FillRectangle(Brushes.Tan, Platform) GFX.DrawRectangle(Pens.RosyBrown, Platform) 'I'm not into interior decorating, so the only thing I can say about these colors is that 'they'd better be a light brown persuasion. This draws the platform. Next |
If PlayerLoc.Bottom >= Me.LANDHEIGHT Then 'Check if we are touching the ground (another RECT advantage). IsJumping = False 'Stop the jump: we have hit the ground. LeftEnd = 0 : RightEnd = MAPWIDTH 'Set the endpoints for the ground. AnimCycler = 0 'Reset the animation cycler: it has been counting during the jump. PlayerLoc.Offset(0, LANDHEIGHT - PlayerLoc.Bottom) 'Move the player to stand on the land properly. Else For Each Platform In Platforms 'Looking at each platform in the platform array. If PlayerVeloc > 0 AndAlso PlayerLoc.Bottom >= Platform.Top AndAlso PlayerLoc.Bottom - SHOULDER <= Platform.Top Then If PlayerLoc.Left < Platform.Right AndAlso PlayerLoc.Right > Platform.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. LeftEnd = Platform.Left : RightEnd = Platform.Right 'Set the endpoints for the platform. AnimCycler = 0 'Reset cycler. PlayerLoc.Offset(0, Platform.Top - PlayerLoc.Bottom) 'Move the player onto this platform. End If End If Next End If |