예제 #1
0
 public AsteroidController(AsteroidData _asteroid, AsteroidView _asteroidView)
 {
     this.asteroid     = _asteroid;
     this.asteroidView = _asteroidView;
     asteroidView.SetDamage(asteroid.Damage);
     resetHP = _asteroid.HP;
 }
예제 #2
0
        public static void Initialize(AsteroidData.TypeAsteroid typeAsteroid, AsteroidData _asteroidData, Vector2 maxPosition)
        {
            init = true;
            switch (typeAsteroid)
            {
            case AsteroidData.TypeAsteroid.Asteroid1:
                asteroid = Resources.Load <GameObject>("For pools/Asteroid/Asteroid");

                break;

            case AsteroidData.TypeAsteroid.Asteroid2:
                asteroid = Resources.Load <GameObject>("For pools/Asteroid/Asteroid2");
                break;

            case AsteroidData.TypeAsteroid.Asteroid3:
                asteroid = Resources.Load <GameObject>("For pools/Asteroid/Asteroid3");
                break;

            default:
                asteroid = Resources.Load <GameObject>("For pools/Asteroid/Asteroid");
                break;
            }

            pool = new SimpleObjectPool(asteroid, 10, _asteroidData, maxPosition);
        }
예제 #3
0
        public SimpleObjectPool(GameObject objectPrefab, int sizePool, AsteroidData asteroid, Vector2 maxPosition)
        {
            Vector3 position;

            _maxPosition  = maxPosition;
            objectStack   = new Stack <AsteroidController>();
            _objectPrefab = objectPrefab;
            _objectPrefab.SetActive(false);
            _asteroid = asteroid;
            for (int i = 0; i < sizePool; i++)
            {
                position = new Vector3(Random.Range(-maxPosition.x, maxPosition.x), maxPosition.y, 0);
                GameObject newObject = Object.Instantiate(_objectPrefab, position, Quaternion.identity) as GameObject;
                objectStack.Push(new AsteroidController(new AsteroidData(asteroid.HP, asteroid.Speed, asteroid.Damage, asteroid.Type), newObject.GetComponent <AsteroidView>()));
            }
        }
예제 #4
0
        /// <summary>
        /// загружаем уровень
        /// </summary>
        public void Load(int level)
        {
            // В зависимости от уровня загружаем нужный тип пуль
            bullet = new Bullet(bulletInfo[level - 1].Speed, bulletInfo[level - 1].SortingOrder, bulletInfo[level - 1].Power, bulletInfo[level - 1].Type);

            // загружаем данные игрока
            IFormatter formatter = new BinaryFormatter();

            string path = "";

            // при первом заходе на уровень загружаем дефолтные данные
            if (!PlayerPrefs.HasKey("Level" + level + "Default"))
            {
                path = Application.streamingAssetsPath + "/saveLavel" + CurrentLevel.ToString() + "Default.txt";
                PlayerPrefs.SetInt("Level" + level + "Default", 1);
            }
            else
            {
                if (PlayerPrefs.GetInt("LevelStay" + level) == (int)LevelManager.LevelStay.Save)
                {
                    path = Application.streamingAssetsPath + "/saveLavel" + CurrentLevel.ToString() + ".txt";
                }
                else
                {
                    path = Application.streamingAssetsPath + "/saveLavel" + CurrentLevel.ToString() + "Default.txt";
                }
            }
            FileStream buffer = File.OpenRead(path);
            ShipData   data   = formatter.Deserialize(buffer) as ShipData;

            ship = new Ship(data, bullet);
            buffer.Close();
            shipController = new ShipController(ship, shipPref);
            ShowShipInfo(data.HP, data.Score, data.Speed, data.FireRate);
            ship.ShipInfoEvent += OnShipInfo;
            // В зависимости от уровня загружаем нужный тип астероидов
            asteroidData = new AsteroidData(asteroidInfo[level - 1].HP, asteroidInfo[level - 1].Speed, asteroidInfo[level - 1].Damage, asteroidInfo[level - 1].Type);

            Spawn();
        }