Exemplo n.º 1
0
    public async ValueTask Reset()
    {
        await _gameSoundPlayer.Reset();

        _step     = 0;
        _finished = false;

        _pacman.StartDigesting();
        _ghostCollection.Ghosts.ForEach(g => g.StopMoving());

        _timer = new(2.Seconds(), () =>
        {
            _step += 1;
            _ = _gameSoundPlayer.PacManDying();

            _pacman.StartDying();

            _timer = new(2.Seconds(), async() =>
            {
                _step += 1;
                _finished = true;
                await _mediator.Publish(new PacManDeadEvent());
            });
        });
    }
Exemplo n.º 2
0
        public ValueTask Reset()
        {
            _finished = false;

            _progress = 0;

            var timeToShowPlayerNumberAndHideGhosts = 2.Seconds();

            if (!_gameStats.HasPlayedIntroTune)
            {
                _gameStats.HasPlayedIntroTune = true;
                _ = _gameSoundPlayer.PlayerStart();
            }

            _currentTimer = new LoopingTimer(timeToShowPlayerNumberAndHideGhosts, () =>
            {
                _progress += 1;

                _gameStats.CurrentPlayerStats.DecreaseLives();

                _currentTimer = new LoopingTimer(2.Seconds(), async() =>
                {
                    _finished = true;

                    var act = await _mediator.Send(new GetActRequest("GameAct"));

                    _game.SetAct(act);
                });
            });

            return(default);
Exemplo n.º 3
0
        void updateTearAnimation()
        {
            ++_animFrame;
            if (_animFrame < _tearFrames.Length)
            {
                _snagSprite = new GeneralSprite(
                    _centerPoint,
                    _tearSize,
                    _tearOffset,
                    _tearFrames[_animFrame]);

                //this.snagSprite.position = this.snagSprite.position.minus(new Point(1, 0));

                _blinky.Position = _blinky.Position - new Vector2(1, 0);

                return;
            }

            _animFrame      = 0;
            _blinky.Visible = false;
            setLookingBlinky(0);

            _lookTimer = new LoopingTimer(1500.Milliseconds(), async() => await updateBlinkyLookAnimation());

            _lookingBlinky.Visible = true;
            _stage = Stage.BlinkyLooking;
        }
Exemplo n.º 4
0
    public ValueTask Reset()
    {
        _finished = false;

        _progress = 0;

        var timeToShowPlayerNumberAndHideGhosts = 2.Seconds();

        if (!_gameStats.HasPlayedIntroTune)
        {
            _gameStats.HasPlayedIntroTune = true;
            _ = _gameSoundPlayer.PlayerStart();
        }

        _currentTimer = new(timeToShowPlayerNumberAndHideGhosts, () =>
        {
            _progress += 1;

            // If the current player has never played, they start of with 3 'remaining' lives
            // and one of them is removed, so they have the current life and 2 remaining.
            // We don't want to remove lives on every level though.
            _gameStats.CurrentPlayerStats.TryDecreaseInitialLives();

            _currentTimer = new(2.Seconds(), async() =>
            {
                _finished = true;

                var act = await _mediator.Send(new GetActRequest("GameAct"));

                _game.SetAct(act);
            });
        });

        return(default);
Exemplo n.º 5
0
        public GhostTearAct(IGameSoundPlayer gameSoundPlayer, IMediator mediator)
        {
            _gameSoundPlayer = gameSoundPlayer;
            _mediator        = mediator;

            _finished = false;
            //NextAct = nextAct;
            _stage     = Stage.MovingBlinky;
            _animFrame = 0;

            _tearFrames = new[]
            {
                new Vector2(589, 98),
                new Vector2(609, 98),
                new Vector2(622, 98),
                new Vector2(636, 98),
                new Vector2(636, 98),
                new Vector2(636, 98),
                new Vector2(649, 98)
            };

            _blinkyLookFrames = new[] {
                new Vector2(584, 113),
                new Vector2(600, 113)
            };

            _blinkyTimer = new EggTimer(4500.Milliseconds(), blinkyCaught);

            _tearTimer = new LoopingTimer(500.Milliseconds(),
                                          () => {
                if (_stage == Stage.TearingBlinky)
                {
                    updateTearAnimation();
                }
            });

            _lookTimer = new LoopingTimer(TimeSpan.MaxValue, () => { });

            _pacTimer = new EggTimer(4750.Milliseconds(), () => { });

            _pacMan = new AttractScenePacMan
            {
                Direction = Directions.Left
            };

            _snagSprite = new GeneralSprite(_centerPoint, _tearSize, _tearOffset, _tearFrames[0])
            {
                Visible = true
            };

            _blinky        = new AttractGhost(GhostNickname.Blinky, Directions.Left);
            _lookingBlinky = new NullSprite();

            var justOffScreen = new Vector2(250, 140);

            _pacPositions = new StartAndEndPos(justOffScreen, new Vector2(-70, justOffScreen.Y));

            _blinkyPositions = new StartAndEndPos(justOffScreen + new Vector2(120, 0), _centerPoint - new Vector2(10, 0));
        }
Exemplo n.º 6
0
    public GhostFrightSession(LevelProps levelProps)
    {
        _amountOfGhostsEaten = 0;
        _timeLeft            = levelProps.FrightGhostTime.Value;

        var flashesLeft = levelProps.FrightGhostFlashes;

        _timeLeftToStartFlashing = _timeLeft -
                                   TimeSpan.FromMilliseconds(flashesLeft * _eachFlashDurationMs.TotalMilliseconds);
        _timer = new(
            _eachFlashDurationMs, () => _tickTock = !_tickTock);
    }
Exemplo n.º 7
0
        public ValueTask Reset()
        {
            _progress = 0;

            var timeToShowPlayerNumberAndHideGhosts = 0.Seconds();

            _currentTimer = new LoopingTimer(timeToShowPlayerNumberAndHideGhosts, () =>
            {
                _progress += 1;

                _currentTimer = new LoopingTimer(2.Seconds(), () => _finished = true);
            });

            return(default);
Exemplo n.º 8
0
    public ValueTask Reset()
    {
        _finished = false;

        _timer = new(2.Seconds(), () =>
        {
            _step += 1;
            _maze.StartFlashing();

            _ghostCollection.Ghosts.ForEach(g => g.Visible = false);

            _timer = new(2.Seconds(), async() =>
            {
                _step += 1;
                _maze.StopFlashing();

                await _mediator.Publish(new LevelFinishedEvent());

                _finished = true;
            });
        });

        return(default);
Exemplo n.º 9
0
 public TwoFrameAnimation(TimeSpan switchEvery)
 {
     _timer = new(switchEvery, () => Flag = !Flag);
 }