Beispiel #1
0
 /// <summary>
 /// In case this ghost is Inky, he will need a reference to blinky in order
 /// to find his way around the maze. Otherwise, setting this has no effect.
 /// </summary>
 /// <param name="blinky">A reference to Blinky.</param>
 public void SetBlinky(Ghost blinky)
 {
     blinky_ = blinky;
 }
Beispiel #2
0
 /// <summary>
 /// In case this ghost is Inky, he will need a reference to blinky in order
 /// to find his way around the maze. Otherwise, setting this has no effect.
 /// </summary>
 /// <param name="blinky">A reference to Blinky.</param>
 public void SetBlinky(Ghost blinky) {
     blinky_ = blinky;
 }
Beispiel #3
0
        /// <summary>
        /// Effectively moves the Pac Man according to member variable direction_.
        /// </summary>
        private void DoMove()
        {
            // Everytime the updateCount == updatesPerPixel, move one pixel in
            // the desired direction and reset the updateCount.
            updateCount_++;
            updateCount_ %= updatesPerPixel_;
            if (updateCount_ == 0)
            {
                // Now is a nice time to update our speed, like we do for the ghosts.
                if (Ghost.NextTile(direction_, position_).HasCrump)
                {
                    updatesPerPixel_ = Constants.PacManSpeed() + 2;
                }
                else
                {
                    updatesPerPixel_ = Constants.PacManSpeed();
                }

                // Move one pixel in the desired direction
                if (direction_ == Direction.Up)
                {
                    position_.DeltaPixel.Y--;
                }
                else if (direction_ == Direction.Down)
                {
                    position_.DeltaPixel.Y++;
                }
                else if (direction_ == Direction.Left)
                {
                    position_.DeltaPixel.X--;
                }
                else if (direction_ == Direction.Right)
                {
                    position_.DeltaPixel.X++;
                }

                // By moving one pixel we might have moved to another tile completely
                if (position_.DeltaPixel.X == 16)
                {
                    // Special case : the tunnel
                    if (position_.Tile.X == 27)
                    {
                        position_.Tile.X = 0;
                    }
                    else
                    {
                        position_.Tile.X++;
                    }
                    position_.DeltaPixel.X = 0;
                }
                else if (position_.DeltaPixel.X == -16)
                {
                    // Special case : the tunnel
                    if (position_.Tile.X == 0)
                    {
                        position_.Tile.X = 27;
                    }
                    else
                    {
                        position_.Tile.X--;
                    }
                    position_.DeltaPixel.X = 0;
                }
                else if (position_.DeltaPixel.Y == 16)
                {
                    position_.Tile.Y++;
                    position_.DeltaPixel.Y = 0;
                }
                else if (position_.DeltaPixel.Y == -16)
                {
                    position_.Tile.Y--;
                    position_.DeltaPixel.Y = 0;
                }
            }
        }
Beispiel #4
0
        void DoMove()
        {
            updateCount_++;
            updateCount_ %= updatesPerPixel_;
            if (updateCount_ == 0)
            {
                if (Ghost.NextTile(direction_, position_).HasCrump)
                {
                    updatesPerPixel_ = Constants.PacManSpeed() + 2;
                }
                else
                {
                    updatesPerPixel_ = Constants.PacManSpeed();
                }

                if (direction_ == Direction.Up)
                {
                    position_.DeltaPixel.Y--;
                }
                else if (direction_ == Direction.Down)
                {
                    position_.DeltaPixel.Y++;
                }
                else if (direction_ == Direction.Left)
                {
                    position_.DeltaPixel.X--;
                }
                else if (direction_ == Direction.Right)
                {
                    position_.DeltaPixel.X++;
                }

                if (position_.DeltaPixel.X == 16)
                {
                    if (position_.Tile.X == 27)
                    {
                        position_.Tile.X = 0;
                    }
                    else
                    {
                        position_.Tile.X++;
                    }
                    position_.DeltaPixel.X = 0;
                }
                else if (position_.DeltaPixel.X == -16)
                {
                    if (position_.Tile.X == 0)
                    {
                        position_.Tile.X = 27;
                    }
                    else
                    {
                        position_.Tile.X--;
                    }
                    position_.DeltaPixel.X = 0;
                }
                else if (position_.DeltaPixel.Y == 16)
                {
                    position_.Tile.Y++;
                    position_.DeltaPixel.Y = 0;
                }
                else if (position_.DeltaPixel.Y == -16)
                {
                    position_.Tile.Y--;
                    position_.DeltaPixel.Y = 0;
                }
            }
        }