private void PacmanForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(Color.White);
            Random rand  = new Random();
            int    count = 24;

            for (int i = 0; i < foodWorld.Length; i++)
            {
                for (int j = 0; j < foodWorld[i].Length; j++)
                {
                    if (foodWorld[i][j])
                    {
                        count++;
                        g.DrawImageUnscaled(foodImage, j * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Height) / 2, i * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Width) / 2);
                    }
                }
            }
            Brush b = new SolidBrush(Color.Red);

            foreach (Prepreka p in prepreki)
            {
                g.FillRectangle(b, p.P.X * Pacman.Radius * 2, p.P.Y * Pacman.Radius * 2, 2 * Pacman.Radius, 6 * Pacman.Radius);
            }
            textBox1.Text      = String.Format("Points: {0}", WORLD_HEIGHT * WORLD_WIDTH - count);
            progressBar1.Value = WORLD_HEIGHT * WORLD_WIDTH - count;
            pacman.Draw(g);
        }
Exemple #2
0
        public void GamePlay()//the event that occurs every timer tick, this is when the game is running
        {
            scoreLabel.Text = "Score: " + pacman.Score.ToString();
            maze.Draw();
            PacmanAnimation();
            pacman.Draw();
            ChasePacman();
            MoveGhouls();
            CheckNumberOfKibble();
            CheckForPacmanGhouls();
            DrawGhouls();

            foreach (Ghoul ghoul in ghouls)
            {
                if (ghoul.FoundPacman == true)
                {
                    pacmanDeath.Play();
                    pacman.Life--;

                    if (pacman.Life == 0)
                    {
                        gameEnd = true;
                    }
                    else if (pacman.Life > 0)
                    {
                        StartNewLife();
                    }
                }
            }
        }
Exemple #3
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //for (int i = 0; i < 8; i++)
            //{
            //    xx[i] = x.Split(',')[i];
            //    yy[i] =y.Split(',')[i];
            //}
            Graphics g = e.Graphics;

            g.Clear(Color.White);
            for (int i = 0; i < foodWorld.Length; i++)
            {
                for (int j = 0; j < foodWorld[i].Length; j++)
                {
                    if (foodWorld[i][j])
                    {
                        g.DrawImageUnscaled(foodImage, j * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Height) / 2, i * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Width) / 2);
                    }
                }
            }
            g.FillRectangle(brush, 40, 40, 40, 120);
            g.FillRectangle(brush, 0, 240, 40, 120);
            g.FillRectangle(brush, 200, 0, 40, 120);
            g.FillRectangle(brush, 320, 40, 40, 120);
            g.FillRectangle(brush, 240, 240, 40, 120);
            g.FillRectangle(brush, 520, 80, 40, 120);
            g.FillRectangle(brush, 320, 200, 40, 120);
            g.FillRectangle(brush, 520, 240, 40, 120);
            pacman.Draw(g);
            if (Poeni == 149)
            {
                timer.Stop();
            }
        }
        //calls in the important methods of drawing the pacman and ghosts sprites
        //along with its movement scripts
        public void PlayGame()
        {
            pacman.animateddirection();
            pacman.Draw();
            pacman.Move();

            //calls in the foreach methods to draw and provide movement for the ghosts
            GhostsMove();
            GhostsDraw();

            //each time pacman eats a pellet it increases his score by 1;
            if (pacman.Eatpellets())
            {
                points++;
                if (points == 10)
                {
                    points += 1;
                }
                if (points == 25)
                {
                    points += 5;
                }
            }

            //if (maze.NKibbles == points)
            //{
            //    wingame = true;
            //}
        }
Exemple #5
0
        /// <summary>
        /// Draw code of the program
        /// </summary>
        private void Draw()
        {
            window.Clear();

            Score.Draw(window);

            if (gameState == GameState.Ready)
            {
                window.Draw(readyText);
            }

            if (gameState == GameState.Lose)
            {
                window.Draw(gameOverText);
            }

            grid.Draw(window);
            pacman.Draw(window);
            blinky.Draw(window);
            inky.Draw(window);
            pinky.Draw(window);
            clyde.Draw(window);

            window.Display();
        }
Exemple #6
0
        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < level.GetLength(0); i++)
            {
                for (int j = 0; j < level.GetLength(1); j++)
                {
                    level[i, j].Draw(spriteBatch);
                }
            }

            foreach (Food f in food)
            {
                f.Draw(spriteBatch);
            }

            pacman.Draw(spriteBatch);

            foreach (Character g in ghosts)
            {
                g.Draw(spriteBatch);
            }

            if (start_timer > 0)
            {
                spriteBatch.DrawString(font, "Game starts in " + (int)start_timer + " seconds", new Vector2(5, 5), Color.White);
            }
            else
            {
                spriteBatch.DrawString(font, "Score: " + score, new Vector2(5, 5), Color.White);
                spriteBatch.DrawString(font, "Lives: " + pacman.Health(), new Vector2(tile_X * 16 - (int)font.MeasureString("Lives: " + pacman.Health()).Length() - 5, 5), Color.White);
            }
        }
Exemple #7
0
 public void DrawGraphic()
 {
     using (var g = Graphics.FromImage(Background))
     {
         this.DrawBackGround(g);
         this.DrawInterior(g);
         this.DrawDots(g);
         pacman.Draw(g);
         pinky.Draw(g);
     }
 }
Exemple #8
0
        void timer_Tick(object sender, EventArgs e)
        {
            Graphics g = Graphics.FromImage(doubleBuffer);

            g.Clear(Color.White);
            for (int i = 0; i < foodWorld.Length; i++)
            {
                for (int j = 0; j < foodWorld[i].Length; j++)
                {
                    if (pacman.X == j && pacman.Y == i)
                    {
                        foodWorld[i][j] = false;
                    }
                    if (foodWorld[i][j])
                    {
                        g.DrawImageUnscaled(foodImage, j * Pacman.RADIUS * 2 + (Pacman.RADIUS * 2 - foodImage.Height) / 2, i * Pacman.RADIUS * 2 + (Pacman.RADIUS * 2 - foodImage.Width) / 2);
                    }
                }
            }
            pacman.Move(WORLD_WIDTH, WORLD_HEIGHT);
            pacman.Draw(g);
            graphics.DrawImageUnscaled(doubleBuffer, 0, 0);
        }
Exemple #9
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            DrawWallBlocks(spriteBatch);
            DrawFoodBlocks(spriteBatch);
            DrawBonusBlocks(spriteBatch);

            pacMan.Draw(gameTime, spriteBatch);

            foreach (Enemy enemy in enemies)
            {
                enemy.Draw(gameTime, spriteBatch);
            }

            base.Draw(gameTime);
        }
Exemple #10
0
 private void Form1_Paint(object sender, PaintEventArgs e)
 {
     e.Graphics.Clear(Color.White);
     for (var i = 0; i < _foodWorld.Length; i++)
     {
         for (var j = 0; j < _foodWorld[i].Length; j++)
         {
             if (_foodWorld[i][j])
             {
                 e.Graphics.DrawImageUnscaled(_foodImage, j * Pacman.Radius * 2 + (Pacman.Radius * 2 - _foodImage.Height) / 2, i * Pacman.Radius * 2 + (Pacman.Radius * 2 - _foodImage.Width) / 2);
             }
         }
     }
     _pacman.Draw(e.Graphics);
 }
Exemple #11
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(Color.White);
            for (int i = 0; i < foodWorld.Length; i++)
            {
                for (int j = 0; j < foodWorld[i].Length; j++)
                {
                    if (foodWorld[i][j])
                    {
                        g.DrawImageUnscaled(foodImage, j * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Height) / 2, i * Pacman.Radius * 2 + (Pacman.Radius * 2 - foodImage.Width) / 2);
                    }
                }
            }
            pacman.Draw(g);
        }
Exemple #12
0
 private void Form1_Paint(object sender, PaintEventArgs e)
 {
     drawOranges(e.Graphics);
     game.Draw(e.Graphics);
 }
Exemple #13
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here

            spriteBatch.Begin();

            int nbBean = 0;

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    if (map[i, j] == 1 || map[i, j] == 3)
                    {
                        nbBean++;
                    }
                }
            }

            if (nbBean == 0)
            {
                map             = (int[, ])oldMap.Clone();
                pacman.Map      = map;
                pacman.Position = Util.Vector(17, 13);
                for (int i = 0; i < ghosts.GetLength(0); i++)
                {
                    ghosts[i].Position = Util.Vector(14, 12 + i);
                }
            }

            if (lifes <= 0)
            {
                string  end  = "GAME OVER";
                Vector2 size = font.MeasureString(end);
                spriteBatch.DrawString(font, end, new Vector2(Window.ClientBounds.Width / 2 - size.X / 2, Window.ClientBounds.Height / 2 - size.Y / 2), Color.White);
            }
            else
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < columns; j++)
                    {
                        switch (map[i, j])
                        {
                        case 0:
                            wall.Position = Util.Vector(i, j);
                            wall.Draw(spriteBatch, gameTime);
                            break;

                        case 1:
                            bean.Position = Util.Vector(i, j);
                            bean.Draw(spriteBatch, gameTime);
                            break;

                        case 3:
                            gros_bean.Position = Util.Vector(i, j);
                            gros_bean.Draw(spriteBatch, gameTime);
                            break;
                        }
                    }
                }

                pacman.Draw(spriteBatch, gameTime);

                foreach (Ghost ghost in ghosts)
                {
                    ghost.Draw(spriteBatch, gameTime);
                }

                string  stat = "Score : " + score + "\n\nLifes : " + lifes;
                Vector2 size = font.MeasureString(stat);
                spriteBatch.DrawString(font, stat, new Vector2(screenWidth - 100, 50), Color.White);
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemple #14
0
        private void Form1_Paint_1(object sender, PaintEventArgs e)
        {
            this.BackColor = Color.Black;
            Graphics g = e.Graphics;

            g.Clear(Color.Black);
            for (int i = 0; i < foodWorld.Length; i++)
            {
                for (int j = 0; j < foodWorld[i].Length; j++)
                {
                    if (foodWorld[i][j])
                    {
                        g.DrawImageUnscaled(foodImage, j * 20 * 2 + (20 * 2 - foodImage.Height) / 2, i * 20 * 2 + (20 * 2 - foodImage.Width) / 2);
                        if (i == 0)
                        {
                            foodWorld[i][j] = false;
                        }

                        /* if (i == 3 && j < 4)
                         * {
                         *  g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                         *  obstacleWorld[i][j] = false;
                         * }
                         * else if (j == 2 && i < 2)
                         * {
                         *  g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                         *  obstacleWorld[i][j] = false;
                         * }
                         * else if (i == 7 && (5 < j && j < 8))
                         * {
                         *  g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                         *  obstacleWorld[i][j] = false;
                         * }
                         * else if (i == 7 && (2 < j && j < 5))
                         * {
                         *  g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                         *  obstacleWorld[i][j] = false;
                         * }
                         * else if (i < 7 && j == 5)
                         * {
                         *  g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                         *  obstacleWorld[i][j] = false;
                         * } */
                    }
                    if (!obstacleWorld[i][j])
                    {
                        g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, i * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                    }
                }
            }

            if (randomFlag)
            {
                randomFlag = false;
                Random random = new Random();
                for (int i = 0; i < 3; i++)
                {
                    int x = random.Next(foodWorld.Length - 5);
                    for (int j = 0; j < 3; j++)
                    {
                        g.DrawImageUnscaled(obstacleImage, j * 20 * 2 + (20 * 2 - obstacleImage.Height) / 2, x + 1 * 20 * 2 + (20 * 2 - obstacleImage.Width) / 2);
                        obstacleWorld[x + 1][j] = false;
                    }
                }
            }

            if (foodflag)
            {
                foodflag = false;
                for (int i = 0; i < obstacleWorld.Length; i++)
                {
                    for (int j = 0; j < obstacleWorld[i].Length; j++)
                    {
                        if (obstacleWorld[i][j])
                        {
                            foodCount++;
                        }
                    }
                }
            }
            pacman.Draw(g);
        }