Пример #1
0
        public GameForm()
        {
            ghosts = new Ghosts(this);
            ghosts.Load();

            player = new PacMan(this);
            player.Load();

            InitializeComponent();
        }
Пример #2
0
        //Check If Game is over
        public bool IsGameOver(Ghosts ghosts, PacMan player)
        {
            bool isGameOver = false;

            if (ghosts.GetBounds("blinky").IntersectsWith(player.GetBounds()))
            {
                isGameOver = true;
                ghostName  = "Blinky";
                score      = takenCoinCount;
            }
            if (ghosts.GetBounds("inky").IntersectsWith(player.GetBounds()))
            {
                isGameOver = true;
                ghostName  = "Pinky";
                score      = takenCoinCount;
            }
            return(isGameOver);
        }
Пример #3
0
 //Update Ghosts
 public void Update(PacMan player, PictureBox[] walls)
 {
     MoveBlinky(player, walls);
     MoveInky(player, walls);
 }
Пример #4
0
        //Move Inky
        void MoveInky(PacMan player, PictureBox[] walls)
        {
            int minX = inky.Location.X - player.refX;
            int minY = inky.Location.Y - player.refY;

            SetDirections(walls, "inky");

            if (stateInky == "idle")
            {
                if (minY < 0)
                {
                    if (!inkyDown && inkyRight)
                    {
                        inky.Left += inkySpeed;
                        inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightinky.png");
                        return;
                    }
                    if (!inkyDown && inkyLeft && inkyRight)
                    {
                        inky.Left += inkySpeed;
                        inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightinky.png");
                        return;
                    }
                }
                else if (minY > 0)
                {
                    if (!inkyUp && inkyLeft)
                    {
                        inky.Left -= inkySpeed;
                        inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\leftinky.jpg");
                        return;
                    }
                    if (!inkyUp && inkyLeft && inkyRight)
                    {
                        inky.Left -= inkySpeed;
                        inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\leftinky.jpg");
                        return;
                    }
                }
            }

            //MOVE ALONG Y AXIS
            if (minY > 0 && inkyUp)
            {
                inky.Top  += -inkySpeed;
                inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightinky.png");
                inky.Image.RotateFlip(RotateFlipType.Rotate90FlipY);
                stateInky = "walking";
                return;
            }
            else if (minY < 0 && inkyDown)
            {
                inky.Top  += inkySpeed;
                inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightinky.png");
                inky.Image.RotateFlip(RotateFlipType.Rotate90FlipX);
                stateInky = "walking";
                return;
            }

            // MOVE ALONG X AXIS
            if (minX > 0 && inkyLeft)
            {
                inky.Left += -inkySpeed;
                inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\leftinky.jpg");
                stateInky  = "walking";
                return;
            }
            else if (minX < 0 && inkyRight)
            {
                inky.Left += inkySpeed;
                inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightinky.png");
                stateInky  = "walking";
                return;
            }
            else
            {
                stateInky  = "idle";
                inky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\idleinky.jpg");
            }
        }
Пример #5
0
        //Move Blinky
        void MoveBlinky(PacMan player, PictureBox[] walls)
        {
            int minX = blinky.Location.X - player.refX;
            int minY = blinky.Location.Y - player.refY;

            SetDirections(walls, "blinky");

            if (stateBlinky == "idle")
            {
                if (minX > 0)
                {
                    //LEFT IDLE MOVEMENT
                    if (blinkyLeft && (blinkyUp || blinkyDown))
                    {
                        blinky.Left -= blinkySpeed;
                        blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\leftblinky.jpg");
                        return;
                    }
                    //MOVE Y AXIS

                    if (!blinkyLeft && blinkyUp)
                    {
                        blinky.Top  -= blinkySpeed;
                        blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                        blinky.Image.RotateFlip(RotateFlipType.Rotate90FlipY);
                        return;
                    }
                }
                //RIGHT IDLE MOVEMENT
                else if (minX < 0)
                {
                    //MOVE ALONG X AXIS
                    if (blinkyRight && (blinkyUp || blinkyDown))
                    {
                        blinky.Left += blinkySpeed;
                        blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                        return;
                    }
                    if (!blinkyRight && blinkyUp)
                    {
                        blinky.Top  -= blinkySpeed;
                        blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                        blinky.Image.RotateFlip(RotateFlipType.Rotate90FlipY);
                        return;
                    }
                }
            }
            // MOVE ALONG X AXIS
            if (minX > 0 && blinkyLeft)
            {
                blinky.Left += -blinkySpeed;
                blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\leftblinky.jpg");
                stateBlinky  = "walking";
                return;
            }
            else if (minX < 0 && blinkyRight)
            {
                blinky.Left += blinkySpeed;
                blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                stateBlinky  = "walking";
                return;
            }

            //MOVE ALONG Y AXIS
            if (minY > 0 && blinkyUp)
            {
                blinky.Top  += -blinkySpeed;
                blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                blinky.Image.RotateFlip(RotateFlipType.Rotate90FlipY);
                stateBlinky = "walking";
                return;
            }
            else if (minY < 0 && blinkyDown)
            {
                blinky.Top  += blinkySpeed;
                blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\rightblinky.jpg");
                blinky.Image.RotateFlip(RotateFlipType.Rotate90FlipX);
                stateBlinky = "walking";
                return;
            }
            else
            {
                stateBlinky  = "idle";
                blinky.Image = Image.FromFile($@"C:\Users\{Environment.UserName}\OneDrive\Desktop\Pac-Man\Sprites\idleblinky.jpg");
            }
        }