/// <summary> /// Upon collision with a Tile, perform the appropriate action depending on the State of the Guy and what kind of Tile is being collided with. /// </summary> /// <remarks>Only if there is an actual collision will any of these statements execute.</remarks> /// <param name="currentState">The current State of the Guy.</param> /// <param name="y">The Y coordinate of the Tile in the level being collided with.</param> /// <param name="x">The X coordinate of the Tile in the level being collided with.</param> protected override void specializedCollision(State currentState, int y, int x) { if (!delayBetweenLaunchesTimer.TimerStarted) // Ensures the Guy doesn't use another Launcher too quickly. { if (currentState == State.Running_Right) { // Allow the Guy to pass through an Air Switch Cannon. if (!Level.tiles[y, x].IsAirCannonSwitch) { position.X = Level.tiles[y, x].Position.X - spriteWidth; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collY = y; collX = x; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.X = 0f; delayCollisionWithShoesAndGuy = false; } } else if (currentState == State.Running_Left) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.X = Level.tiles[y, x].Position.X + Level.tiles[y, x].Texture.Width + 1; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.X = 0f; delayCollisionWithShoesAndGuy = false; } } else if (currentState == State.Jumping) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.Y = Level.tiles[y, x].Position.Y + Level.tiles[y, x].Texture.Height + 2; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.Y = 0f; } } else if (currentState == State.Decending) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.Y = Level.tiles[y, x].Position.Y - spriteHeight; } if (Level.tiles[y, x].TileRepresentation == 'S' && velocity.Y > 1f) { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); position = new Vector2(Level.tiles[y, x].Position.X - 16, Level.tiles[y, x].Position.Y - 32); velocity = new Vector2(0f, 0f); if (!idleAnimationLockIsOn) { changeSpriteOfTheGuy("Idle_WithoutShoes_Right"); idleAnimationLockIsOn = true; } } else { velocity = new Vector2(0f, 0f); // So the Guy doesn't fall through. useGravity = false; changeSpriteOfTheGuy("Idle_WithoutShoes_Right"); SoundEffectHandler.playGuyLandingSoundEffect(); } } } }