Exemple #1
0
        public static float DistanceBetween(CellIndex cell1, CellIndex cell2)
        {
            float a = cell1.X - cell2.X;
            float b = cell1.Y - cell2.Y;

            return((float)Math.Sqrt(a * a + b * b));
        }
Exemple #2
0
        public async ValueTask PillEaten(CellIndex point)
        {
            await _ghostHouseDoor.PillEaten();

            await IncreaseScoreBy(10);

            _levelStats.PillEaten(point);
        }
Exemple #3
0
        public static Tile FromIndex(CellIndex index)
        {
            var tile = new Tile();

            tile.UpdateWithSpritePos(new Vector2(index.X * 8, index.Y * 8));

            return(tile);
        }
Exemple #4
0
        public async ValueTask PowerPillEaten(CellIndex point)
        {
            FrightSession = new GhostFrightSession(_levelStats.GetLevelProps());

            await _ghostHouseDoor.PillEaten();

            await IncreaseScoreBy(50);

            _levelStats.PillEaten(point);
        }
Exemple #5
0
        public void PillEaten(CellIndex cellPosition)
        {
            FruitSession.PillEaten();

            --PillsRemaining;

            int index = cellPosition.Y * 29 + cellPosition.X;

            _currentMap[index] = '+';
        }
Exemple #6
0
        public void UpdateWithSpritePos(Vector2 spritePos)
        {
            SpritePos = spritePos;
            Index     = CellIndex.FromSpritePos(spritePos);

            TopLeft   = new Vector2(Index.X * 8, Index.Y * 8);
            CenterPos = TopLeft + Vector2s.Four;

            _isInCenter = CenterPos == spritePos.Round();

            handleWrapping();
        }
Exemple #7
0
        public async ValueTask Update(CanvasTimingInformation timing)
        {
            if (_currentPlayerStats == null)
            {
                throw new InvalidOperationException("no current player stats");
            }

            if (_lifeStatus == LifeStatus.BeingDigested)
            {
                return;
            }

            if (_lifeStatus == LifeStatus.Dying || _lifeStatus == LifeStatus.Dead)
            {
                handleDying();
                return;
            }

            updateAnimation(timing);

            if (_tile.IsNearCenter(2))
            {
                recordInput(timing);

                recenterInLane();

                handleDirection();
            }

            if (_tile.IsNearCenter(1.5))
            {
                await handleWhatIsUnderCell();

                var can = _maze.CanContinueInDirection(_direction, _tile);

                _speed = can ? Constants.PacManBaseSpeed : 0;
            }

            float speed = _speed;

            var levelProps = _currentPlayerStats.LevelStats.GetLevelProps();
            var inPillCell = _tile.Index == _pillEatenAt;

            var pcToUse = inPillCell ? levelProps.PacManDotsSpeedPc : levelProps.PacManSpeedPc;

            if (_currentPlayerStats.IsInFrightSession)
            {
                pcToUse = inPillCell ? levelProps.FrightPacManDotSpeedPc : levelProps.FrightPacManSpeedPc;
            }

            if (!inPillCell)
            {
                _pillEatenAt = CellIndex.Zero;
            }

            speed = speed * (pcToUse / 100);

            var offset = DirectionToIndexLookup.IndexVectorFor(_direction) * speed;

            Position = Position + offset;
        }
Exemple #8
0
 public static Vector2 ToVector2(this CellIndex cellIndex) => new Vector2(cellIndex.X, cellIndex.Y);
Exemple #9
0
 // special intersections have an extra restriction
 // ghosts can not choose to turn upwards from these tiles.
 public static bool IsSpecialIntersection(CellIndex cell) =>
 cell == _specialIntersections[0] ||
 cell == _specialIntersections[1] ||
 cell == _specialIntersections[2] ||
 cell == _specialIntersections[3];
Exemple #10
0
        public async ValueTask PowerPillEaten(CellIndex point)
        {
            await _playerStats[_currentPlayerIndex].PowerPillEaten(point);

            updateHighScore();
        }
Exemple #11
0
 public char GetCellContent(CellIndex point) => _currentMap[getArrayIndex(point)];
Exemple #12
0
 static int getArrayIndex(CellIndex point) => point.Y * 29 + point.X;