예제 #1
0
        public frmMain()
        {
            InitializeComponent();

            //form config
            this.DoubleBuffered  = true;
            this.MaximizeBox     = false;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.ClientSize      = GameEngine.GameFieldSize();

            clientWidth  = this.ClientRectangle.Width;
            clientHeight = this.ClientRectangle.Height;

            //buffer
            backBuffer     = (Image) new Bitmap(clientWidth, clientHeight);
            bufferGraphics = Graphics.FromImage(backBuffer);

            graphics = this.CreateGraphics();
        }
예제 #2
0
        private void Draw(Graphics g)
        {
            //draw layers
            backLayer.Draw(g);
            foodLayer.Draw(g);

            //draw pacman
            pacMan.Draw(g);

            //draw ghosts
            for (int i = 0; i < GameObjects.Count; i++)
            {
                GameObjects[i].Draw(g);
            }

            //draw score
            g.DrawString("Score: " + totalScore, new Font("Arial", 12f, FontStyle.Bold), new SolidBrush(Color.Yellow), new Point(0, 0));

            //draw
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            //is game over
            if (this.isGameOver && this.isGameWon == false)
            {
                g.DrawString("GAME OVER", new Font("Arial", 32f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 3, stringFormat);
                g.DrawString("Press ENTER for new game", new Font("Arial", 18f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
            //is game won
            if (this.isGameOver && this.isGameWon)
            {
                g.DrawString("WINNER!", new Font("Arial", 32f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 3, stringFormat);
                g.DrawString("Press ENTER for new game", new Font("Arial", 18f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
            //is power up active
            if (this.isGameOver == false && pacMan.HasPower)
            {
                g.DrawString("POWER UP ACTIVATED!", new Font("Arial", 24f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 4, stringFormat);
            }
            //if game is paused
            if (this.isPaused)
            {
                g.DrawString("GAME PAUSED", new Font("Arial", 24f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
        }