First, there is a bug that I did not address in the last episode. The character gets
killed if you ride a lift going down. So, we'll just add this quick check in place
Now that we have our moving walls fully functional, it's time to get them into the file.
Getting them into the file is not much of a problem. The real problem is going to come
when we try to create a moving wall object with the editor, since it consists of two
rectangles and two more integers. But, first, let's knock out the SaveLevel routine for
MovingWalls. There are 10 properties that need to be saved.
For Each MobileWall In MobileWalls
If PlayerLoc.IntersectsWith(MobileWall.Loc) AndAlso MobileWalls.IndexOf(MobileWall) <> R Then
IsGoner = True
'The player has been smushed. Lose a life.
PlayerVeloc = SBARINITIALVELOCITY
MobileWall = DirectCast(MobileWalls(R), MovingWall)
It's important that the arguments be supplied in the order that they go into the
constructor. It'll save you some time.
Now, update all of your files so that each will have the number of moving walls written
into it in the right place. (even 0 needs to be written)
Now, to read a file that has MobileWall data in it, we read each number back from the
file into our MobileWall structures one by one.
'Moving walls written to file.
For Each MobileWall In MobileWalls
Don't forget to remove the arraylist instantiation that occurs in Form_Load.
Now that we've got that out of the way, let's work on the editor.
MobileWalls = New ArrayList(BR.ReadInt32)
For LV = 1 To MobileWalls.Capacity
MobileWalls.Add(New MovingWall(Rectangle.FromLTRB(BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32()), _
BR.ReadInt32(), BR.ReadInt32(), _
Rectangle.FromLTRB(BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32(), BR.ReadInt32())))
'Moving wall data from file.
To take two rectangles, we should clearly take two selection rectangles, because it
would be really hard for the editor (possibly you) to make a decent rectangle with four
number prompts. The dX and dY properties can be handled by a number prompt, by the way,
similar to the one we did for Jumpboard.
Now, the question is how do we keep up with two selection rectangles? An answer: these
selection rectangles will be made one at a time... after we make one, we'll hold it in
memory until the second one is made. From there, we'll make our movingwall from the
two selection rectangles. For even more ease of use, we can automatically set it so that
the larger rectangle will become the boundary and the smaller will become the moving
Now, let's get to it. Our editor key for Moving Walls can be M, so we add support for
the key in the KeyDown event.
Now, we go into the MouseUp event and from there, we should be able to coordinate the
two selection rectangle.
ElseIf e.KeyCode = Keys.M Then
If Not IsMouseDown Then
MDObject = "M"c
That wasn't too hard. I even was shocked to see that the
trackbars handled the negatives nicely. Have fun.
If MemoryRect.IsEmpty Then
MemoryRect = Placed
Dim Mw As MovingWall 'Will hold the data that we are about to collect.
Clock.Enabled = False
'Stop timed execution.
If Placed.Width > MemoryRect.Width Then
'Placed is bigger, therefore it must be the boundary.
Mw.Boundary = Placed
Mw.Loc = MemoryRect
'Placed is smaller, it must be the actual wall.
Mw.Boundary = MemoryRect
Mw.Loc = Placed
Mw.dX = NumericBox.Show(-24, 24, "X Velocity")
Mw.dY = NumericBox.Show(-24, 24, "Y Velocity")
'Set the wall velocity.
'Add it to our list of moving wall.
Clock.Enabled = True
'continue timed execution.