You knew it was coming eventually - vertically moving walls. Fortunately, our MovingWall structure should properly handle all vertical movement. The only thing we need to add is smush tests. While this may seem to be pretty easy since all vertical movement collisions concerning moving walls would smush the player, things get complicated if the wall is moving horizontally and vertically. If the player on the moving wall collides with a wall, we need some way of determining if the player collided with the wall vertically or horizontally. We've already done horizontal pushing and smushing, and all vertical walls coming together smush the player (you can't move the player back down into the wall), but since the moving walls do these at the same time by themselves, we cannot check which movement direction caused the player to collide with the wall. So, we need to remodel the MovingWall Structure so that, at the least, we can make the horizontal and vertical movements into separate calls.
Public Sub MoveHorizontal() 'This subroutine does just like the Movewall does, but only in the horizontal, with cx, left and right. rect.Offset(cx, 0) 'Move. If rect.Right > bound.Right OrElse rect.Left < bound.Left Then 'When the wall hits the edge of our boundary, then it must begin moving in the other direction. cx = -cx End If End Sub Public Sub MoveVertical() 'Same as MoveWall, but only in the vertical, with cy, top and bottom. rect.Offset(0, cy) 'Move. If rect.Bottom > bound.Bottom OrElse rect.Top < bound.Top Then 'This is for vertical movement direction switching. cy = -cy End If End Sub |
If MobileWall.dX < 0 Then 'The wall is moving left. MobileWall.MoveHorizontal() 'This does horizontal movement for the wall. If MobileWall.Loc.IntersectsWith(PlayerLoc) Then If Not TouchingWall Then 'Move the player to the left side of this wall. PlayerLoc.Offset(MobileWall.Loc.Left - PlayerLoc.Right, 0) TouchingWall = True If PlayerLoc.Right < LeftEnd AndAlso Not IsJumping Then IsJumping = True 'We are not really jumping, but we are falling. MobileIndex = -1 'We are not standing on anything now, because we are jumping. PlayerVeloc = 0 'Since we are falling from rest, the initial velocity will be zero. End If Else IsGoner = True 'The player has been smushed. Lose a life. PlayerVeloc = SBARINITIALVELOCITY End If End If ElseIf MobileWall.dX > 0 Then 'The wall is moving right. MobileWall.MoveHorizontal() 'This does all of the movement for the wall. If MobileWall.Loc.IntersectsWith(PlayerLoc) Then If Not TouchingWall Then 'Move the player to the right side of this wall. PlayerLoc.Offset(MobileWall.Loc.Right - PlayerLoc.Left, 0) TouchingWall = True If PlayerLoc.Left > RightEnd AndAlso Not IsJumping Then IsJumping = True 'We are falling. MobileIndex = -1 'We are not standing on anything now, because we are jumping. PlayerVeloc = 0 'A fall from rest. End If Else IsGoner = True 'The player has been smushed. Lose a life. PlayerVeloc = SBARINITIALVELOCITY End If End If Else MobileWall.MoveHorizontal() 'This does all of the movement for the wall. End If MobileWall.MoveVertical() 'Vertical movement here. If MobileWall.Loc.IntersectsWith(PlayerLoc) Then If Not IsJumping Then IsGoner = True 'The player has been smushed. Lose a life. PlayerVeloc = SBARINITIALVELOCITY End If End If |
PlayerLoc.Offset(0, MobileWall.dY) For Each Wall In Walls If PlayerLoc.IntersectsWith(Wall) Then IsGoner = True 'The player has been smushed. Lose a life. PlayerVeloc = SBARINITIALVELOCITY End If Next |
For Each MobileWall In MobileWalls If PlayerLoc.IntersectsWith(MobileWall.Loc) Then IsGoner = True 'The player has been smushed. Lose a life. PlayerVeloc = SBARINITIALVELOCITY End If Next MobileWall = DirectCast(MobileWalls(R), MovingWall) |