private void UpdateFallingInHoles() { if (fallingInHole) { holeDoomTimer--; // After a delay, disable the player's motion. if (holeDoomTimer < 0) { player.Physics.Velocity = Vector2F.Zero; } if (!player.Physics.IsInHole) { // Stop falling in a hole. fallingInHole = false; doomedToFallInHole = false; holeTile = null; return; } else if (doomedToFallInHole) { // Collide with hole boundary's inside edges. Rectangle2F collisionBox = new Rectangle2F(-1, -1, 2, 2); player.Physics.PerformInsideEdgeCollisions(collisionBox, holeTile.Bounds); } else { // Check if the player has changed quadrents, // which dooms him to fall in the hole. Point2I holeTileLoc = player.RoomControl.GetTileLocation(player.Position); Tile newHoleTile = player.RoomControl.GetTopTile(holeTileLoc); Point2I newQuadrent = (Point2I)(player.Position / 8); if (newQuadrent != holeEnterQuadrent) { doomedToFallInHole = true; holeTile = newHoleTile; } } // Move toward the hole's center on each axis seperately. for (int i = 0; i < 2; i++) { float diff = holeTile.Center[i] - player.Center[i]; if (Math.Abs(diff) > 0.6f) { float dist = 0.25f; // Pull the player in more if he's moving away from the hole. if ((diff < 0.0f && player.Physics.Velocity[i] > 0.25f) || (diff > 0.0f && player.Physics.Velocity[i] < -0.25f)) { dist = 0.5f; } if (!(diff < 0.0f && player.Physics.Velocity[i] < -0.25f) && !(diff > 0.0f && player.Physics.Velocity[i] > 0.25f)) { holeSlipVelocity[i] = Math.Sign(diff) * dist; } } } player.Position += holeSlipVelocity; // Fall in the hole when too close to the center. if (player.Center.DistanceTo(holeTile.Center) <= 1.0f) { AudioSystem.PlaySound(GameData.SOUND_PLAYER_FALL); player.SetPositionByCenter(holeTile.Center); player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_FALL); player.RespawnDeath(); holeTile = null; fallingInHole = false; doomedToFallInHole = false; } } else if (player.Physics.IsInHole && player.CurrentState != player.RespawnDeathState) { // Start falling in a hole. Point2I holeTileLoc = player.RoomControl.GetTileLocation(player.Position); holeTile = player.Physics.TopTile; holeEnterQuadrent = (Point2I)(player.Position / 8); doomedToFallInHole = false; fallingInHole = true; holeDoomTimer = 10; } }