In this episode we are going to let the player become smushed when a moving wall presses
him against another wall.
This should be really simple... all we do is move the player if he touches the moving wall
after it moves.  If, after being moved by a moving wall, the player comes in contact with
another wall, then the player is smushed.
So, first we check each moving wall immediately after it moves.
If the player touches the wall, we need to determine which way it is moving.  This is only
valid before the .MoveWall subroutine, because that changes the direction of the wall's
movement, but we won't know if the player collides with the wall until after the .MoveWall
subroutine.  So, what do we do?  Well, the biggest thing is that our MovingWall structure
should be refined so that this check could be done after the wall moves but before the wall
velocities change.  But, I do have a workaround, as you will see soon (by merely using a bigger
If statement).
First, we need a boolean to determine if the Player has came in contact with the first wall.
        Dim TouchingWall As Boolean
        'This is true when the player has touched a wall.
And then, in our wall movement section (before the IsJumping block) do not replace the call to .MoveWall with this code.
                If MobileWall.dX < 0 Then
                    'The wall is moving left.
                    MobileWall.MoveWall()
                    'This does all of the movement for the wall.
                    If MobileWall.Loc.IntersectsWith(PlayerLoc) Then
                        'Move the player to the left side of this wall.
                        PlayerLoc.Offset(MobileWall.Loc.Left - PlayerLoc.Right, 0)
                        TouchingWall = True
                    End If
                ElseIf MobileWall.dX > 0 Then
                    'The wall is moving right.
                    MobileWall.MoveWall()
                    'This does all of the movement for the wall.
                    If MobileWall.Loc.IntersectsWith(PlayerLoc) Then
                        'Move the player to the right side of this wall.
                        PlayerLoc.Offset(MobileWall.Loc.Right - PlayerLoc.Left, 0)
                        TouchingWall = True
                    End If

                End If
While this code would be fine so far with detecting the player gets smushed between a fixed wall and a moving wall, we can also consider the player colliding with another moving wall here as well. So, we examine TouchingWall when the two rectangles (wall and player). Replace the call to .MoveWall with:
                If MobileWall.dX < 0 Then
                    'The wall is moving left.
                    MobileWall.MoveWall()
                    'This does all of the 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
                        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.MoveWall()
                    '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
                        Else
                            IsGoner = True
                            'The player has been smushed.  Lose a life.
                            PlayerVeloc = SBARINITIALVELOCITY
                        End If
                    End If
                Else
                    MobileWall.MoveWall()
                    'This does all of the movement for the wall.
                End If
Now, we also need to check if the player gets smushed by a still wall and a moving wall. (Note, the player cannot get smushed by two unmoving walls.) This will have to be done in a wall movement block. This should not be done in the loop that is in the IsJumping block, because that will only smush the player while he is jumping. We'll need an extra loop before the IsJumping block that checks the walls only if the player has touched one of the moving walls. So, immediately after the MovingWalls loop, we'll have:
            If TouchingWall Then
                For Each Wall In Walls
                    If PlayerLoc.IntersectsWith(Wall) Then
                        'The player is smushed if he is touching another wall,
                        'because he has been pushed at the same time by a moving wall.
                        IsGoner = True
                        'The player has been smushed.  Lose a life.
                        PlayerVeloc = SBARINITIALVELOCITY
                    End If
                Next
            End If
And now, the player gets smushed.
Now, when the moving wall pushes the player, he doesn't fall off of an obstacle that he is on. We can fix that by taking the part of the walking code that causes the player to fall and placing that inside of the moving wall section that pushes the player. Find the new additions in the segment below:
            Dim R As Integer
            For R = 0 To MobileWalls.Count - 1
                MobileWall = DirectCast(MobileWalls(R), MovingWall)
                'We have to use DirectCast since arraylist contains structures and we are changing the property values.
                If R = MobileIndex Then  'R will never be -1 because of our For Loop.
                    'We need to move the Player, the left end, and the right end.
                    LeftEnd += MobileWall.dX
                    RightEnd += MobileWall.dX
                    PlayerLoc.Offset(MobileWall.dX, MobileWall.dY)
                End If

                If MobileWall.dX < 0 Then
                    'The wall is moving left.
                    MobileWall.MoveWall()
                    'This does all of the 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.MoveWall()
                    '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.MoveWall()
                    'This does all of the movement for the wall.
                End If
                MobileWalls(R) = MobileWall
            Next
Now, the walls can push the player off of an object.
We also need to get the player to move if he is standing on the moving wall and collides with a stationary wall. We don't need to do a check for standing on moving wall and colliding with a moving wall since that is handled by the previous code above. In the moving wall loop, we'll need to loop through all of the walls when the player is standing on a moving wall. We'll have to determine which direction the player is moving in order to determine which side of the wall to move the player onto. Everything is straightforward and mostly comprised of stuff we've done before, so there should be no surprises here. Well, only one. When the moving wall is moving right, the player has to move to the left side of the opposing wall and likewise for the wall moving left. This of course goes immediately after the movement of the player in the If R = MobileIndex if block inside the moving wall loop.
                    For Each Wall In Walls
                        If PlayerLoc.IntersectsWith(Wall) Then
                            'Collided with a wall while riding the moving wall.
                            If MobileWall.dX < 0 Then
                                'Move the player to the right side of this wall... can't collide with a wall if we're not moving.
                                PlayerLoc.Offset(Wall.Right - PlayerLoc.Left, 0)
                                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
                                'Move the player to the left side of this wall.
                                PlayerLoc.Offset(Wall.Left - PlayerLoc.Right, 0)
                                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
                            End If
                        End If
                    Next
Now, things should be all better.