Example #1
0
        public void Draw(SpriteBatch spriteBatch, Container.GameState GameState)
        {
            switch (GameState)
            {
                #region GameState = MainMenu
            case Container.GameState.MainMenu:
                spriteBatch.Draw(mainMenuTexture, new Rectangle(0, 0, Container.scrWidth, Container.scrHeight), Color.White);
                playButton.Draw(spriteBatch);
                introButton.Draw(spriteBatch);
                creditButton.Draw(spriteBatch);
                break;
                #endregion

                #region    GameState = Intro
            case Container.GameState.Intro:
                spriteBatch.Draw(mainMenuTexture, new Rectangle(0, 0, Container.scrWidth, Container.scrHeight), Color.White);
                spriteBatch.Draw(huongDanTexture, new Rectangle(200, 50, 800, 600), Color.White);
                backButton.Draw(spriteBatch);
                break;
                #endregion

                #region GameState = TacGia
            case Container.GameState.Tacgia:
                spriteBatch.Draw(mainMenuTexture, new Rectangle(0, 0, Container.scrWidth, Container.scrHeight), Color.White);
                spriteBatch.Draw(tacGiaTexture, new Rectangle(0, 0, tacGiaTexture.Width, tacGiaTexture.Height), Color.White);
                backButton.Draw(spriteBatch);
                break;
                #endregion

                #region GameState = Pausing || Playing || Win  || GameOver
            case Container.GameState.Pausing:
            case Container.GameState.Playing:
            case Container.GameState.Win:
            case Container.GameState.GameOver:
                //Vẽ menu field
                spriteBatch.Draw(menuField, Container.playMenuPosition, Color.White * 0.1f);
                spriteBatch.Draw(infoBlock, Container.infoBlock, Color.White * 0.3f);
                spriteBatch.Draw(towerBlock, Container.towerBlock, Color.White * 0.3f);
                spriteBatch.Draw(skillBlock, Container.skillBlock, Color.White * 0.3f);
                // Cac ban ve trong playing thi Update o day
                //<Start>
                //Vẽ các towerButton
                foreach (towerButton item in towerButtonList)
                {
                    item.Draw(spriteBatch);
                }
                if (!isSoundOn)
                {
                    onMusicButton.Draw(spriteBatch);
                }
                else
                {
                    offMusicButton.Draw(spriteBatch);
                }
                if (!isPauseSet)
                {
                    pauseButton.Draw(spriteBatch);
                }
                else
                {
                    resumeButton.Draw(spriteBatch);
                }
                replayButton.Draw(spriteBatch);
                nextWave.Draw(spriteBatch);
                specialSkill1Button.Draw(spriteBatch);
                specialSkill2Button.Draw(spriteBatch);
                specialSkill3Button.Draw(spriteBatch);
                //<End>
                break;
                #endregion
            }
        }
Example #2
0
        protected override void Update(GameTime gameTime)
        {
            //Tu update MainMenu
            //<Start>
            mouse = Mouse.GetState();
            btM.Update(CurrentState, mouse, goldHave, gameTime);
            CurrentState = btM.GameState;
            // check Exit
            if (CurrentState == Container.GameState.Exit)
            {
                Exit();
            }

            if (CurrentState == Container.GameState.MainMenu)
            {
                //Load nhạc nền menu
                if (temp > 0)
                {
                    MediaPlayer.Play(sm.mainMenu);
                    MediaPlayer.Volume = 0.5f;
                    temp--;
                }
            }

            if (CurrentState == Container.GameState.Playing)
            {
                buttonReturn();
                //Tắt nhạc nền menu, bật nhạc nền epic
                if (temp == 0)
                {
                    MediaPlayer.Play(sm.bgMusic);
                    MediaPlayer.Volume = 0.5f;
                    temp--;
                }
                #region     Thông tin về đợt tấn công
                if (enemyPerWave > 0)           //Nếu chưa hết một lượt tấn công
                {
                    timer += 3;
                    if (timer > Container.timeBetweenEnemy)
                    {
                        if (wave <= Container.waveQuantity)
                        {
                            int sttEnemy = 0;
                            while (true)
                            {
                                if (Container.enemyEachWave[wave - 1][sttEnemy] > 0)
                                {
                                    enemyList.Add(new Enemy(enemyTextureList[sttEnemy], healthbar, sttEnemy + 1));
                                    Container.enemyEachWave[wave - 1][sttEnemy]--;
                                    timer = 0;
                                    break;
                                }
                                else
                                {
                                    sttEnemy++;
                                }
                            }
                            enemyPerWave--;
                            if (enemyPerWave == 0)
                            {
                                timer = 0;
                            }
                        }
                    }
                }
                #endregion

                #region  Hết một lượt tấn công, chuyển sang lượt tấn công khác
                else
                {
                    nextWaveTimer -= 5;
                    if (nextWaveTimer < 0)
                    {
                        wave++;
                        enemyPerWave  = Container.enemyPerWave;
                        nextWaveTimer = Container.timeBetweenWave;
                    }
                }
                #endregion

                #region Tạo enemy
                foreach (Enemy enemy in enemyList)
                {
                    if (enemy.isWayPointsSet == false)      //Nếu chưa setwaypoint thì bắt đầu set
                    {
                        Random rand = new Random();
                        int    k    = rand.Next(0, 20);
                        level.LoadWayPoint(k, enemy.isNavy);
                        enemy.SetWaypoints(level.WayPoints);
                        enemy.isWayPointsSet = true;
                    }
                }
                #endregion

                #region Update enemyList
                for (int i = 0; i < enemyList.Count; i++)
                {
                    if (enemyList[i].IsAlive)
                    {
                        enemyList[i].Update(gameTime);
                    }
                    else
                    {
                        //sm.explodeSound.Play();
                        enemyList.RemoveAt(i);
                        i--;
                    }
                }
                if (enemyList.Count <= 0)          //Kiểm tra thua
                {
                    if (wave == Container.waveQuantity && enemyPerWave == 0)
                    {
                        wave++;
                    }
                }
                #endregion

                #region Update hiệu ứng explosion
                for (int i = 0; i < explosionAnimation.Count; i++)
                {
                    if (explosionAnimation[i].IsVisible)
                    {
                        explosionAnimation[i].Update(gameTime);
                    }
                    else
                    {
                        explosionAnimation.RemoveAt(i);
                        i--;
                    }
                }
                #endregion

                player.Update(gameTime, enemyList, btM.RetButton);

                base.Update(gameTime);
            }

            if (CurrentState == Container.GameState.Win)          //Trạng thái thua
            {
                #region Update hiệu ứng explosion
                for (int i = 0; i < explosionAnimation.Count; i++)
                {
                    if (explosionAnimation[i].IsVisible)
                    {
                        explosionAnimation[i].Update(gameTime);
                    }
                    else
                    {
                        explosionAnimation.RemoveAt(i);
                        i--;
                    }
                }
                #endregion
            }
            hud = new HUD(new Vector2(mouse.X, mouse.Y), playerScoreFont, new Vector2(0, 50), healthbar);
            hud.Update(gameTime);
            base.Update(gameTime);
        }
Example #3
0
        /* Giá trị của retButton
         * 0-tower1
         * ...
         * 5-tower6
         * 6-special1
         * ...
         * 8-special3
         * 9-pause
         * 10-resume
         * 11-onmusic
         * 12-offmusic
         * 13-nextwave
         * 14-replay
         * -1-nothing
         */
        public void Update(Container.GameState CurrentState, MouseState mouse, int goldHave, GameTime gameTime)
        {
            GameState = CurrentState;
            KeyboardState state = new KeyboardState();

            state = Keyboard.GetState();
            if (Container.HP < 1)
            {
                GameState = Container.GameState.GameOver;
            }
            if (Game1.wave > Container.waveQuantity && Game1.enemyPerWave <= 0)
            {
                GameState = Container.GameState.Win;
            }
            switch (GameState)
            {
            case Container.GameState.GameOver:              //Trường hợp thua
                Container.HP = 0;
                backButton.Update(mouse);
                if (backButton.isClicked == true)           //Chơi lại
                {
                    GameState    = Container.GameState.MainMenu;
                    Container.HP = 100;
                    Game1.wave   = 1;
                    goldHave     = 400;
                }
                break;

            case Container.GameState.Win:               //Trường hợp thắng
                backButton.Update(mouse);
                if (backButton.isClicked == true)       //Chơi lại
                {
                    GameState    = Container.GameState.MainMenu;
                    Container.HP = 100;
                    Game1.wave   = 1;
                    goldHave     = 400;
                }
                break;

            case Container.GameState.MainMenu:              //Main menu
                playButton.Update(mouse);
                creditButton.Update(mouse);
                introButton.Update(mouse);
                backButton.Update(mouse);
                if (playButton.isClicked == true)
                {
                    GameState = Container.GameState.Playing;
                }
                else if (creditButton.isClicked == true)
                {
                    GameState = Container.GameState.Tacgia;
                }
                else if (introButton.isClicked == true)
                {
                    GameState = Container.GameState.Intro;
                }
                break;

            case Container.GameState.Intro:             //Giới thiệu
                if (backButton.isClicked == true || state.IsKeyDown(Keys.Escape))
                {
                    GameState = Container.GameState.MainMenu;
                }
                backButton.Update(mouse);
                break;

            case Container.GameState.Tacgia:            //Tác giả
                if (backButton.isClicked == true || state.IsKeyDown(Keys.Escape))
                {
                    GameState = Container.GameState.MainMenu;
                }
                backButton.Update(mouse);
                break;

            case Container.GameState.Playing:                                      //Đang chơi
                retButton = -1;
                if (pauseButton.isClicked == true || state.IsKeyDown(Keys.Escape)) //Nếu nhấn nut pause hoặc escape
                {
                    if (isPauseSet != true)
                    {
                        retButton = 9;
                    }
                    isPauseSet = !isPauseSet;
                    GameState  = Container.GameState.Pausing;
                    pauseButton.Update(mouse);
                }
                else
                {
                    resumeButton.Update(mouse);

                    foreach (towerButton tB in towerButtonList)
                    {
                        tB.Update(mouse, goldHave);
                    }
                    onMusicButton.Update(mouse);
                    offMusicButton.Update(mouse);
                    nextWave.Update(mouse);
                    pauseButton.Update(mouse);
                    replayButton.Update(mouse);
                    specialSkill1Button.Update(mouse);
                    specialSkill2Button.Update(mouse);
                    specialSkill3Button.Update(mouse);

                    if (onMusicButton.isClicked == true)
                    {
                        if (isSoundOn)
                        {
                            retButton = 11;
                        }
                        else
                        {
                            retButton = 12;
                        }
                        isSoundOn = !isSoundOn;
                    }
                    for (int i = 0; i < towerButtonList.Count; i++)
                    {
                        if (towerButtonList[i].isClicked == true)
                        {
                            retButton = i;
                        }
                    }
                    if (specialSkill1Button.isClicked == true)
                    {
                        RetButton = 6;
                    }
                    if (specialSkill2Button.isClicked == true)
                    {
                        RetButton = 7;
                    }
                    if (specialSkill3Button.isClicked == true)
                    {
                        RetButton = 8;
                    }
                    if (nextWave.isClicked == true)
                    {
                        RetButton = 13;
                    }
                    if (replayButton.isClicked == true)
                    {
                        RetButton = 14;
                    }
                }
                break;

            case Container.GameState.Pausing:                   //Trường hợp pause
                if (pauseButton.isClicked == true || state.IsKeyDown(Keys.Escape))
                {
                    if (isPauseSet)
                    {
                        RetButton = 10;
                    }
                    isPauseSet = !isPauseSet;
                    GameState  = Container.GameState.Playing;
                }
                pauseButton.Update(mouse);
                replayButton.Update(mouse);
                break;
            }
            base.Update(gameTime);
        }