Esempio n. 1
0
        public virtual void Init(Func<bool> shouldPauseCb, ITimeProvider time, ShipConfig config, ShipModel model, Rect levelBounds)
        {
            base.Init( shouldPauseCb, time );
            Config = config;
            Model = model;
            LevelBounds = levelBounds;
            ShipCollider = gameObject.As< BoxCollider >();

            if ( ShipCollider == null )
                throw new MissingComponentException( "Box collider is not present on Ship" );

            var poolItem = gameObject.As< PrefabPoolItem > ();
            if ( poolItem == null )
                throw new MissingComponentException("PrefabPoolItem is not present on Ship");

            poolItem.Reset = PoolReset;
        }
Esempio n. 2
0
        public override void StartLevel()
        {
            var camera = Camera.main;
            var cameraWidth = camera.GetOrthographicWidth();
            var cameraHeight = camera.GetOrthographicHeight();
            bounds = new Rect( -cameraWidth / 2, -cameraHeight / 2, cameraWidth, cameraHeight );

            background.transform.localScale = new Vector3( cameraWidth, cameraHeight, 1 );
            background.sharedMaterial = Instantiate( background.sharedMaterial );

            enemyShips = new LinkedList<EnemyShip>();
            var shipConfig = new ShipConfig( 0.1f, 0.1f );
            var shipModel = new ShipModel() { Lives = 3 };
            var weaponConfig = new WeaponConfig( 5f, 1, 0.5f );

            var weapon = Locator.ResLoader.LoadAndInstantiateAs< ProjectileWeapon >( "Weapons/Cannon" );
            weapon.Init( IsRunning, TimeProvider, weaponConfig, bounds, 1 );

            var enemyShipPrefab = Locator.ResLoader.Load< GameObject >( "Ships/Enemies/LaserCorvette" );
            enemyShipPrefabLink = enemyShipPrefab.transform;
            PrefabPoolManager.Prepare( enemyShipPrefabLink, 8 );

            Player = Locator.ResLoader.LoadAndInstantiateAs< PlayerShip >( "Ships/PlayerShip" );
            Player.transform.SetParent( transform, true );
            Player.OnShipDestroyed += OnGameOver;
            Player.Init( IsRunning, TimeProvider, shipConfig, shipModel, bounds);
            Player.Weapon = weapon;

            backgroundMaterial = background.GetComponent< Renderer >().sharedMaterial;
            initialTextureOffset = backgroundMaterial.GetTextureOffset( "_MainTex" );

            if ( musicTrack != null )
                Locator.Sound.PlayMusic( musicTrack );

            base.StartLevel();
        }
Esempio n. 3
0
        private void SpawnEnemy()
        {
            var weaponConfig = new WeaponConfig( 5f, 1, 1.5f );

            var speed = Locator.Random.GetRandom( 2f, 5f );
            var shipConfig = new ShipConfig( speed, 3f );
            var shipModel = new ShipModel() { Lives = 1, Score = Locator.Random.GetRandom( 5, 7) };
            var enemyShip = PrefabPoolManager.Spawn( enemyShipPrefabLink ).gameObject.As< EnemyShip >();

            enemyShip.transform.SetParent( transform, true );
            enemyShip.Init( IsRunning, TimeProvider, shipConfig, shipModel, bounds );

            if ( speed <= 3 )
            {
                //In the future Weapon instances will also be created and recycled through pooling
                var weapon = Locator.ResLoader.LoadAndInstantiateAs< ProjectileWeapon >( "Weapons/EnemyCannon" );
                weapon.Init( IsRunning, TimeProvider, weaponConfig, bounds, -1 );
                enemyShip.Weapon = weapon;
            }

            enemyShip.OnShipDestroyed += OnEnemyShipDestroyed;
            enemyShip.OnLeftBattlefield += OnEnemyShipLeftBattleField;
            enemyShips.AddLast( enemyShip );

            var randomPos = Locator.Random.GetRandom( bounds.x + enemyShip.HalfWidth, bounds.xMax - enemyShip.HalfWidth );
            enemyShip.X = randomPos;
            enemyShip.Z = bounds.yMax + enemyShip.HalfHeight;
         
            ++enemyShipsSpawned;
        }
Esempio n. 4
0
 public virtual void Apply(ShipModel ship)
 {
     
 }
Esempio n. 5
0
 private void UpdateData(ShipModel model)
 {
     LivesText.text = "Lives: " + model.Lives;
     ScoreText.text = "Score: " + model.Score;
 }
Esempio n. 6
0
 public override void Apply(ShipModel ship)
 {
     ship.Lives -= 1;
 }