示例#1
0
 public virtual void Init(Func<bool> shouldPauseCb, ITimeProvider time, WeaponConfig config, Rect levelBounds)
 {
     base.Init( shouldPauseCb, time);
     Config = config;
     LevelBounds = levelBounds;
     ShotFiredTimeStamp = Time.Time;
 }
示例#2
0
        public void Init(Func< bool > shouldPauseCb, ITimeProvider time, WeaponConfig config, Rect levelBounds, int shotDirection)
        {
            base.Init( shouldPauseCb, time, config, levelBounds );

            PrefabPoolManager.Prepare( ShotPrefabLink, 8);
            ShotDirection = shotDirection;
        }
示例#3
0
        public void Init(Func<bool> shouldPauseCb, ITimeProvider time, WeaponConfig weaponConfig, BaseShip owner, Rect levelBounds )
        {
            base.Init( shouldPauseCb, time);
            WeaponConfig = weaponConfig;
            Owner = owner;
            LevelBounds = levelBounds;

            ProjectileCollider = gameObject.As< BoxCollider >();

            if ( ProjectileCollider == null )
                throw new MissingComponentException("Box collider is not present on Projectile");
        }
示例#4
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();
        }
示例#5
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;
        }
示例#6
0
 public void Init( Func<bool> shouldPauseCb, ITimeProvider time, WeaponConfig weaponConfig, int direction, BaseShip owner, Rect levelBounds )
 {
     base.Init( shouldPauseCb, time, weaponConfig, owner, levelBounds);
     Direction = direction;
 }