public PlayingState(Serpents serpents, SerpentCamera serpentCamera) { SerpentCamera = serpentCamera; _serpents = serpents; _serpents.PlayerSerpent.DirectionTaker = this; _serpents.ParallelToDos.AddOneShot(0.9f, () => _serpents.PlayerCave.OpenDoor = false); _serpents.EnemyCave.OpenDoor = false; }
public StartSerpentState(Serpents serpents) { _serpents = serpents; HomingDevice.Attach(_serpents).CanTurnAround = true; Vector3 toPosition, toLookAt; _serpents.PlayingField.GetCameraPositionForLookingAtPlayerCave(out toPosition, out toLookAt); _actions.AddDurable(new MoveCameraYaw( serpents.Camera, 5f.UnitsPerSecond(), toPosition, GetPlayerInitialLookAt(_serpents.PlayingField))); _actions.AddOneShot(() => _serpents.PlayerSerpent.Restart(_serpents.PlayingField, 1)); _actions.AddWhile(time => _serpents.PlayingField.FieldValue(_serpents.PlayerSerpent.Whereabouts).Restricted != Direction.None); _actions.AddOneShot(() => { _serpentCamera = new SerpentCamera(_serpents.Camera, _serpents.PlayerSerpent, 0, 1, 8); while (_serpents.Enemies.Count > 3 + _serpents.Scene) // remove spawned serpents _serpents.Enemies.RemoveAt(0); foreach (var enemy in _serpents.Enemies) enemy.DirectionTaker = null; }); }
private void addCameraActions() { _cameraMovements.AddWait(_random.NextFloat(2, 8)); switch (_random.Next(8)) { case 0: // go to random position while (true) { var newPosition = new Vector3(_random.NextFloat(-2, 25), 0, _random.NextFloat(-2, 25)); var dx = _random.NextFloat(5, 10); var dz = _random.NextFloat(5, 10); if (_random.Next() < 0.5) dx = -dx; if (_random.Next() < 0.5) dz = -dz; var newLookAt = new Vector3(MathUtil.Clamp(newPosition.X + dx, 5, 20), 0, MathUtil.Clamp(newPosition.Z + dz, 5, 20)); if (Vector3.DistanceSquared(newPosition, newLookAt) < 30) continue; _cameraMovements.AddDurable(new MoveCameraYaw( _serpents.Camera, 2f.UnitsPerSecond(), newPosition + Vector3.Up*5, newLookAt)); break; } break; case 2: // pan in random direction { var direction = _serpents.Camera.Left*_random.NextFloat(5, 10)*(_random.NextDouble() < 0.5 ? 1 : -1); _cameraMovements.AddDurable(() => new MoveCameraYaw( _serpents.Camera, 2f.UnitsPerSecond(), _serpents.Camera.Position + direction, _serpents.Camera.Target + direction)); break; } case 3: case 4: case 5: // follow a serpent around awhile { var serpent = _random.NextDouble() > 0.4 || !_serpents.Enemies.Any() ? (BaseSerpent) _serpents.PlayerSerpent : _serpents.Enemies[_random.Next(0, _serpents.Enemies.Count)]; var serpentCamera = new SerpentCamera(_serpents.Camera, serpent, 0, 1, 5); _cameraMovements.AddWhile(time => { serpentCamera.Do(time); return time < 8 && serpent.SerpentStatus == SerpentStatus.Alive; }); break; } default: { _cameraMovements.AddDurable(GetOverviewMoveCamera(_serpents.Camera)); break; } } }