/// <summary> /// Performs door-based operations to move Samus into the adjacent zone. /// </summary> /// <param name="samus"></param> public void handleZoneTransition(PlayerController samus) { Point globalCoord = m_owningZone.getGlobalScreenFromLocalScreen(m_zoneScreenCoord); // Find target door (door in target zone which aligns with this door) Zone targetZone = WorldManager.GetZone(DirectionUtils.Move(globalCoord, Side)); Point targetScreenInZoneCoord = targetZone.getLocalScreenFromGlobalScreen(globalCoord); Rectangle targetScreenArea = targetZone.getScreenRectangle(targetScreenInZoneCoord); List<Collider> colliders = targetZone.CollisionDetector.query(new DoubleRect(ref targetScreenArea)); Collider targetDoorCollider = colliders.Find(i => {return (i.m_owner is DoorController && ((DoorController)i.m_owner).Side == this.Side.Opposite); }); DoorController targetDoor = (DoorController)targetDoorCollider.m_owner; // Trigger closing animation on target door targetDoor.close(); // Calculate Samus' new position in target zone DoubleRect samusBounds = samus.getCollider().Bounds; Vector2 dropPos = new Vector2(); switch (Side.Opposite.EnumValue) { case DirectionEnum.Left: dropPos.X = (float)(targetDoorCollider.Bounds.X + targetDoorCollider.Bounds.Width + 1 + samusBounds.Width / 2); dropPos.Y = (float)(targetDoorCollider.Bounds.Y + targetDoorCollider.Bounds.Height - 1); break; case DirectionEnum.Right: dropPos.X = (float)(targetDoorCollider.Bounds.X - 1 - samusBounds.Width / 2); dropPos.Y = (float)(targetDoorCollider.Bounds.Y + targetDoorCollider.Bounds.Height - 1); break; case DirectionEnum.Up: dropPos.X = (float)(targetDoorCollider.Bounds.X + targetDoorCollider.Bounds.Width / 2); dropPos.Y = (float)(targetDoorCollider.Bounds.Y + targetDoorCollider.Bounds.Height + 1 + samusBounds.Height); break; case DirectionEnum.Down: dropPos.X = (float)(targetDoorCollider.Bounds.X + targetDoorCollider.Bounds.Width / 2); dropPos.Y = (float)(targetDoorCollider.Bounds.Y - 1 - samusBounds.Height); break; } // And create a new zone transition state with this information EngineManager.pushState(new EngineStateZoneTransition( EngineManager.Engine, this, targetDoor, targetZone, dropPos)); setCollisionModeClosed(); }