示例#1
0
        public override void Move()
        {
            if (myLevel == null)  // If no level has been indicated, it will not move
            {
                return;
            }

            // Decrease ghost chasing time
            if (isGrey)
            {
                greyTime--;
            }
            if (greyTime <= 0)
            {
                greyTime = 200;
                BecomeNormal();
            }

            // Move through the labyrinth
            if (myLevel.CanMoveTo(x + xSpeed, y + ySpeed,
                                  x + width + xSpeed, y + height + ySpeed))
            {
                x += xSpeed;
                y += ySpeed;
            }
            else
            {
                switch (randomGenerator.Next(0, 4))
                {
                case 0:     // Next move: to the right
                    xSpeed = baseEnemySpeed;
                    ySpeed = 0;
                    break;

                case 1:     // Next move: to the left
                    xSpeed = -baseEnemySpeed;
                    ySpeed = 0;
                    break;

                case 2:     // Next move: upwards
                    xSpeed = 0;
                    ySpeed = -baseEnemySpeed;
                    break;

                case 3:     // Next move: downwards
                    xSpeed = 0;
                    ySpeed = baseEnemySpeed;
                    break;
                }
            }

            // And change image if needed
            frameWaitCounter++;
            if (frameWaitCounter >= maxFramesToWait)
            {
                NextFrame();
                frameWaitCounter = 0;
            }
        }