Esempio n. 1
0
        public bool UpdateWorld(float DT)
        {
            mPrevInput = mInput;
            mInput     = Keyboard.GetState();
            if (mInput.IsKeyDown(Keys.P) && mPrevInput.IsKeyUp(Keys.P) && !isPaused && !Player.IsDead() || mInput.IsKeyDown(Keys.Escape) && mPrevInput.IsKeyUp(Keys.Escape) && !isPaused && !Player.IsDead())
            {
                isPaused = true;
                aaDisplay.aaGame.IsMouseVisible = true;
                PausedPlaque = new UIElement_StaticMenuElement(aaDisplay, this, mKit_Paused.ASSET_NAME, 540, 320, (int)mKit_Paused.ORIGIN.X, (int)mKit_Paused.ORIGIN.Y, Constants.LAYER_UI_FRONT, mKit_Paused.SRC_RECTX, mKit_Paused.SRC_RECTY, mKit_Paused.SRC_RECTWIDTH, mKit_Paused.SRC_RECTHEIGHT, 0.0f);
                aaDisplay.AddMenuUIElement(PausedPlaque);
            }
            else if (mInput.IsKeyDown(Keys.P) && mPrevInput.IsKeyUp(Keys.P) && isPaused || mInput.IsKeyDown(Keys.Escape) && mPrevInput.IsKeyUp(Keys.Escape) && isPaused)
            {
                isPaused = false;
                aaDisplay.aaGame.IsMouseVisible = false;
                PausedPlaque.MenuDestroy();
                PausedPlaque = null;
            }

            if (!isPaused)
            {
                mAiDirector.Update(DT);

                if (mAiDirector.DoneSpawning() && mAiDirector.mTotalEnemies <= mEnemiesKilled)
                {
                    if (!waveResting)
                    {
                        waveResting = true;
                    }

                    if (waveResting)
                    {
                        waveRested += DT;
                    }

                    if (waveRested >= waveRestDuration)
                    {
                        waveIndicator.Show();
                        waveResting    = false;
                        waveRested     = 0.0f;
                        mEnemiesKilled = 0;
                        mCurrentWave++;
                        mAiDirector.StartWave(mCurrentWave);
                    }
                }

                foreach (Entity e in mToSpawnEntityList)
                {
                    mEntityList.Add(e);
                }
                mToSpawnEntityList.Clear();

                foreach (Entity e in mEntityList)
                {
                    e.Update(DT);
                }

                foreach (Projectile p in mProjectileList)
                {
                    p.Update(DT);
                }

                foreach (Projectile p in mProjDeadList)
                {
                    if (!mProjectileList.Remove(p))
                    {
                        if (mProjectileList.Contains(p))
                        {
                            // Console.WriteLine("But the projectile list contains p");
                        }
                    }
                    mRemovedProjectileList.Add(p);

                    if (p.mCollisionType == CollisionType.Point)
                    {
                        CollisionShapes_Points.Remove(p.mCollision as PointCollision);
                    }
                    else if (p.mCollisionType == CollisionType.Circle)
                    {
                        CollisionShapes_Circle.Remove(p.mCollision as CircleCollision);
                    }

                    p.mDispObject.Hide();

                    /*
                     * if (p.mDispObject != null)
                     * {
                     *  Console.WriteLine("Display object not null, removing it");
                     *  p.mDispObject.Destroy();
                     *  aaDisplay.mDisplayObjects.Remove(p.mDispObject);
                     *  p.mDispObject = null;
                     * }
                     * p.aaGameWorld.aaDisplay.mDisplayObjects.Remove(p.mDispObject);*/
                }
                mProjDeadList.Clear();

                foreach (Entity e in mEntityDeadList)
                {
                    if (e != null)
                    {
                        if (e is Ship)
                        {
                            Ship s = e as Ship;

                            if (!Player.IsDead())
                            {
                                mPoints += s.mKit.POINTS;
                            }
                            if (s.mTeam == Constants.ENEMY_TEAM)
                            {
                                mEnemiesKilled++;
                                if (s.mType == "Grunt_Boss" || s.mType == "Tank_Boss" || s.mType == "Bomb_Boss")
                                {
                                    if (Player.FireBullet as Ability_FireBullet != null)
                                    {
                                        AssetKit_Tier2Pickup mAssetKit = new AssetKit_Tier2Pickup();
                                        mPickups.Add(new DualShotPickup(aaDisplay, this, mAssetKit.ASSET_NAME, new Vector2(s.mXPos, s.mYPos), mAssetKit.ORIGIN, Constants.LAYER_ENTITY_DEPTH, new Rectangle(mAssetKit.SRC_RECTX, mAssetKit.SRC_RECTY, mAssetKit.SRC_RECTWIDTH, mAssetKit.SRC_RECTHEIGHT), 0));
                                    }
                                    else if (Player.FireBullet as Ability_ShootTier2 != null)
                                    {
                                        AssetKit_Tier3Pickup mAssetKit = new AssetKit_Tier3Pickup();
                                        mPickups.Add(new TriShotPickup(aaDisplay, this, mAssetKit.ASSET_NAME, new Vector2(s.mXPos, s.mYPos), mAssetKit.ORIGIN, Constants.LAYER_ENTITY_DEPTH, new Rectangle(mAssetKit.SRC_RECTX, mAssetKit.SRC_RECTY, mAssetKit.SRC_RECTWIDTH, mAssetKit.SRC_RECTHEIGHT), 0));
                                    }
                                    else if (Player.FireBullet as Ability_ShootTier3 != null)
                                    {
                                        AssetKit_Tier4Pickup mAssetKit = new AssetKit_Tier4Pickup();
                                        mPickups.Add(new QuadShotPickup(aaDisplay, this, mAssetKit.ASSET_NAME, new Vector2(s.mXPos, s.mYPos), mAssetKit.ORIGIN, Constants.LAYER_ENTITY_DEPTH, new Rectangle(mAssetKit.SRC_RECTX, mAssetKit.SRC_RECTY, mAssetKit.SRC_RECTWIDTH, mAssetKit.SRC_RECTHEIGHT), 0));
                                    }
                                }
                                else
                                {
                                    if (mRand.NextDouble() <= 0.02)
                                    {
                                        AssetKit_HealthPickup mAssetKit = new AssetKit_HealthPickup();
                                        mPickups.Add(new HealthPickup(aaDisplay, this, mAssetKit.ASSET_NAME, new Vector2(s.mXPos, s.mYPos), mAssetKit.ORIGIN, Constants.LAYER_ENTITY_DEPTH, new Rectangle(mAssetKit.SRC_RECTX, mAssetKit.SRC_RECTY, mAssetKit.SRC_RECTWIDTH, mAssetKit.SRC_RECTHEIGHT), 0));
                                    }
                                }
                            }
                            s.Destroy();
                        }

                        aaDisplay.mDisplayObjects.Remove(e.mDispObj);
                        mEntityList.Remove(e);
                    }
                }
                mEntityDeadList.Clear();

                ResolveWorldCollisions();

                aaGFXHandler.Update(DT);

                aaDisplay.aaCamera.ChangeFocus(Player.mXPos, Player.mYPos);
                aaDisplay.aaCamera.Update(DT);

                foreach (UIElement e in aaDisplay.mUIElements)
                {
                    e.Update(DT);
                }
                foreach (UIElement e in aaDisplay.mMenuUIElements)
                {
                    e.Update(DT);
                }


                if (Player.IsDead())
                {
                    aaDisplay.aaGame.IsMouseVisible = true;

                    if (ScoreTextBox == null)
                    {
                        ScoreTextBox = new UIElement_ScoreTextBox(aaDisplay, this, 340, 315);
                    }
                    if (UnlockText == null)
                    {
                        UnlockText = new UIElement_Text(aaDisplay, this, aaDisplay.aaGame.mTextboxFont, 480, 230, Color.White, "");
                        aaDisplay.AddMenuUIElement(UnlockText);
                    }
                    if (FinalScoreText == null)
                    {
                        FinalScoreText = new UIElement_Text(aaDisplay, this, aaDisplay.aaGame.mTextboxFont, 640 - (int)(aaDisplay.aaGame.mTextboxFont.MeasureString(mPoints.ToString()).X / 2), 260, Color.White, mPoints.ToString());
                        aaDisplay.AddMenuUIElement(FinalScoreText);
                    }
                    aaDisplay.AddMenuUIElement(GameOverPlaque);
                    ScoreTextBox.Show();
                    FinalScoreText.Show();
                    ScoreTextBox.Update(DT);

                    if (((UIElement_ScoreTextBox)ScoreTextBox).AcceptClicked() || Keyboard.GetState().IsKeyDown(Keys.Enter))
                    {
                        aaDisplay.aaGame.aaHSManager.AddScore(((UIElement_ScoreTextBox)ScoreTextBox).GetText(), mPoints, mCurrentWave);
                        aaDisplay.aaGame.aaHSManager.SaveScores();
                        GameOverPlaque.MenuDestroy();
                        GameOverPlaque = null;
                        FinalScoreText.MenuDestroy();
                        FinalScoreText = null;
                        ScoreTextBox.Destroy();
                        ScoreTextBox = null;
                        aaDisplay.aaGame.mManager.ChangeState(aaDisplay.aaGame.mHighScoreMenu);
                    }
                    else if (((UIElement_ScoreTextBox)ScoreTextBox).CancelClicked() || Keyboard.GetState().IsKeyDown(Keys.Escape))
                    {
                        aaDisplay.aaGame.mManager.ChangeState(aaDisplay.aaGame.mHighScoreMenu);
                        GameOverPlaque.MenuDestroy();
                        GameOverPlaque = null;
                        FinalScoreText.MenuDestroy();
                        FinalScoreText = null;
                        ScoreTextBox.Destroy();
                        ScoreTextBox = null;
                    }

                    //Manage unlocked ships and abilities
                    if ((aaDisplay.aaGame.mShipMenu as State_Menu_Ship).shipCount == 0)
                    {
                        if (mCurrentWave >= 10 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[0] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[0] = 2736;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 20 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[1] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[1] = 1967;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 30 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[2] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[2] = 8913;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                    }
                    else if ((aaDisplay.aaGame.mShipMenu as State_Menu_Ship).shipCount == 1)
                    {
                        if (mCurrentWave >= 10 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[3] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[3] = 8432;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 20 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[4] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[4] = 6874;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 30 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[5] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[5] = 8794;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                    }
                    else if ((aaDisplay.aaGame.mShipMenu as State_Menu_Ship).shipCount == 2)
                    {
                        if (mCurrentWave >= 10 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[6] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[6] = 3252;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 20 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[7] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[7] = 3248;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                        if (mCurrentWave >= 30 && (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[8] == 0)
                        {
                            (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).Abilitydata.mUnlocks[8] = 8942;
                            UnlockText.mText = "NEW ABILITY UNLOCKED";
                        }
                    }
                    (aaDisplay.aaGame.mShipMenu as State_Menu_Ship).SaveData();
                }

                foreach (SoundEffectInstance sfx in aaDisplay.aaGame.mGameSoundFX)
                {
                    if (sfx.State == SoundState.Stopped)
                    {
                        sfx.Dispose();
                        aaDisplay.aaGame.mGameSoundFXRemove.Add(sfx);
                    }
                }

                foreach (SoundEffectInstance sfx in aaDisplay.aaGame.mGameSoundFXRemove)
                {
                    aaDisplay.aaGame.mGameSoundFX.Remove(sfx);
                }
                aaDisplay.aaGame.mGameSoundFXRemove.Clear();
            }

            return(true);
        }