Exemplo n.º 1
0
        // Clears the scene and draws the game (Paddle, Ball, Walls, Text)
        private void DrawGame(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            Brush cBrush;   // Used to draw solid shapes

            // Clear the scene
            cBackBuffer.Clear(Color.Black);

            // Draw the Pitch Meter
            mcPitchMeter.Draw(cBackBuffer);

            // Draw the Pitch Meter To Match
            mcPitchMeterToMatch.Draw(cBackBuffer);


            // Display to press Space Bar to Pause the game
            cBrush = new SolidBrush(Color.LightBlue);
            cBackBuffer.DrawString("Pause - Space Bar", mcFontText, cBrush, 475, 530);

            // Display to press R to Restart the game
            cBackBuffer.DrawString("Restart - R", mcFontText, cBrush, 150, 530);

            // Display the players Score
            cBackBuffer.DrawString("Score " + miScore, mcFontText, cBrush, 10, 10);

            // Display how to earn points
            cBackBuffer.DrawString("Match your pitch closer to the Target pitch to earn more points", mcFontText, cBrush, 10, 50);

            // Display how many seconds remain in the game
            cBackBuffer.DrawString("Time " + mfGameTimeRemaining.ToString("#"), mcFontText, cBrush, 100, 260);

            // Release the Brush resource
            cBrush.Dispose();
        }
Exemplo n.º 2
0
        // Clears the scene and draws the game (Paddle, Ball, Walls, Text)
        private void DrawGame(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            Brush cBrush;                               // Used to draw solid shapes
            Pen   cPitchMeterPen = new Pen(Color.Gray); // Used to draw the Pitch Meter

            // Keep the Paddle in bounds
            if (mrPaddle.Top < mrTopWall.Bottom)
            {
                mrPaddle.Y = mrTopWall.Bottom;
            }
            else if (mrPaddle.Bottom > mrBottomWall.Top)
            {
                mrPaddle.Y = mrBottomWall.Top - mrPaddle.Height;
            }

            // Clear the scene
            cBackBuffer.Clear(Color.Black);

            // Draw the Players Paddle
            cBackBuffer.DrawImage(mcPaddleImage, mrPaddle);

            // Draw the Ball
            cBackBuffer.DrawImage(mcBallImage, mrBall);

            // Draw the Walls
            cBrush = new SolidBrush(Color.White);
            cBackBuffer.FillRectangle(cBrush, mrLeftWall);
            cBackBuffer.FillRectangle(cBrush, mrRightWall);
            cBackBuffer.FillRectangle(cBrush, mrTopWall);
            cBackBuffer.FillRectangle(cBrush, mrBottomWall);

            // Draw the Pitch Meter
            mcPitchMeter.Draw(cBackBuffer);

            // Draw the text
            cBrush = new SolidBrush(Color.LightBlue);
            cBackBuffer.DrawString("Score " + miScore.ToString(), mcFontText, cBrush, 10, 10);
            cBackBuffer.DrawString("Balls " + miLives.ToString(), mcFontText, cBrush, 690, 10);
            cBackBuffer.DrawString("Pause - Space Bar       Restart Game - R       Main Menu - Esc", mcFontText, cBrush, 10, 520);

            // Release the Brush and Pen resources
            cBrush.Dispose();
            cPitchMeterPen.Dispose();
        }
Exemplo n.º 3
0
        // Update this form
        private void UpdateForm(object sender, PaintEventArgs e)
        {
            // Get a handle to this forms Graphics object so we can draw to it
            Graphics cGraphics = e.Graphics;

            // Get input from PD (audio input from player), without keeping the Pitch within range
            CSoundInput.Instance().GetPDInput(false);

            // If we should be Detecting the Pitch
            if (mbDetectingPitch)
            {
                // Get the Players current Pitch
                int iPitch = (int)CSoundInput.Instance().fPitch;

                // Increment the Hits on the Players current Pitch
                miaPitchHits[iPitch]++;

                // If this is the lowest Pitch heard so far and it's been hit at least 10 times
                if ((CSoundInput.Instance().fPitch < CSoundInput.Instance().iLowerPitchRange ||
                     CSoundInput.Instance().iLowerPitchRange <= 10) && CSoundInput.Instance().fPitch > 1.0f &&
                    miaPitchHits[iPitch] >= 10)
                {
                    // Record this as the new lowest Pitch
                    CSoundInput.Instance().iLowerPitchRange = iPitch;

                    // If the Pitch is too low
                    if (CSoundInput.Instance().iLowerPitchRange < 0)
                    {
                        CSoundInput.Instance().iLowerPitchRange = 0;
                    }
                }

                // If this is the highest Pitch heard so far
                if ((CSoundInput.Instance().fPitch > CSoundInput.Instance().iUpperPitchRange ||
                     CSoundInput.Instance().iUpperPitchRange <= 10) && CSoundInput.Instance().fPitch > 1.0f &&
                    miaPitchHits[iPitch] >= 10)
                {
                    // Record this as the new highest Pitch
                    CSoundInput.Instance().iUpperPitchRange = iPitch;

                    // If the High Pitch isn't at least 10 Pitches louder than the low
                    if ((CSoundInput.Instance().iUpperPitchRange - CSoundInput.Instance().iLowerPitchRange) < 10)
                    {
                        // Increase the High Pitch to 10 Pitches louder
                        CSoundInput.Instance().iUpperPitchRange = CSoundInput.Instance().iLowerPitchRange + 10;

                        // If the Pitch is too high
                        if (CSoundInput.Instance().iUpperPitchRange > 130)
                        {
                            CSoundInput.Instance().iUpperPitchRange = 130;
                        }
                    }
                }
            }
            // Else we are not Detecting the Pitch
            else
            {
                // Draw the Pitch Meter
                mcPitchMeter.AutoDetectPitchAndUpdateMeter();
                mcPitchMeter.Draw(cGraphics);
            }

            // Show the Current Pitch
            textCurrentPitch.Text = CSoundInput.Instance().fPitch.ToString();

            // Show the High and Low Pitch Values
            numericHighPitch.Value = CSoundInput.Instance().iUpperPitchRange;
            numericLowPitch.Value  = CSoundInput.Instance().iLowerPitchRange;
        }
Exemplo n.º 4
0
        // Function to Draw the Game in it's current state to the Back Buffer
        private void DrawGame(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // Brush and Pen to draw with
            Brush cBrush;
            Pen   cPen;

            // Clear the screen to Black
            cBackBuffer.Clear(Color.Black);

            // Loop though all Targets in the Target List
            int iTargetIndex     = 0;
            int iNumberOfTargets = mcTargetList.Count;

            for (iTargetIndex = 0; iTargetIndex < iNumberOfTargets; iTargetIndex++)
            {
                // Save a handle to this Target for readability
                CTarget cTarget = mcTargetList[iTargetIndex];

                // Rectangle used to draw Target to the screen
                Rectangle rRect = new Rectangle((int)cTarget.rRect.X, (int)cTarget.rRect.Y, (int)cTarget.rRect.Width, (int)cTarget.rRect.Height);

                // If the Target is Facing Left
                if (cTarget.bFacingLeft)
                {
                    // Draw this Target to the screen facing Left
                    cBackBuffer.DrawImage(mcTargetFacingLeftImage, rRect, 0, 0, mcTargetFacingLeftImage.Width, mcTargetFacingLeftImage.Height, GraphicsUnit.Pixel, mcTargetImageAttributes);
                }
                // Else the Target is Facing Right
                else
                {
                    // Draw this Target to the screen facing Right
                    cBackBuffer.DrawImage(mcTargetFacingRightImage, rRect, 0, 0, mcTargetFacingLeftImage.Width, mcTargetFacingLeftImage.Height, GraphicsUnit.Pixel, mcTargetImageAttributes);
                }
            }

            // Draw the Pitch Meter
            mcPitchMeter.AutoDetectPitchAndUpdateMeter();
            mcPitchMeter.Draw(cBackBuffer);

            // Draw the area in which the Targets can be "hit"
            cPen = new Pen(Color.White);
            cBackBuffer.DrawRectangle(cPen, miSHOOT_TARGET_AREA_LEFT, miSHOOT_TARGET_AREA_TOP, (miSHOOT_TARGET_AREA_RIGHT - miSHOOT_TARGET_AREA_LEFT), (miSHOOT_TARGET_AREA_BOTTOM - miSHOOT_TARGET_AREA_TOP));

            // Display to press Space Bar to Pause the game
            cBrush = new SolidBrush(Color.LightBlue);
            cBackBuffer.DrawString("Pause - Space Bar", mcFontText, cBrush, 475, 530);

            // Display to press R to Restart the game
            cBackBuffer.DrawString("Restart - R", mcFontText, cBrush, 150, 530);

            // Display the players Score
            cBackBuffer.DrawString("Score " + miScore, mcFontText, cBrush, 10, 10);

            // Display the instructions
            cBackBuffer.DrawString("Try and hit as many ducks as possible", mcFontText, cBrush, 190, 10);

            // If the Song is still loading
            if (mcWindowsMediaPlayer.status == "Connecting...")
            {
                cBackBuffer.DrawString("Loading Tune", mcFontChooseMusicTitle, cBrush, 230, 200);
            }

            // Clean up the Brush and Pen resources
            cBrush.Dispose();
            cPen.Dispose();
        }