Example #1
0
        public Player(ContentManager content)
        {
            mapManager = new MapManager(content);
            _map = mapManager.CreateMap(Global.LEVEL);
            towerButtons = Data.loadTowerButton(content);
            waveManager = Data.loadWave(Global.LEVEL);
            SetUpPanel(content);
            coin_tex = content.Load<Texture2D>(@"Sprite\Image\coin");
            coin = new NormalSprite(coin_tex, 0, 0, coin_tex.Width, coin_tex.Height);

            speed_1_tex = content.Load<Texture2D>(@"Sprite\Image\Menu\button_x1");
            NormalSprite speed_1 = new NormalSprite(speed_1_tex, 685, 5, speed_1_tex.Width / 2, speed_1_tex.Height);
            increaseSpeed_1 = new Checkbox(speed_1, 2, Global.NEW_GAME_SPEED == 1 ? true : false);
            speedButtonList.Add(increaseSpeed_1);

            skip_tex = content.Load<Texture2D>(@"Sprite\Image\Menu\button_skip");
            NormalSprite speed_2 = new NormalSprite(skip_tex, 720, 5, skip_tex.Width / 2, skip_tex.Height);
            increaseSpeed_2 = new Checkbox(speed_2, 2, Global.NEW_GAME_SPEED == 2 ? true : false);
            speedButtonList.Add(increaseSpeed_2);

            speed_3_tex = content.Load<Texture2D>(@"Sprite\Image\Menu\button_x3");
            NormalSprite speed_3 = new NormalSprite(speed_3_tex, 755, 5, speed_3_tex.Width / 2, speed_3_tex.Height);
            increaseSpeed_3 = new Checkbox(speed_3, 2, Global.NEW_GAME_SPEED == 3 ? true : false);
            speedButtonList.Add(increaseSpeed_3);

            _content = content;
        }
        public WaveManager(Map map, int numberOfWave, float timeBetweenWaves, int[] numberofdot, int[] timebetweendot, int[] numberOfEnemy, float[] timeEnemyAppear)
        {
            _waves = new Queue<Wave>();
            _numberOfWave = numberOfWave;
            _map = map;
            _timeBetweenWaves = timeBetweenWaves;
            _numberOfDot = numberofdot;
            _timeBetweenDot = timebetweendot;
            _numberOfEnemy = numberOfEnemy;
            _timeEnemyAppear = timeEnemyAppear;

            _toolbarfont = FontManager.getFont(0);
            _wavefont = FontManager.getFont(1);

            Texture2D texture = Global.CONTENT.Load<Texture2D>(@"Sprite\Image\Menu\button_skip");
            NormalSprite skip = new NormalSprite(texture, 750, 55, texture.Width / 2, texture.Height / 2);
            button_skip = new MenuButton(skip, 2, 1, 0, 0);

            for (int i = 0; i < _numberOfWave; i++)
            {
                Wave wave = new Wave(i, _numberOfDot[i], _timeBetweenDot[i], _numberOfEnemy[i], _timeEnemyAppear[i], _map);
                _waves.Enqueue(wave);
            }

            StartNextWave();
        }
Example #3
0
 public Arrow(string strArrowFile, ContentManager content, Vector2 position, float rotation = 0, float speed = 0, int damage = 0)
 {
     Texture2D texture = content.Load<Texture2D>(strArrowFile);
     _sprite = new NormalSprite(texture, 0, 0, texture.Width, texture.Height);
     _speed = speed;
     _curSpeed = 1;
     _defaultSpeed = _speed;
     _damage = damage;
     _rotation = rotation;
 }
 public Background(string strBackgroundFilePath, ContentManager Content, float v, float t)
 {
     Texture2D texture = Content.Load<Texture2D>(strBackgroundFilePath);
     scale = Global.GAME_HEIGHT / texture.Height;
     Width = texture.Width;
     Height = texture.Height;
     Sprite = new NormalSprite(texture, 0, 0, Width, Height, scale);
     this.v = v;
     this.t = t;
     _P0 = Vector2.Zero;
 }
Example #5
0
 public Checkbox(NormalSprite sprite, int nframe, bool value)
 {
     _sprite = sprite;
     _nFrame = nframe;
     if (value)
     {
         _iFrame = 1;
     }
     else
         _iFrame = 0;
 }
 public MenuButton(NormalSprite sprite, int frames, int buttonID, float v, float t)
 {
     if (v == 0)
         _ViTriHienTai = sprite.Left;
     else
         _ViTriHienTai = 0;
     ButtonSprite = sprite;
     nFrame = frames;
     ButtonID = buttonID;
     _scaleRatio = (float)ButtonSprite.Width / (ButtonSprite.Texture.Width / 2);
     _v = v;
     _t = t;
 }
Example #7
0
        private void SetUpPanel(ContentManager Content)
        {
            menuButtonList = new List<MenuButton>();

            #region Panel
            Texture2D texture_lose = Content.Load<Texture2D>(@"Sprite\Image\Menu\panel_lose");
            panel_lose = new NormalSprite(texture_lose, 250, 150, texture_lose.Width, texture_lose.Height);
            Texture2D texture_win = Content.Load<Texture2D>(@"Sprite\Image\Menu\panel_win");
            panel_win = new NormalSprite(texture_win, 250, 150, texture_win.Width, texture_win.Height);
            #endregion
            float x = panel_lose.Left + panel_lose.Texture.Width / 3;
            float y = panel_lose.Top + panel_lose.Texture.Height / 2;

            #region Button menu in panel ID = 1
            Texture2D button_menu_texture = Content.Load<Texture2D>(@"Sprite\Image\Menu\button_menu");
            NormalSprite button_menu = new NormalSprite(button_menu_texture, x - button_menu_texture.Width / 4 + panel_lose.Texture.Width / 3, y, button_menu_texture.Width / 2, button_menu_texture.Height);
            menu = new MenuButton(button_menu, 2, 1, 0, 0);
            menuButtonList.Add(menu);
            #endregion

            #region Button replay in panel ID = 2
            Texture2D button_replay_texture = Content.Load<Texture2D>(@"Sprite\Image\Menu\button_replay");
            NormalSprite button_replay = new NormalSprite(button_replay_texture, x - button_replay_texture.Width / 4, y, button_replay_texture.Width / 2, button_replay_texture.Height);
            replay = new MenuButton(button_replay, 2, 2, 0, 0);
            menuButtonList.Add(replay);
            #endregion

            #region Button play in panel ID = 3
            Texture2D button_play_texture = Content.Load<Texture2D>(@"Sprite\Image\Menu\button_play");
            NormalSprite button_play = new NormalSprite(button_play_texture, x - button_play_texture.Width / 4, y, button_play_texture.Width / 2, button_play_texture.Height);
            play = new MenuButton(button_play, 2, 3, 0, 0);
            menuButtonList.Add(play);
            #endregion
        }
Example #8
0
        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < speedButtonList.Count; i++)
            {
                speedButtonList[i].Update(gameTime);

                int value = speedButtonList[i].pressCheckbox(false);
                switch (value)
                {
                    case 1:
                        Global.OLD_GAME_SPEED = Global.NEW_GAME_SPEED;
                        Global.NEW_GAME_SPEED = i + 1;
                        switch (Global.OLD_GAME_SPEED)
                        {
                            case 1:     // x 1
                                if (Global.NEW_GAME_SPEED == 2)
                                {
                                    Global.GAME_SPEED = 2;
                                    increaseSpeed_1.setFrame(0);
                                    increaseSpeed_3.setFrame(0);
                                }
                                if (Global.NEW_GAME_SPEED == 3)
                                {
                                    Global.GAME_SPEED = 4;
                                    increaseSpeed_1.setFrame(0);
                                    increaseSpeed_2.setFrame(0);
                                }
                                break;

                            case 2:     // x 2
                                if (Global.NEW_GAME_SPEED == 1)
                                {
                                    increaseSpeed_2.setFrame(0);
                                    increaseSpeed_3.setFrame(0);
                                    Global.GAME_SPEED = 1;
                                }
                                if (Global.NEW_GAME_SPEED == 3)
                                {
                                    increaseSpeed_1.setFrame(0);
                                    increaseSpeed_2.setFrame(0);
                                    Global.GAME_SPEED = 4;
                                }
                                break;
                            case 3:     // x 4
                                if (Global.NEW_GAME_SPEED == 1)
                                {
                                    increaseSpeed_2.setFrame(0);
                                    increaseSpeed_3.setFrame(0);
                                    Global.GAME_SPEED = 1;
                                }
                                if (Global.NEW_GAME_SPEED == 2)
                                {
                                    increaseSpeed_1.setFrame(0);
                                    increaseSpeed_3.setFrame(0);
                                    Global.GAME_SPEED = 2;
                                }
                                break;
                        }
                        break;
                }
            }

            if (isPanelVisible)
            {
                for (int i = 0; i < menuButtonList.Count; i++)
                {
                    menuButtonList[i].Update(gameTime);

                    int id = menuButtonList[i].getButtonPressedID();
                    switch (id)
                    {
                        case 1:     // quay về menu chính
                            if (isLose == false)
                                Global.LEVEL += 1;

                            Data.saveDataBeforeQuit();
                            towers.Clear();
                            Global.SCREEN = GameScreen.MENU;
                            Global.playMusic(SoundManager.mu_menuSound, true);
                            break;

                        case 2:
                            towers.Clear();
                            if (isLose == false)
                            {
                                Global.LEVEL += 1;
                            }
                            _map = mapManager.CreateMap(Global.LEVEL);
                            waveManager = Data.loadWave(Global.LEVEL);
                            towerButtons = Data.loadTowerButton(_content);
                            waveManager.PlayerWin = false;
                            isLose = false;
                            Global.HEALTH = 100;
                            Global.playMusic(SoundManager.mu_backgroundSound, true);
                            break;
                    }
                }
            }

            if (waveManager.PlayerWin == false && isLose == false)
            {
                if (waveManager.IsNewWaveStart)
                {
                    enemies = Global.ENEMIES;
                }
                mouseState = Mouse.GetState();

                chiSoCot = (int)(mouseState.X / Global.CELL_WIDTH);
                chiSoDong = (int)(mouseState.Y / Global.CELL_HEIGHT);

                viTriDong = (int)(chiSoDong * Global.CELL_WIDTH);
                viTriCot = (int)(chiSoCot * Global.CELL_HEIGHT);

                waveManager.Update(gameTime);

                if (waveManager.PlayerWin == true)
                    isPanelVisible = true;

                #region Chọn tháp và rê vào vị trí muốn đặt, xuất hiện tháp nếu đủ coin
                for (int i = 0; i < towerButtons.Count; i++)
                {
                    towerButtons[i].Update(gameTime);

                    int towerIdx = towerButtons[i].getButtonPressedID(true);

                    if (towerIdx >= 0)
                        towerIndexSelected = towerIdx;

                    if (towerIndexSelected >= 0)
                    {
                        if (mouseState.LeftButton == ButtonState.Pressed)
                        {
                            isDragging = true;
                            chiSoCot = (int)(mouseState.X / Global.CELL_WIDTH);
                            chiSoDong = (int)(mouseState.Y / Global.CELL_HEIGHT);

                            viTriDong = (int)(chiSoDong * Global.CELL_WIDTH);
                            viTriCot = (int)(chiSoCot * Global.CELL_HEIGHT);

                            preview = BuildingManager.SampleBuilding[towerIndexSelected].sprite;
                            preview.Left = viTriCot;
                            preview.Top = viTriDong - (preview.Texture.Height - Global.CELL_HEIGHT);
                            oldState = mouseState;
                        }
                        mouseState = Mouse.GetState();
                        if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed)
                        {
                            isDragging = false;
                            chiSoCot = (int)(mouseState.X / Global.CELL_WIDTH);
                            chiSoDong = (int)(mouseState.Y / Global.CELL_HEIGHT);

                            viTriDong = (int)(chiSoDong * Global.CELL_WIDTH);
                            viTriCot = (int)(chiSoCot * Global.CELL_HEIGHT);

                            if (laViTriHopLe())
                            {
                                Tower tower = (Tower)BuildingManager.CreateBuilding(towerIndexSelected);
                                if (Global.COIN >= tower.Cost && tower.LevelReq <= Global.LEVEL)
                                {
                                    tower.sprite.Left = viTriCot;
                                    tower.sprite.Top = viTriDong - (tower.sprite.Texture.Height - Global.CELL_HEIGHT);
                                    towers.Add(tower);
                                    Global.COIN -= tower.Cost;
                                }
                            }
                            towerIndexSelected = -1;
                        }
                    }
                }
                #endregion

                foreach (Tower tower in towers)
                {
                    if (tower.TargetEnemy == null)
                    {
                        tower.getClosestEnemy(enemies);
                    }
                    tower.Update(gameTime);
                }

                oldState = mouseState;

                if (Global.HEALTH <= 0)
                {
                    Global.HEALTH = 0;
                    isPanelVisible = true;
                    isLose = true;
                    if (Global.SOUNDEFFECT_ENABLE)
                        SoundManager.so_failSound.Play();
                }
            }
        }
Example #9
0
        public static List<MenuButton> loadTowerButton(ContentManager Content)
        {
            List<MenuButton> list = new List<MenuButton>();

            XmlDocument doc = new XmlDocument();
            doc.Load(@"Data/tower.dat");

            XmlNodeList towerButtons = doc.SelectNodes("//tower-button");

            for (int i = 0; i < towerButtons.Count; i++)
            {
                if (int.Parse(towerButtons[i].Attributes[0].Value) <= Global.LEVEL)
                {
                    Texture2D texture = Content.Load<Texture2D>(towerButtons[i].InnerText);
                    NormalSprite sprite = new NormalSprite(texture, 34 + i * 67, 510, texture.Width / 2, texture.Height);
                    MenuButton button = new MenuButton(sprite, 2, i, 0, 0);

                    list.Add(button);
                }
            }

            return list;
        }
Example #10
0
 public Toolbar(ContentManager content)
 {
     Texture2D texture = content.Load<Texture2D>(@"Sprite\Image\Menu\menu_bar_bottom");
     bar = new NormalSprite(texture, 0, 500, texture.Width, texture.Height);
 }
Example #11
0
        private void createQuitScreen()
        {
            Texture2D panel = Content.Load<Texture2D>(@"Sprite\Image\Menu\quit");
            quitPanel = new NormalSprite(panel, 200, (Global.GAME_HEIGHT - panel.Height)/2, panel.Width, panel.Height);

            Texture2D yes_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\yes");
            NormalSprite yes = new NormalSprite(yes_tex, (Global.GAME_WIDTH - yes_tex.Width) / 2 - 5, Global.GAME_HEIGHT / 2, yes_tex.Width / 2, yes_tex.Height);
            btn_yes = new MenuButton(yes, 2, 1, 0, 0);

            Texture2D no_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\no");
            NormalSprite no = new NormalSprite(no_tex, Global.GAME_WIDTH / 2 + 5, Global.GAME_HEIGHT / 2, no_tex.Width / 2, no_tex.Height);
            btn_no = new MenuButton(no, 2, 2, 0, 0);
        }
Example #12
0
 private void createPausePanel()
 {
     createOptionScreen(@"Sprite\Image\Menu\pause_panel");
     Texture2D menuButton_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\menu");
     NormalSprite menuButton = new NormalSprite(menuButton_tex, 340, 375, menuButton_tex.Width / 2, menuButton_tex.Height);
     button_menu = new MenuButton(menuButton, 2, 4, 0, 0);
 }
Example #13
0
        private void createOptionScreen(string panel_file)
        {
            Data.loadConfig();
            Texture2D texture = Content.Load<Texture2D>(panel_file);
            _optionPanel = new NormalSprite(texture, 250, 150, texture.Width, texture.Height);

            Texture2D checkbox_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\checkbox");

            NormalSprite checkbox_sound = new NormalSprite(checkbox_tex, 458, 230, checkbox_tex.Width / 2, checkbox_tex.Height);
            button_sound = new Checkbox(checkbox_sound, 2, Global.SOUNDEFFECT_ENABLE);

            NormalSprite checkbox_music = new NormalSprite(checkbox_tex, 458, 270, checkbox_tex.Width / 2, checkbox_tex.Height);
            button_music = new Checkbox(checkbox_music, 2, Global.MUSIC_ENABLE);

            Texture2D okButton_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\ok");
            NormalSprite okButton = new NormalSprite(okButton_tex, 340, 325, okButton_tex.Width / 2, okButton_tex.Height);
            button_ok = new MenuButton(okButton, 2, 3, 0, 0);
        }
Example #14
0
        private void createAboutScreen()
        {
            Texture2D panel = Content.Load<Texture2D>(@"Sprite\Image\Menu\about");
            aboutPanel = new NormalSprite(panel, 250, 150, panel.Width, panel.Height);

            Texture2D close_tex = Content.Load<Texture2D>(@"Sprite\Image\Menu\ok");
            NormalSprite close = new NormalSprite(close_tex, (Global.GAME_WIDTH - close_tex.Width / 2) / 2, 300, close_tex.Width / 2, close_tex.Height);
            btn_close = new MenuButton(close, 2, 1, 0, 0);
        }
Example #15
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            #region Khởi tạo Resolution của game và độ rộng của 1 ô
            Global.GAME_WIDTH = GraphicsDevice.Viewport.Bounds.Width;
            Global.GAME_HEIGHT = GraphicsDevice.Viewport.Bounds.Height;
            Global.CELL_WIDTH = 50;
            Global.CELL_HEIGHT = 50;
            #endregion

            #region Khởi tạo giá trị HEALTH của người chơi, Game speed
            Global.HEALTH = 100;
            Global.GAME_SPEED = 1;
            Global.NEW_GAME_SPEED = 1;
            Global.OLD_GAME_SPEED = Global.NEW_GAME_SPEED;
            Global.CONTENT = Content;
            #endregion

            #region Khởi tạo background và logo
            _backgroundSprite = new Background(@"Sprite\Image\background", Content, 2, 0.1f);
            _logoTexture = this.Content.Load<Texture2D>(@"Sprite\Image\logo");
            _logoSprite = new NormalSprite(_logoTexture, (GraphicsDevice.Viewport.Width - _logoTexture.Width) / 2, 35, _logoTexture.Width, _logoTexture.Height, 1);

            //Animation đốm lửa sau logo
            _backgroundAnimatedTexture = this.Content.Load<Texture2D>(@"Sprite\Image\backgroundAnimation");
            _backgroundAnimatedSprite = new AnimatedSprite(_backgroundAnimatedTexture, (GraphicsDevice.Viewport.Width - _logoTexture.Width) / 2, 0, _backgroundAnimatedTexture.Width, _backgroundAnimatedTexture.Height, 65, 6, 8);
            #endregion

            #region Khởi tạo menu game
            _menuBackgroundTexture = this.Content.Load<Texture2D>(@"Sprite\Image\Menu\menuBackground");
            _mainMenu = new Menu();
            for (int i = 0; i < _nButton; i++)
            {
                _menuButtonTexture = this.Content.Load<Texture2D>(@"Sprite\Image\Menu\Button" + (i + 1));
                NormalSprite _menuButtonSprite = new NormalSprite(_menuButtonTexture, GraphicsDevice.Viewport.Width / 20, (i + 3) * GraphicsDevice.Viewport.Height / 9, GraphicsDevice.Viewport.Width / 6, _menuButtonTexture.Height);
                MenuButton _button = new MenuButton(_menuButtonSprite, 2, i + 1, 2, 0.5f);
                _mainMenu.Buttons.Add(_button);
            }
            #endregion

            #region Khởi tạo âm thanh
            SoundManager.Init(Content);
            Data.loadConfig();
            #endregion

            createMenuScreen();
        }
 internal NormalSprite Clone()
 {
     NormalSprite newSprite = new NormalSprite(this.Texture, _left, _top, _width, _height, _scale);
     return newSprite;
 }