Inheritance: BaseEnemyShip
Example #1
0
        public void InitializeScreen(ShipStats ship, bool spawnEnemies)
        {
            //Reset any active ships, since we're re-initializing the game screen
            StateManager.EnemyShips.Clear();
            StateManager.AllyShips.Clear();
            playerMinimapVisible = null;
            _minimapYou = null;

            //Reset music
            _gameHasStarted = false;
            //_allowMusicHandling = false;
            playerSbObjects.Clear();
            Sprites.Clear();
            enemies.Clear();

            wcMovePrettyCode = new EventHandler(wcMovePreUpdate);

            SpriteFont SegoeUIMono = GameContent.Assets.Fonts.NormalText;

            secondaryWeaponLabel = new TextSprite(playerSb, SegoeUIMono, "No Secondary Weapon");
            secondaryWeaponLabel.Position = new Vector2((Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * .1f - secondaryWeaponLabel.Width / 2) + 30, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .1f - secondaryWeaponLabel.Height / 2);
            secondaryWeaponLabel.Color = Color.White;
            playerSbObjects.Add(secondaryWeaponLabel);

            //Initialize the game map (world)
            bgspr = new BackgroundSprite(bgImg, Sprites.SpriteBatch, 10, 2);
            bgspr.Drawn += new EventHandler(bgspr_Drawn);
            worldCam.Pos = new Vector2(bgspr.TotalWidth / 2, bgspr.TotalHeight - (bgspr.Height / 2));
            BackgroundSprite = bgspr;

            //Set the world size in StateManager for later access
            StateManager.WorldSize = new Rectangle(0, 0, (int)bgspr.TotalWidth, (int)bgspr.TotalHeight);

            StateManager.SpawnArea = new Rectangle(500, 500, bgspr.TotalWidth.Round() - 1000, bgspr.TotalHeight.Round() - 1000);

            Vector2 minSpawnArea = _playableAreaOffset;
            Vector2 maxSpawnArea = new Vector2(bgspr.TotalWidth, bgspr.TotalHeight) - _playableAreaOffset;

            _enemies = spawnEnemies;

            #region Enemy Spawns
            if (spawnEnemies)
            {

                if (StateManager.CurrentLevel.ToInt() == 4)
                {
                    foreach (SignedInGamer sig in Gamer.SignedInGamers)
                    {
                        sig.Presence.PresenceMode = GamerPresenceMode.BattlingBoss;
                    }
                    CloneBoss enemyBoss = new CloneBoss(GameContent.Assets.Images.Ships[ShipType.EnemyFighterCarrier, ShipTier.Tier4], Vector2.Zero, Sprites.SpriteBatch);
                    CloneBoss enemyCloneOne = new CloneBoss(GameContent.Assets.Images.Ships[ShipType.EnemyFighterCarrier, ShipTier.Tier4], Vector2.Zero, Sprites.SpriteBatch);
                    CloneBoss enemyCloneTwo = new CloneBoss(GameContent.Assets.Images.Ships[ShipType.EnemyFighterCarrier, ShipTier.Tier4], Vector2.Zero, Sprites.SpriteBatch);

                    enemyBoss.WorldCoords = StateManager.RandomGenerator.NextVector2(minSpawnArea, maxSpawnArea);
                    enemyCloneOne.WorldCoords = enemyBoss.WorldCoords;
                    enemyCloneTwo.WorldCoords = enemyBoss.WorldCoords;

                    enemyBoss.isClone = false;

                    enemyBoss.targetPosition = StateManager.RandomGenerator.NextVector2(new Vector2(500), new Vector2(StateManager.WorldSize.Width - 500, StateManager.WorldSize.Height - 500));
                    enemyCloneOne.targetPosition = StateManager.RandomGenerator.NextVector2(new Vector2(500), new Vector2(StateManager.WorldSize.Width - 500, StateManager.WorldSize.Height - 500));
                    enemyCloneTwo.targetPosition = StateManager.RandomGenerator.NextVector2(new Vector2(500), new Vector2(StateManager.WorldSize.Width - 500, StateManager.WorldSize.Height - 500));

                    enemyCloneOne.EnemyCounts = false;
                    enemyCloneTwo.EnemyCounts = false;

                    Sprites.Add(enemyBoss);
                    enemies.Add(enemyBoss);

                    if (StateManager.Options.SFXEnabled)
                    {
                        ClonesMade.Play();
                    }

                    Sprites.Add(enemyCloneOne);
                    enemies.Add(enemyCloneOne);

                    if (StateManager.Options.SFXEnabled)
                    {
                        ClonesMade.Play();
                    }

                    Sprites.Add(enemyCloneTwo);
                    enemies.Add(enemyCloneTwo);
                }
                else
                {
                    foreach (SignedInGamer sig in Gamer.SignedInGamers)
                    {
                        sig.Presence.PresenceMode = GamerPresenceMode.InCombat;
                    }
                    for (int i = 0; i < 4 * StateManager.CurrentLevel.ToInt(); i++)
                    {
                        Texture2D enemyTexture = GameContent.Assets.Images.Ships[ShipType.Drone, StateManager.RandomGenerator.NextShipTier(ShipTier.Tier1, ShipTier.Tier2)];
                        EnemyBattleCruiser enemy = new EnemyBattleCruiser(GameContent.Assets.Images.Ships[ShipType.EnemyBattleCruiser, ShipTier.Tier1], Vector2.Zero, Sprites.SpriteBatch);

                        enemy.WorldCoords = StateManager.RandomGenerator.NextVector2(minSpawnArea, maxSpawnArea);

                        enemy.DistanceToNose = .5f;

                        enemy.Tier = ShipTier.Tier1;

                        Sprites.Add(enemy);
                        enemies.Add(enemy);
                    }
                }
            }
            #endregion

            TextureFactory creator = new TextureFactory(Graphics);

            miniMap = new Sprite(creator.CreateSquare(1, new Color(Color.Navy.R, Color.Navy.G, Color.Navy.B, 128)), Vector2.Zero, playerSb);
            miniMap.Width = bgspr.TotalWidth / MinimapDivAmount;
            miniMap.Color = Color.White;
            miniMap.Height = bgspr.TotalHeight / MinimapDivAmount;
            miniMap.Y = Graphics.Viewport.TitleSafeArea.Y + 7.5f;
            miniMap.X = Graphics.Viewport.TitleSafeArea.X + Graphics.Viewport.TitleSafeArea.Width - miniMap.Width - 7.5f;
            miniMap.Updated += new EventHandler(miniMap_Updated);
            miniShipInfoBg = new Sprite(creator.CreateSquare(1, new Color(0, 0, 0, 192)), new Vector2(7.5f, miniMap.Y), playerSb);
            miniShipInfoBg.Height = 0.01f;
            miniShipInfoBg.Width = 767.5f - miniShipInfoBg.X - 7.5f - miniMap.Width - 266.6666667f;
            miniShipInfoBg.X = miniMap.X - miniShipInfoBg.Width - 7.5f;
            miniShipInfoBg.Color = Color.Transparent;
            playerSbObjects.Add(miniShipInfoBg);
            playerSbObjects.Add(miniMap);

            if (StateManager.DebugData.FogOfWarEnabled)
            {
                //Create fog of war array
                // > 9x15 = Xbox lag
                // TODO: RenderTarget conversion
                fogOfWar = new Sprite[9, 15];
            }

            if (ship.Type == ShipType.Drone)
            {
                throw new Exception("Can't create a Drone as the main ship");
            }

            playerShip = BaseAllyShip.CreateShip(ship, playerSb);

            playerShip.WorldSb = Sprites.SpriteBatch;
            playerShip.Position = playerShip.GetCenterPosition(Sprites.SpriteBatch.GraphicsDevice.Viewport, playerShip.Origin * playerShip.Scale);
            playerShip.WCMoved += new EventHandler(playerShip_WCMoved);
            playerShip.WCMoved += wcMovePrettyCode;
            playerShip.IsPlayerShip = true;
            playerShip.RotateTowardsMouse = true;
            playerSbObjects.Add(playerShip);

            //TODO: Tier change event handles this
            //playerShip.InitialHealth = 100;

            //Set as own ship
            playerShip.PlayerType = PlayerType.MyShip;
            playerShip.WorldCoords = worldCam.Pos;

            if (fogOfWar != null)
            {
                for (int row = 0; row <= fogOfWar.GetUpperBound(1); row++)
                {
                    for (int column = 0; column <= fogOfWar.GetUpperBound(0); column++)
                    {
                        fogOfWar[column, row] = new Sprite(creator.CreateSquare(1, Color.DarkGray), Vector2.Zero, playerSb);
                        fogOfWar[column, row].Width = miniMap.Width / fogOfWar.GetLength(0);
                        fogOfWar[column, row].Height = miniMap.Height / fogOfWar.GetLength(1);
                        fogOfWar[column, row].X = miniMap.X + fogOfWar[0, 0].Width * column;
                        fogOfWar[column, row].Y = miniMap.Y + fogOfWar[0, 0].Height * row;
                        fogOfWar[column, row].Color = Color.White;
                        StateManager.KnownMap[column, row] = false;
                    }
                }
            }

            World = Sprites.SpriteBatch;
            playerShip.BulletFired += new EventHandler<BulletEventArgs>(playerShip_BulletFired);

            _bulletsInProgress.Clear();
        }
        public static BaseEnemyShip CreateRandomEnemy(SpriteBatch spawn)
        {
            ////ShipType[] possibleSpawnTypes = new ShipType[] { ShipType.EnemyBattleCruiser, ShipType.EnemyFighterCarrier, ShipType.EnemyTorpedoShip };
            ShipTier spawnTier = StateManager.RandomGenerator.NextShipTier(ShipTier.Tier1, ShipTier.Tier2);
            ////ShipType spawned = possibleSpawnTypes[StateManager.RandomGenerator.Next(possibleSpawnTypes.Length)];

            //TODO: IMPLEMENT MORE ENEMY SHIPS!!!!!!!!!!!!!!!!!
            ShipType spawned = ShipType.EnemyBattleCruiser;
            BaseEnemyShip enemy = null;

            switch (spawned)
            {
                case ShipType.EnemyBattleCruiser:
                    enemy = new EnemyBattleCruiser(GameContent.Assets.Images.Ships[spawned, spawnTier], Vector2.Zero, spawn);
                    break;
            }

            enemy.WorldCoords = StateManager.RandomGenerator.NextVector2((LocationUtility)StateManager.SpawnArea.Location, new Vector2(StateManager.SpawnArea.X, StateManager.SpawnArea.Y)+new Vector2(StateManager.SpawnArea.Width, StateManager.SpawnArea.Height));

            enemy.DistanceToNose = .5f;

            enemy.Tier = spawnTier;

            //Sprites.Add(enemy);
            //enemies.Add(enemy);

            return enemy;
        }