/// <summary> /// Change the current map, arriving at the given portal if any. /// </summary> /// <param name="contentName">The asset name of the new map.</param> /// <param name="originalPortal">The portal from the previous map.</param> public static void ChangeMap(string contentName, Portal originalPortal) { // make sure the content name is valid string mapContentName = contentName; if (!mapContentName.StartsWith(@"Maps\")) { mapContentName = Path.Combine(@"Maps", mapContentName); } // check for trivial movement - typically intra-map portals if ((Map != null) && (Map.Name == mapContentName)) { SetMap(Map, originalPortal == null ? null : Map.GetPortal(originalPortal.DestinationMap)); } // load the map changeMap = MapContentManager.Load<Map>(mapContentName); // modify the map based on the world changes (removed chests, etc.). //ModifyMap(map); // start playing the music for the new map //AudioManager.PlayMusic(map.MusicCueName); // set the new map into the tile engine SetMap(changeMap, originalPortal == null ? null : changeMap.GetPortal(originalPortal.DestinationPortal)); }
private static void HandlePortal(Portal portalEntry) { fadeOut = true; fadeIn = false; // change to the new map ChangeMap(portalEntry.DestinationMap, portalEntry); Portal landingPortal = changeMap.GetPortal(portalEntry.DestinationPortal); changePos = new Vector2(landingPortal.Position.X * Map.TILE_WIDTH, landingPortal.Position.Y * Map.TILE_HEIGHT); }
/// <summary> /// Set the map in use by the tile engine. /// </summary> /// <param name="map">The new map for the tile engine.</param> /// <param name="portal">The portal the party is entering on, if any.</param> public static void SetMap(Map newMap, Portal portalEntry) { // check the parameter if (newMap == null) { throw new ArgumentNullException("newMap"); } // assign the new map changeMap = newMap; // move the party to its initial position if (portalEntry == null) { // no portal - use the spawn position Player.Position = new Vector2(changeMap.SpawnMapPosition.X * Map.TILE_WIDTH, changeMap.SpawnMapPosition.Y * Map.TILE_HEIGHT); } else { // use the portal provided, which may include automatic movement changePos = new Vector2(portalEntry.Position.X * Map.TILE_WIDTH, portalEntry.Position.Y * Map.TILE_HEIGHT); Player.SetAutoMovement(new Vector2(portalEntry.AutoMotion.X * Map.TILE_WIDTH, portalEntry.AutoMotion.Y * Map.TILE_HEIGHT)); motion = Vector2.Zero; } }