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();
        }
Beispiel #2
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;
        }
Beispiel #3
0
 public Wave(int waveNum, int numberofdot, int timebetweendot, int enemyQuantity, float timeAppear, Map map)
 {
     _waveNum = waveNum;
     _numberOfDot = numberofdot;
     _timeBetweenDot = timebetweendot;
     _enemyQuantity = enemyQuantity;
     _map = map;
     _timeAppear = timeAppear;
 }
Beispiel #4
0
 public Dot(int pathIndex, Map map, int enemyQuantity, float timeAppear)
 {
     _pathIndex = pathIndex;
     _map = map;
     _enemyQuantity = enemyQuantity;
     _timeAppear = timeAppear;
     _enemyKilled = 0;
     _enemyAppeared = 0;
     _enemyStartMoving = true;
 }
        public Map CreateMap(int level)
        {
            Map map = new Map();

            Map mapLoaded = Data.loadMap(level);
            map.MapStructure = mapLoaded.MapStructure;
            map.TileTexture = this._tileMapTextures;
            map.Waypoints = mapLoaded.Waypoints;

            return map;
        }
Beispiel #6
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();
                }
            }
        }
Beispiel #7
0
        public static Map loadMap(int level)
        {
            Map map = new Map();
            XmlDocument doc = new XmlDocument();
            doc.Load(@"Data/map.dat");

            int numberOfPath = int.Parse(doc.SelectSingleNode("//map[@level=" + level + "]").Attributes["count"].Value);

            XmlNodeList structure = doc.SelectNodes("//map[@level=" + level + "]/structures/structure");
            int soDong = structure.Count;
            Global.COIN = int.Parse(doc.SelectSingleNode("//map[@level=" + level + "]").Attributes["coin"].Value);
            int soCot = int.Parse(structure[0].Attributes["count"].Value);

            map.MapStructure = new int[soDong, soCot];
            for (int i = 0; i < soDong; i++)
            {
                string temp = structure[i].InnerText;
                string[] temp1 = temp.Split(',');
                for (int j = 0; j < soCot; j++)
                {
                    map.MapStructure[i, j] = int.Parse((temp.Split(','))[j]);
                }
            }

            for (int index = 0; index < numberOfPath; index++)
            {
                Queue<Vector2> waypoint = new Queue<Vector2>();
                XmlNodeList waypoints = doc.SelectNodes(string.Format("//map[@level={0}]/waypoints[@value={1}]/waypoint", level, index));

                int[,] path = new int[soDong, soCot];
                for (int i = 0; i < soDong; i++)
                {
                    string temp = waypoints[i].InnerText;
                    string[] temp1 = temp.Split(',');
                    for (int j = 0; j < soCot; j++)
                    {
                        path[i, j] = int.Parse(temp1[j]);
                    }
                }

                int c = 0;
                int r = 0;

                for (int i = 0; i < soDong; i++)
                {
                    if (path[i, 0] == 1)
                    {
                        r = i;
                        break;
                    }
                }

                if (r == 0)
                {
                    for (int j = 0; j < soCot; j++)
                    {
                        if (path[1, j] == 1)
                        {
                            c = j;
                            break;
                        }
                    }
                }
                waypoint.Enqueue(new Vector2(c, r) * Global.CELL_WIDTH);

                while (c < soCot && r < soDong && r >= 0)
                {
                    if (path[r, c + 1] == 1)
                    {
                        waypoint.Enqueue(new Vector2(c + 1, r) * Global.CELL_WIDTH);
                        path[r, c] = 0;
                        c++;
                    }
                    else if (r > 0 && path[r - 1, c] == 1)
                    {
                        waypoint.Enqueue(new Vector2(c, r - 1) * Global.CELL_WIDTH);
                        path[r, c] = 0;
                        r--;
                    }
                    else if (path[r + 1, c] == 1)
                    {
                        waypoint.Enqueue(new Vector2(c, r + 1) * Global.CELL_WIDTH);
                        path[r, c] = 0;
                        r++;
                    }
                    else
                    {
                        break;
                    }
                }

                map.Waypoints.Add(waypoint);
            }

            return map;
        }