Example #1
0
        void Update()
        {
            if (MenuManager.ActiveMenu == this && MapManager.IsMapOpened)
            {
                // update text

                PlayerTank tank = PlayerTank.Instance;
                string     str  = string.Concat(
                    "Score ", MapManager.CurrentScore,
                    "\nLifes ", MapManager.NumLifes,
                    "\nHealth ",
                    (tank != null ? tank.health.ToString() : "0") + " / " + PickupManager.Instance.GetMaxPlayerTankHealth(),
                    "\nDamage ",
                    (tank != null ? tank.bulletDamage.ToString() : "0") + " / " + PickupManager.Instance.GetMaxPlayerTankBulletDamage(),
                    "\nLevel ", MapManager.CurrentLevel,
                    "\nEnemies left ", EnemyTankSpawner.Instance.NumTanksLeftToSpawn + EnemyTank.AllTanks.Count);

                if (this.hudText.text != str)
                {
                    this.hudText.text = str;
                }

                // update game-over text
                this.gameOverText.gameObject.SetActive(MapManager.IsGameOver);
            }

            if (Input.GetButtonDown("Pause") && MapManager.IsMapOpened)
            {
                if (MenuManager.ActiveMenu == this)
                {
                    MenuManager.ActiveMenu = PauseMenu.Instance;
                }
            }
        }
Example #2
0
        private async void Start()
        {
            Platform.ImportCurrentStage();
            await UniTask.Yield();

            foreach (var color in humanPlayerColors)
            {
                Gamepad.GetInstance(color).Add(gamepadListeners[color] = new GamepadListener(color));
            }


            // spawn enemy
            EnemyTank.lifes[EnemyTank.Type.Big] = 1;
            EnemyAgent.SpawnTank().Forget();



            // spawn player
            PlayerTank.lifes[Tank.Color.Yellow] = 1;            // Test
            PlayerTank.lifes[Tank.Color.Green]  = 1;            // Test

            if (aiPlayerColors.Length != 0)
            {
                "Player Agent".Instantiate(transform);
            }
            foreach (var color in humanPlayerColors)
            {
                PlayerTank.Spawn(color, false).Forget();
            }
            foreach (var color in aiPlayerColors)
            {
                PlayerTank.Spawn(color, false).Forget();
            }
        }
Example #3
0
            public void OnButtonStart()
            {
                // Đang còn BUG


                // Chỉ được Pause trong Offline Mode

                if (gamepadColor != Tank.Color.Yellow)
                {
                    return;
                }
                isPause = !isPause;
                foreach (var c in instance.humanPlayerColors)
                {
                    var g      = Gamepad.GetInstance(c);
                    var player = PlayerTank.GetLivingTank(c);
                    if (!isPause)
                    {
                        g.Add(player);
                    }
                    else if (g.Contains(player))
                    {
                        g.Remove(player);
                    }
                }
                Agent.GetInstance <EnemyAgent>().enabled = !isPause;
                var agent = Agent.GetInstance <PlayerAgent>();

                if (agent)
                {
                    agent.enabled = !isPause;
                }
            }
Example #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            scoreField = new ScoreField(Content, GraphicsDevice, currentLevel);

            playerTank = new PlayerTank(Content, "playertank1");

            enemyTankSprite1 = Content.Load <Texture2D>("enemytank1");
            enemyTankSprite2 = Content.Load <Texture2D>("enemytank2");

            bulletSprite = Content.Load <Texture2D>("bulletSprite");

            levelData = Content.Load <LevelData[]>("levelData");

            tilesSprite = Content.Load <Texture2D>("minitiles");

            // load audio content
            audioEngine = new AudioEngine(@"Content\GameAudio.xgs");
            waveBank    = new WaveBank(audioEngine, @"Content\Wave Bank.xwb");
            soundBank   = new SoundBank(audioEngine, @"Content\Sound Bank.xsb");

            cuePlayerMove = soundBank.GetCue("w6_playerMove");

            cueEnemyMove = soundBank.GetCue("w13_enemyMove");
            cueEnemyMove.Play();
            cueEnemyMove.Pause();

            menuScreen      = new MenuScreen(Content);
            scoreScreen     = new ScoreScreen(Content, currentLevel, soundBank);
            nextLevelScreen = new NextLevel(Content, GraphicsDevice, currentLevel);
            endGameScreen   = new EndGameScreen(Content);

            scoreSprite           = Content.Load <Texture2D>("scoreSprite");
            gameOverDrawRectangle = new Rectangle(
                GameConstants.TILE_WIDTH * (GameConstants.FIELD_WIDTH_TILES / 2) - GameConstants.SMALL_TILE_WIDTH,
                GameConstants.FIELD_HEIGHT,
                GameConstants.TILE_WIDTH * 2, GameConstants.TILE_WIDTH);
            gameOverSourceRectangle = new Rectangle(
                0, GameConstants.TILE_WIDTH + GameConstants.SMALL_TILE_WIDTH,
                GameConstants.TILE_WIDTH * 2, GameConstants.TILE_WIDTH);

            pauseDrawRectangle = new Rectangle(
                GameConstants.TILE_WIDTH * (GameConstants.FIELD_WIDTH_TILES / 2) - GameConstants.SMALL_TILE_WIDTH,
                GameConstants.GAME_OVER_Y_POSITION,
                GameConstants.TILE_WIDTH * 2, GameConstants.SMALL_TILE_WIDTH);
            pauseSourceRectangle = new Rectangle(
                0, GameConstants.TILE_WIDTH,
                GameConstants.TILE_WIDTH * 2 + GameConstants.SMALL_TILE_WIDTH, GameConstants.SMALL_TILE_WIDTH);
        }
Example #5
0
        public override void ApplyEffect()
        {
            PlayerTank tank = PlayerTank.Instance;

            if (tank != null)
            {
                // 3 levels of strength/damage (0.34 * 3 = 1.02)

                float newPerc = Mathf.Min(tank.GetHealthPerc() + 0.34f, 2.0f);
                tank.SetHealthPerc(newPerc);

                newPerc = Mathf.Min(tank.GetBulletDamagePerc() + 0.34f, 2.0f);
                tank.SetBulletDamagePerc(newPerc);
            }
        }
Example #6
0
        static System.Collections.IEnumerator LoadLevelCoroutine(string[] lines, float timeToWaitBeforeLoading)
        {
            s_isLoadingLevel = true;

            yield return(null);

            yield return(new WaitForSeconds(timeToWaitBeforeLoading));

            // first destroy all existing objects
            foreach (GameObject go in FindObjectsOfType <MapObject>().Select(obj => obj.gameObject)
                     .Concat(FindObjectsOfType <EnemyTank>().Select(obj => obj.gameObject)
                             .Concat(FindObjectsOfType <Bullet>().Select(obj => obj.gameObject))))
            {
                Destroy(go);
            }

            yield return(null);

            yield return(null);


            var dict = new Dictionary <char, GameObject>()
            {
                { 'b', Instance.brickPrefab }, { 'w', Instance.wallPrefab }, { '~', Instance.waterPrefab },
                { 'f', Instance.flagPrefab },
                { 's', Instance.playerSpawnPrefab },
                { 'e', Instance.enemySpawnPrefab },
            };

            int width  = s_mapWidth = lines[0].Length;
            int height = s_mapHeight = lines.Length;

            s_mapObjects = new MapObject[width, height];

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    char c = lines[i][j];
                    if (dict.ContainsKey(c))
                    {
                        Vector2Int pos = new Vector2Int(j, height - i - 1);
                        SpawnMapObject(dict[c], pos);
                    }
                }
            }

            // set ground scale and position

            Transform groundTransform = GameObject.Find("Ground").transform;

            Vector3 groundScale = groundTransform.localScale;

            groundScale.x = width;
            groundScale.z = height;
            groundTransform.localScale = groundScale;

            groundTransform.position = new Vector3(width / 2f - 0.5f, groundTransform.position.y, height / 2f - 0.5f);

            // set camera position
            if (CurrentLevel <= 1)
            {
                CameraManager.Instance.SwitchToSideView();
            }

            if (null == PlayerTank.Instance)
            {
                SpawnPlayerTank();
            }
            else
            {
                // reset position of player tank
                PlayerTank tank = PlayerTank.Instance;

                Transform tr  = tank.transform;
                Vector3   pos = FindObjectOfType <PlayerSpawn>().transform.position;
                pos.y = tr.position.y;

                tank.CController.enabled = false;
                tr.position = pos;
                tr.rotation = Quaternion.identity;
                tank.CController.enabled = true;

                // restore health
                if (tank.GetHealthPerc() < 1)
                {
                    tank.SetHealthPerc(1);
                }
            }

            // reset num lifes
            NumLifes = Instance.startingNumLifes;

            AudioManager.Instance.PlayMusic(AudioManager.kLevelLoadSoundIndex);

            s_isLoadingLevel = false;

            Debug.LogFormat("LoadLevel() finished");

            onLevelLoaded();
        }