Esempio n. 1
0
        private IEnumerator WaitForTargetBeenSetInLevel(TornadoGameObject tornado)
        {
            while (_level.Stork == null)
            {
                yield return(null);
            }

            tornado.Target = _level.Stork;
        }
Esempio n. 2
0
        public void SpawnTornado(TiledObject tornadoData)
        {
            int   throwAngleMin = tornadoData.GetIntProperty("throw_angle_min", 0);
            int   throwAngleMax = tornadoData.GetIntProperty("throw_angle_max", 359);
            float throwDistance = tornadoData.GetFloatProperty("throw_distance", 512);

            var tornado = new TornadoGameObject(tornadoData.X, tornadoData.Y, tornadoData.Width, tornadoData.Height, throwAngleMin, throwAngleMax, throwDistance);

            tornado.OnUpdateListeners = tornado.OnUpdateListeners.Concat(new IOnUpdateListener[] { _enemiesSoundManager })
                                        .ToArray();

            CoroutineManager.StartCoroutine(WaitForTargetBeenSetInLevel(tornado), this);

            string idString = tornadoData.Name.Replace("tornado ", "");

            if (int.TryParse(idString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var id))
            {
                //Check if has path
                var pathObj = _level.Map.ObjectGroup.Objects.FirstOrDefault(ob => ob.Name == $"path tornado {id}");
                if (pathObj != null && pathObj.polygons?.Length == 1)
                {
                    var pathPos = new Vector2(pathObj.X, pathObj.Y);

                    //Get points
                    var pts = pathObj.polygons[0].points.Select(pt => pt + pathPos).ToArray();

                    if (pts.Length > 0)
                    {
                        tornado.Path = pts;
                    }
                }
            }

            _level.AddChild(tornado);

            _tornadosList.Add(tornado);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        private IEnumerator CollisionWithTornadoRoutine(TornadoGameObject tornado)
        {
            MyGame.ThisInstance.Camera.shakeDuration = 3000;

            _stork.InputEnabled        = false;
            _stork.IsMoveEnabled       = false;
            _stork.IsCollisionDisabled = true;

            _stork.SetSpeed(0);

            //Turn stork
            var turnStorkRoutine = CoroutineManager.StartCoroutine(TurnStorkInTornadoRoutine(), this);

            //Snap to tornado
            int       snapTimer    = 0;
            const int snapDuration = 200;

            var snapStartPos = _stork.Pos;

            SoundManager.Instance.PlayFx(9);

            while (snapTimer < snapDuration)
            {
                float xPos = (tornado.Pos.x - snapStartPos.x) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, snapTimer, 0, 1, snapDuration);
                float yPos = (tornado.Pos.y - snapStartPos.y) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, snapTimer, 0, 1, snapDuration);

                _stork.SetXY(snapStartPos.x + xPos, snapStartPos.y + yPos);

                snapTimer += Time.deltaTime;

                yield return(null);
            }

            //Keep stork in tornado
            int       stuckTimer    = 0;
            const int stuckDuration = 2000;

            while (stuckTimer < stuckDuration)
            {
                _stork.SetXY(tornado.x, tornado.y);

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

            //Thrown Stork

            SoundManager.Instance.PlayFx(6);

            float throwAngle = 0;

            if (tornado.ThrowAngleMin == tornado.ThrowAngleMax)
            {
                throwAngle = tornado.ThrowAngleMin;
            }
            else
            {
                throwAngle = MRandom.Range((float)tornado.ThrowAngleMin, (float)tornado.ThrowAngleMax);
            }

            throwAngle = throwAngle.DegToRad();

            var throwDirection = new Vector2()
            {
                x = Mathf.Cos(throwAngle),
                y = Mathf.Sin(throwAngle)
            };

            var throwStartPos = tornado.Pos;
            var throwPos      = throwStartPos + throwDirection * tornado.ThrowDistance;

            int thrownTimer    = 0;
            int thrownDuration = 1000;

            float startScale = _stork.scale;

            Console.WriteLine($"{this}: throwAngle: {throwAngle.RadToDegree()}");

            while (thrownTimer < thrownDuration)
            {
                float xPos = (throwPos.x - throwStartPos.x) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration);
                float yPos = (throwPos.y - throwStartPos.y) *
                             Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration);

                _stork.SetXY(throwStartPos.x + xPos, throwStartPos.y + yPos);

                float scale;
                if (thrownTimer < thrownDuration * 0.5f)
                {
                    scale = startScale + Easing.Ease(Easing.Equation.QuadEaseOut, thrownTimer, 0, 1, thrownDuration * 0.5f);
                }
                else
                {
                    scale = startScale + 1 - Easing.Ease(Easing.Equation.QuadEaseIn, thrownTimer - thrownDuration * 0.5f, 0, 1, thrownDuration * 0.5f);
                }

                _stork.SetScaleXY(scale, scale);

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

            _stork.SetScaleXY(startScale, startScale);

            _inCollisionWithTornado = false;
            _lastTornadoCollided    = null;

            _stork.InputEnabled        = true;
            _stork.IsMoveEnabled       = true;
            _stork.IsCollisionDisabled = false;
        }