Esempio n. 1
0
        public void SpawnDrones()
        {
            //Load Drones
            var droneObjects = _level.Map.ObjectGroup.Objects.Where(o => o.Name.StartsWith("drone")).ToArray();

            for (int i = 0; i < droneObjects.Length; i++)
            {
                var droneData = droneObjects[i];

                float droneSpeed = droneData.GetFloatProperty("speed", 100);

                var drone = new DroneGameObject(droneData.X, droneData.Y, droneData.Width, droneData.Height, droneSpeed,
                                                droneData.rotation);

                drone.DroneBehaviorListener = this;
                drone.OnUpdateListeners     = drone.OnUpdateListeners.Concat(new IOnUpdateListener[] { _enemiesSoundManager }).ToArray();

                _drones.Add(drone);

                _level.AddChild(drone);
            }

            for (int i = _drones.Count() - 1; i > -1; i--)
            {
                if (_drones[i].Destroyed)
                {
                    _drones.RemoveAt(i);
                }
            }

            Console.WriteLine($"{this}: drone count: {droneObjects.Length}");
        }
Esempio n. 2
0
 void IDroneBehaviorListener.OnEnemyCollision(DroneGameObject drone, GameObject enemy)
 {
     if (enemy is Stork)
     {
         if (drone.State != DroneGameObject.DroneState.HIT_ENEMY &&
             drone.State != DroneGameObject.DroneState.RETURN_TO_START_POINT_AFTER_HIT &&
             drone.State != DroneGameObject.DroneState.ENEMY_DETECTED)
         {
             CoroutineManager.StartCoroutine(DroneHitEnemyRoutine(drone, enemy), this);
         }
     }
 }
Esempio n. 3
0
        private IEnumerator CollisionWithDroneRoutine(DroneGameObject drone)
        {
            //_stork.InputEnabled = false;

            //Shake Camera
            MyGame.ThisInstance.Camera.shakeDuration = 500;

            LocalEvents.Instance.Raise(new StorkLocalEvent(_stork, StorkLocalEvent.Event.STORK_HIT_BY_DRONE));

            yield return(new WaitForMilliSeconds(2500));

            //_stork.InputEnabled = true;
            _inCollisionWithDrone = false;
            _lastDroneCollided    = null;
        }
Esempio n. 4
0
        IEnumerator DroneHitEnemyRoutine(DroneGameObject drone, GameObject enemy)
        {
            drone.SetState(DroneGameObject.DroneState.HIT_ENEMY);

            LocalEvents.Instance.Raise(new LevelLocalEvent(enemy, drone, _level,
                                                           LevelLocalEvent.EventType.DRONE_HIT_PLAYER));

            //Stole pizza animation
            yield return(StolePizzaAnimationRoutine(drone, enemy));

            if (drone.State != DroneGameObject.DroneState.END_LEVEL)
            {
                drone.DroneHitEnemy();
            }

            yield return(null);
        }
Esempio n. 5
0
        IEnumerator DroneReleasePizzaRoutine(DroneGameObject drone, Sprite pizza)
        {
            while (drone.State == DroneGameObject.DroneState.HIT_ENEMY ||
                   drone.State == DroneGameObject.DroneState.RETURN_TO_START_POINT_AFTER_HIT)
            {
                yield return(null);
            }

            int duration = 1000;

            SpriteTweener.TweenAlpha(pizza, 1, 0, duration);

            yield return(new WaitForMilliSeconds(duration));

            pizza.visible = false;
            pizza.alpha   = 1;
            pizza.parent  = _level;
        }
Esempio n. 6
0
        private IEnumerator StolePizzaAnimationRoutine(DroneGameObject drone, GameObject enemy)
        {
            CoroutineManager.StopCoroutine(_droneReleasePizzaRoutine);

            var pizza = _level.GetPizzaFromPool();

            pizza.SetScaleXY(1, 1);
            pizza.SetXY(enemy.x, enemy.y);
            pizza.alpha   = 1;
            pizza.visible = true;

            int firstAirplaneIndex = _level.FirstAirplaneIndex;

            _level.SetChildIndex(pizza, firstAirplaneIndex - 1);

            //Animate pizza

            float fromX = enemy.x;
            float fromY = enemy.y;

            float offsetX = 0;
            float offsetY = -25;

            int time     = 0;
            int duration = 450;

            while (time < duration && !drone.Destroyed)
            {
                pizza.x = Easing.Ease(Easing.Equation.CubicEaseOut, time, fromX, drone.x + offsetX - fromX, duration);
                pizza.y = Easing.Ease(Easing.Equation.CubicEaseOut, time, fromY, drone.y + offsetY - fromY, duration);

                time += Time.deltaTime;
                yield return(null);
            }

            pizza.parent = drone;
            pizza.SetXY(offsetX, offsetY);

            _droneReleasePizzaRoutine =
                CoroutineManager.StartCoroutine(DroneReleasePizzaRoutine(drone, (Sprite)pizza), this);
        }
Esempio n. 7
0
 void IDroneBehaviorListener.OnEnemyDetected(DroneGameObject drone, GameObject enemy)
 {
     LocalEvents.Instance.Raise(new LevelLocalEvent(enemy, drone, _level,
                                                    LevelLocalEvent.EventType.DRONE_DETECTED_ENEMY));
 }
Esempio n. 8
0
        void IColliderListener.OnCollisionWith(Stork stork, GameObject other)
        {
            if (!_inCollisionWithDeliveryPoint && other is DeliveryPoint)
            {
                if (!_level.IsLevelEnding)
                {
                    //Pizza delivered
                    LocalEvents.Instance.Raise(new LevelLocalEvent(_level, LevelLocalEvent.EventType.PIZZA_DELIVERED));

                    SoundManager.Instance.PlayFx(5);

                    //Drop the pizza to the center of the delivery point
                    var dropPoint = new Vector2(other.x, other.y);
                    CoroutineManager.StartCoroutine(DropPizzaRoutine(dropPoint), this);
                }

                _inCollisionWithDeliveryPoint = true;

                CoroutineManager.StartCoroutine(WaitDeliveryPointBeDisabled(other), this);
            }
            else if (!_stork.IsCollisionDisabled && !_inCollisionWithAirplane && other is CompoundCollider && other.parent is Airplane parent &&
                     parent != _lastAirplaneCollided)
            {
                _inCollisionWithAirplane = true;
                _lastAirplaneCollided    = parent;

                SoundManager.Instance.PlayFx(6);

                //Lose Pizza
                CoroutineManager.StartCoroutine(CollisionWithAirplaneRoutine(parent), this);
            }

            if (!_stork.IsCollisionDisabled && !_inCollisionWithDrone && other is DroneGameObject drone && drone != _lastDroneCollided &&
                drone.State != DroneGameObject.DroneState.RETURN_TO_START_POINT_AFTER_HIT)
            {
                _lastDroneCollided    = drone;
                _inCollisionWithDrone = true;

                SoundManager.Instance.PlayFx(6);

                //Lose Pizza
                CoroutineManager.StartCoroutine(CollisionWithDroneRoutine(drone), this);
            }

            if (!_stork.IsCollisionDisabled && !_inCollisionWithBullet && other is HunterBullet bullet && bullet != _lastBulletCollided)
            {
                _inCollisionWithBullet = true;

                if (bullet.IsCollisionEnabled) //When bullet is falling, ignore collision
                {
                    _lastBulletCollided = bullet;

                    SoundManager.Instance.PlayFx(6);

                    CoroutineManager.StartCoroutine(CollisionWithHunterBulletRoutine(bullet), this);
                }
            }

            if (!_stork.IsCollisionDisabled && !_inCollisionWithTornado && other is TornadoGameObject tornado && tornado != _lastTornadoCollided)
            {
                _inCollisionWithTornado = true;
                _lastTornadoCollided    = tornado;

                CoroutineManager.StartCoroutine(CollisionWithTornadoRoutine(tornado), this);
            }
        }