/// <summary> /// Loads a new level asynchronously /// </summary> /// <param name="level">The name of the level to load</param> public void LoadLevel(string level) { Loading = true; ThreadStart threadStarter = delegate { CurrentMap = game.Content.Load<Tilemap>("Tilemaps/" + level); CurrentMap.LoadContent(game.Content); // Load the background music if (CurrentMap.MusicTitle != null && CurrentMap.MusicTitle != "") { CurrentSong = game.Content.Load<Song>("Music/" + CurrentMap.MusicTitle); } else { CurrentSong = null; } // Set the *default* starting scroll position to 16 tiles // above the bottom of the map scrollDistance = (-2 * CurrentMap.Height * CurrentMap.TileHeight) + (2 * 16 * CurrentMap.TileHeight); // Load the game objects for (int i = 0; i < CurrentMap.GameObjectGroupCount; i++) { for (int j = 0; j < CurrentMap.GameObjectGroups[i].GameObjectData.Count(); j++) { GameObjectData goData = CurrentMap.GameObjectGroups[i].GameObjectData[j]; Vector2 position = new Vector2(goData.Position.Center.X, goData.Position.Center.Y); GameObject go; switch (goData.Category) { case "PlayerStart": ScrollingShooterGame.Game.Player.Position = position; scrollDistance = -2 * position.Y + 300; break; case "LevelEnd": break; case "Powerup": go = ScrollingShooterGame.GameObjectManager.CreatePowerup((PowerupType)Enum.Parse(typeof(PowerupType), goData.Type), position); CurrentMap.GameObjectGroups[i].GameObjectData[j].ID = go.ID; go.LayerDepth = CurrentMap.GameObjectGroups[i].LayerDepth; go.ScrollingSpeed = CurrentMap.GameObjectGroups[i].ScrollingSpeed; break; case "Enemy": go = ScrollingShooterGame.GameObjectManager.CreateEnemy((EnemyType)Enum.Parse(typeof(EnemyType), goData.Type), position); CurrentMap.GameObjectGroups[i].GameObjectData[j].ID = go.ID; go.LayerDepth = CurrentMap.GameObjectGroups[i].LayerDepth; go.ScrollingSpeed = CurrentMap.GameObjectGroups[i].ScrollingSpeed; break; case "Boss": go = ScrollingShooterGame.GameObjectManager.CreateBoss((BossType)Enum.Parse(typeof(BossType), goData.Type), position); CurrentMap.GameObjectGroups[i].GameObjectData[j].ID = go.ID; go.LayerDepth = CurrentMap.GameObjectGroups[i].LayerDepth; go.ScrollingSpeed = CurrentMap.GameObjectGroups[i].ScrollingSpeed; break; } } } // Mark level as loaded Loading = false; }; Thread loadingThread = new Thread(threadStarter); loadingThread.Start(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); GameObjectManager = new GameObjectManager(Content); // TODO: use this.Content to load your game content here player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300)); GameObjectManager.CreatePowerup(PowerupType.Fireball, new Vector2(100, 200)); //player.ApplyPowerup(PowerupType.Fireball); tilemap = Content.Load<Tilemap>("Tilemaps/example"); for (int i = 0; i < tilemap.GameObjectGroupCount; i++) { for (int j = 0; j < tilemap.GameObjectGroups[i].GameObjectData.Count(); j++ ) { GameObjectData goData = tilemap.GameObjectGroups[i].GameObjectData[j]; Vector2 position = new Vector2(goData.Position.Center.X, goData.Position.Center.Y); GameObject go; switch (goData.Category) { case "Powerup": go = GameObjectManager.CreatePowerup((PowerupType)Enum.Parse(typeof(PowerupType), goData.Type), position); goData.ID = go.ID; break; case "Enemy": go = GameObjectManager.CreateEnemy((EnemyType)Enum.Parse(typeof(EnemyType), goData.Type), position); goData.ID = go.ID; break; } } } tilemap.Scrolling = true; GameObjectManager.CreateEnemy(EnemyType.Cobalt, new Vector2(200, 200)); }
public void UnloadLevel() { CurrentMap = null; CurrentSong = null; scrollDistance = 0; }
/// <summary> /// Loads a new level /// </summary> /// <param name="level">The name of the level to load</param> public void LoadLevel(string level) { CurrentMap = game.Content.Load<Tilemap>("Tilemaps/" + level); // Set the *default* starting scroll position to 16 tiles // above the bottom of the map scrollDistance = (-2 * CurrentMap.Height * CurrentMap.TileHeight) + (2 * 16 * CurrentMap.TileHeight); // Load the game objects for (int i = 0; i < CurrentMap.GameObjectGroupCount; i++) { for (int j = 0; j < CurrentMap.GameObjectGroups[i].GameObjectData.Count(); j++) { GameObjectData goData = CurrentMap.GameObjectGroups[i].GameObjectData[j]; Vector2 position = new Vector2(goData.Position.Center.X, goData.Position.Center.Y); GameObject go; switch (goData.Category) { case "PlayerStart": ScrollingShooterGame.Game.Player.Position = position; scrollDistance = -2 * position.Y + 300; break; case "Powerup": go = ScrollingShooterGame.GameObjectManager.CreatePowerup((PowerupType)Enum.Parse(typeof(PowerupType), goData.Type), position); CurrentMap.GameObjectGroups[i].GameObjectData[j].ID = go.ID; go.LayerDepth = CurrentMap.GameObjectGroups[i].LayerDepth; go.ScrollingSpeed = CurrentMap.GameObjectGroups[i].ScrollingSpeed; break; case "Enemy": go = ScrollingShooterGame.GameObjectManager.CreateEnemy((EnemyType)Enum.Parse(typeof(EnemyType), goData.Type), position); CurrentMap.GameObjectGroups[i].GameObjectData[j].ID = go.ID; go.LayerDepth = CurrentMap.GameObjectGroups[i].LayerDepth; go.ScrollingSpeed = CurrentMap.GameObjectGroups[i].ScrollingSpeed; break; } } } // Turn on scrolling CurrentMap.Scrolling = true; }