Using Graphics: Making a Lander Game - Part 2
To add another level of difficulty to our game, we are going to make a landing area, which the pilot must land on, otherwise they will drown in the gooey bogs of the planet Zogg, where this game happens to take place. And we don't want that to happen to our poor defenceless intergalactic space travelers do we?
The platform will be draw with the land, so that is where the major modifications will occur. The platform will appear at a random place each time, so the Randomize Timer call should be moved to just after the if statement. Then we need to add a a little code to draw the platform. The code will finally look like this:
If curtime = 0 Then Randomize Timer
' Draw the earth picEarth.Line (0, picEarth.ScaleHeight _ - 30)-(picEarth.ScaleWidth, picEarth.ScaleHeight), _ vbWhite, BF ' Draw landing area randnum = CLng(Rnd * (picEarth.ScaleWidth - _ (picEarth.ScaleWidth / 5))) picEarth.Line (randnum, picEarth.ScaleHeight _ - 30)-(randnum + (picEarth.ScaleWidth / 5), _ picEarth.ScaleHeight - 28), vbRed, BF safeleft = randnum saferight = randnum + (picEarth.ScaleWidth / 5) ' Draw stars..etc
You have probably also spotted the safeleft and saferight variables. These should be both declared in the General Declarations section as Long:
'The left and right points of the landing area Private safeleft As Long Private saferight As Long
Now that we have these two variables, we must also check that the craft has landed within the allowed area. This is done by modifying the line that checks that the craft is not moving too fast:
' Previously: If vSpeed > -2 Then ' Change to: If vSpeed > -2 And hSpeed > -2 And LandX > safeleft _ And (LandX + piclander.ScaleWidth) < saferight Then
The now checks that you are not moving to fast in the horizontal and vertical dimensions, and also checks that you are within the allowed bounds of the platform.
Page 4 of 5