Ejemplo n.º 1
0
 public static HomingDevice Attach(Serpents serpents, bool player = true, bool enemies = true)
 {
     var hd = new HomingDevice(serpents);
     if (player)
         serpents.PlayerSerpent.DirectionTaker = hd;
     if (enemies)
         serpents.Enemies.ForEach(_ => _.DirectionTaker = hd);
     return hd;
 }
Ejemplo n.º 2
0
        public LevelCompleteState(Serpents serpents)
        {
            _serpents = serpents;

            _homingDevice = new HomingDevice(_serpents);
            _serpents.PlayerSerpent.DirectionTaker = this;

            Vector3 toPosition, toLookAt;
            _serpents.PlayingField.GetCameraPositionForLookingAtPlayerCave(out toPosition, out toLookAt);

            _moveCamera = new MoveCamera(
                _serpents.Camera,
                4.5f.UnitsPerSecond(),
                toPosition,
                () => _serpents.PlayerSerpent.LookAtPosition);

            _serpents.PlayerCave.OpenDoor = true;

            // wait until serpent is in cave, then give length bonus
            _todo.AddOneShot(() => _homeIsNearCaveEntrance = true);
            _todo.AddWhile(time => !_serpentIsHome);
            _todo.AddOneShot(() =>
            {
                _serpents.PlayerSerpent.IsPregnant = false;
                _haltSerpents = true;
            });
            for (var i = 0; i < _serpents.PlayerSerpent.Length; i++)
                _todo.AddOneShot(1, () =>
                {
                    var tailSegement = _serpents.PlayerSerpent.RemoveTailWhenLevelComplete();
                    if (tailSegement != null)
                        _serpents.AddAndShowScore(500, tailSegement.Position);
                });

            // wait until all bonus texts gone
            _todo.AddWhile(time => _serpents.FloatingTexts.Items.Any());
            _todo.AddOneShot(() =>
            {
                _serpentIsHome = false;
                _haltSerpents = false;
                _homeIsNearCaveEntrance = false;
            });
            //_todo.AddWhile(time => !_serpentIsHome);

            _todo.AddOneShot(() =>
            {
                if (_serpents.PlayerEgg == null)
                {
                    _haltSerpents = false;
                    return;
                }
                _bonusLives = 1;
                _serpents.PlayerSerpent.DirectionTaker = null;
                var playerEggPosition = _serpents.PlayerEgg.Position;
                _moveCamera = new MoveCamera(_serpents.Camera, 2f.Time(), toPosition, () => playerEggPosition);
                // wait two sec (for camera) and then drive the baby home
                _todo.InsertNext(
                    time => time < 2,
                    time =>
                    {
                        _serpents.PlayerSerpent.Restart(_serpents.PlayingField, 0, _serpents.PlayerEgg.Whereabouts);
                        _serpents.PlayerEgg = null;
                        _serpents.PlayerSerpent.DirectionTaker = this;
                        _haltSerpents = false;
                        _serpentIsHome = false;
                        return false;
                    });
            });

            // make sure the camera aims at a serpent (the original or the new born baby)
            _todo.AddOneShot(() =>
            {
                _moveCamera = new MoveCamera(_serpents.Camera, 1f.Time(), toPosition, () => _serpents.PlayerSerpent.LookAtPosition);
            });

            _todo.AddWhile(time => (!_serpentIsHome || _serpents.FloatingTexts.Items.Any()) && time < 10);
        }