Exemple #1
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);
            }
        }
Exemple #2
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();
        }