Beispiel #1
0
        FMOD.Sound msSoundSelectionChanged; // Sound to play when the Menu Selection is changed

        // Class constructor
        public CMainMenu()
        {
            try
            {
                // Pre-load the images
                mcBackgroundImage      = Image.FromFile("../../Data/Images/MainMenuBackground.png");
                mcPongImage            = Image.FromFile("../../Data/Images/MainMenuPong.png");
                mcShootingGalleryImage = Image.FromFile("../../Data/Images/MainMenuShootingGallery.png");
                mcPitchMatcherImage    = Image.FromFile("../../Data/Images/MainMenuPitchMatcher.png");
                mcTargetPracticeImage  = Image.FromFile("../../Data/Images/MainMenuTargetPractice.png");
                mcProfileSettingsImage = Image.FromFile("../../Data/Images/MainMenuProfileSettings.png");
                mcHighScoresImage      = Image.FromFile("../../Data/Images/MainMenuHighScores.png");

                // Pre-load the sounds
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/MenuSelectionChanged.wav", FMOD.MODE.DEFAULT, ref msSoundSelectionChanged), "FMOD Create Sound Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught");
            }

            // Setup the Font to use to display the current Profile
            mcFontText = new Font("Arial", 14, FontStyle.Regular);

            // Set the clickable area to toggle the Sound on/off
            mrToggleSoundArea = new Rectangle(640, 530, 160, 50);

            // Setup default variable values
            Reset();
        }
Beispiel #2
0
        // If a Keyboard Key is pressed
        public override EGames KeyDown(KeyEventArgs e)
        {
            // Game to load
            EGames eGameToPlay = meGame;

            // If the player is switching the selection
            if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up)
            {
                // Switch selection to previous game
                meSelectedGame--;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Wrap around if necessary
                if (meSelectedGame == EGames.MainMenu)
                {
                    meSelectedGame = EGames.HighScores;
                }

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            else if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Down)
            {
                // Switch selection to next game
                meSelectedGame++;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Wrap around if necessary
                if (meSelectedGame > EGames.HighScores)
                {
                    meSelectedGame = EGames.Spong;
                }

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }

            // If the player has chosen the Game to play
            if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
            {
                eGameToPlay = meSelectedGame;
            }

            // If the player is toggling the Sound on/off
            if (e.KeyCode == Keys.S)
            {
                // Toggle the Sound on/off
                CFMOD.mbSoundOn = !CFMOD.mbSoundOn;
            }

            // Return which Game should be played now
            return(eGameToPlay);
        }
Beispiel #3
0
        // Function to Play a FMOD Sound
        static public FMOD.Channel PlaySound(FMOD.Sound sFMODSound, bool bForcePlaySound)
        {
            // Dummy Channel Handle
            FMOD.Channel sFMODChannelHandle = new FMOD.Channel();

            // If Sounds should be played
            if (mbSoundOn || bForcePlaySound)
            {
                // Play Sound
                CFMOD.CheckResult(CFMOD.GetSystem().playSound(FMOD.CHANNELINDEX.FREE, sFMODSound, false, ref sFMODChannelHandle), "FMOD Play Sound Error");
            }

            // Return the Channel the sound is playing on
            return(sFMODChannelHandle);
        }
Beispiel #4
0
        // Class constructor
        public CSpong()
        {
            try
            {
                // Pre-load images
                mcPaddleImage = Image.FromFile("../../Data/Images/SpongPaddle.png");
                mcBallImage   = Image.FromFile("../../Data/Images/SpongBall.png");

                // Pre-load sounds
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/SpongBallBounce.wav", FMOD.MODE.DEFAULT, ref msSoundBallBounce), "FMOD Create Sound Error");
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/SpongBallDied.wav", FMOD.MODE.DEFAULT, ref msSoundBallDied), "FMOD Create Sound Error");
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/SpongGameOver.wav", FMOD.MODE.DEFAULT, ref msSoundGameOver), "FMOD Create Sound Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught");
            }

            // Seed the Random number generator
            mcRandom = new Random(Environment.TickCount);

            // Mouse turned off by default
            mbMouseEnabled    = false;
            miMouseYLastFrame = 0;

            // Setup the Walls
            mrLeftWall   = new Rectangle(60, 50, 10, 460);
            mrRightWall  = new Rectangle(770, 50, 10, 460);
            mrTopWall    = new Rectangle(60, 50, 720, 10);
            mrBottomWall = new Rectangle(60, 500, 720, 10);

            // Setup the Pitch Meter
            mcPitchMeter = new CPitchMeter(26, 125);
            mcPitchMeter.ShowHalfPointMarker(true);

            // Setup the Fonts
            mcFontText  = new Font("Arial", 20, FontStyle.Regular);
            mcFontPause = new Font("Arial", 50, FontStyle.Regular);

            // Set the other variables default values
            Reset();
        }
Beispiel #5
0
        // Function to Fire the Arrow
        private void FireArrow()
        {
            // If the Player is currently Aiming
            if (meTargetPracticeState == ETargetPracticeGameStates.Aiming)
            {
                // Switch to Shooting the Arrow
                meTargetPracticeState = ETargetPracticeGameStates.FiredArrow;

                // Set the Arrows Velocity based on the current Pitch and Amplitude of the Players voice

                // Find the Middle Point of the Bow And Arrow to Rotate around
                PointF sMiddlePoint = new Point();
                sMiddlePoint.X = mrBOW_AND_ARROW_POSITION.X + (mrBOW_AND_ARROW_POSITION.Width / 2.0f);
                sMiddlePoint.Y = mrBOW_AND_ARROW_POSITION.Y + (mrBOW_AND_ARROW_POSITION.Height / 2.0f);

                // Rotate the Bow And Arrow by the specified Bow And Arrow Rotation Amount
                System.Drawing.Drawing2D.Matrix sRotationMatrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0);
                sRotationMatrix.RotateAt(miBowAndArrowRotation, sMiddlePoint);
                PointF[] sPoint = new PointF[1];
                sPoint[0].X = sMiddlePoint.X + 1;
                sPoint[0].Y = sMiddlePoint.Y;
                sRotationMatrix.TransformPoints(sPoint);

                // Set the Arrows initial Direction to travel
                mcArrowVelocity.X = sPoint[0].X - sMiddlePoint.X;
                mcArrowVelocity.Y = sPoint[0].Y - sMiddlePoint.Y;
                mcArrowVelocity.Normalize();

                // Set the Arrows initial speed
                mcArrowVelocity   *= (mfUnitBowAndArrowPower * 300.0f);
                mcArrowVelocity.X += 100.0f;

                // Set the Arrows Rotation to be the same as the Bow And Arrow initially
                miArrowRotation = miBowAndArrowRotation;

                // Play the Fire Arrow sound
                CFMOD.PlaySound(msSoundFire, false);
            }
        }
        // Form Constructor
        public formProfileSettings()
        {
            // Initializes form controls
            InitializeComponent();

            try
            {
                // Pre-load images

                // Pre-load Sounds
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/ProfileSettingsExample.wav", FMOD.MODE.DEFAULT, ref msSoundPitchTransitionExample), "FMOD Create Sound Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught");
            }

            // Setup the Update Timer
            mcUpdateTimer          = new Timer();
            mcUpdateTimer.Tick    += new EventHandler(UpdateTimer_Tick);
            mcUpdateTimer.Interval = 16;
            mcUpdateTimer.Enabled  = true;
            mcUpdateTimer.Start();

            // Set all of the Pitch Hits to zero
            for (int i = 0; i < miaPitchHits.Length; i++)
            {
                miaPitchHits[i] = 0;
            }

            // Display the Profiles in the Profiles combo box
            UpdateShownProfilesAndCurrentSettings();

            // Set the initial Pitch Meter Indicators position
            mcPitchMeter = new CPitchMeter(350, 125);
            mcPitchMeter.ShowHalfPointMarker(true);
        }
Beispiel #7
0
        // If the Mouse is moved
        public override void MouseMove(MouseEventArgs e)
        {
            // Get Mouses Position and store it as a rectangle
            Rectangle rMouse = new Rectangle(e.X, e.Y, 1, 1);

            // If the Mouse is over the Pong game icon
            if (mrPongIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.Spong)
            {
                // Set Pong as the Selected game
                meSelectedGame = EGames.Spong;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            // Else if the Mouse is over the Shooting Gallery game icon
            else if (mrShootingGalleryIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.ShootingGallery)
            {
                // Set Shooting Gallery as the Selected game
                meSelectedGame = EGames.ShootingGallery;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            // Else if the Mouse is over the Pitch Matcher game icon
            else if (mrPitchMatcherIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.PitchMatcher)
            {
                // Set Pitch Matcher as the Selected game
                meSelectedGame = EGames.PitchMatcher;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            // Else if the Mouse is over the Target Practice game icon
            else if (mrTargetPracticeIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.TargetPractice)
            {
                // Set Target Practice as the Selected game
                meSelectedGame = EGames.TargetPractice;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            // Else if the Mouse is over the Profile Settings icon
            else if (mrProfileSettingsIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.ProfileSettings)
            {
                // Set the Profile Settings as the Selected icon
                meSelectedGame = EGames.ProfileSettings;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
            // Else if the Mouse is over the High Scores icon
            else if (mrHighScoresIcon.IntersectsWith(rMouse) && meSelectedGame != EGames.HighScores)
            {
                // Set High Scores as the Selected game
                meSelectedGame = EGames.HighScores;

                // Reset the Game Scale
                mfSelectedGameScale = 0.0f;

                // Play Menu Selection Changed sound
                CFMOD.PlaySound(msSoundSelectionChanged, false);
            }
        }
Beispiel #8
0
        FMOD.Sound msSoundFire = null;      // Sound when the player Fires the Arrow

        // Class constructor
        public CTargetPractice()
        {
            try
            {
                // Pre-load images
                mcBowAndArrowImage = Image.FromFile("../../Data/Images/TargetPracticeBowAndArrow.png");
                mcArrowImage       = Image.FromFile("../../Data/Images/TargetPracticeArrow.png");
                mcTargetImage      = Image.FromFile("../../Data/Images/TargetPracticeTarget.png");

                // Pre-load sounds
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/TargetPracticeHit.wav", FMOD.MODE.DEFAULT, ref msSoundHit), "FMOD Create Sound Error");
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/TargetPracticeMiss.wav", FMOD.MODE.DEFAULT, ref msSoundMiss), "FMOD Create Sound Error");
                CFMOD.CheckResult(CFMOD.GetSystem().createSound("../../Data/Sounds/TargetPracticeFire.wav", FMOD.MODE.DEFAULT, ref msSoundFire), "FMOD Create Sound Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception caught");
            }

            // Seed the Random number generator
            mcRandom = new Random(Environment.TickCount);

            // Setup the Pitch Meter
            mcPitchMeter = new CPitchMeter(500, 125);
            mcPitchMeter.ShowFourthsMarkers(true);

            // Setup the Fonts
            mcFontText  = new Font("Arial", 20, FontStyle.Regular);
            mcFontLarge = new Font("Arial", 50, FontStyle.Regular);

            // Start the player with no Score
            miScore = 0;

            // Record that we are playing Pong
            meGame = EGames.TargetPractice;

            // Set the games initial State
            meTargetPracticeState = ETargetPracticeGameStates.Aiming;

            // Set the initial Pitch Meter Indicator positions
            mcPitchMeter.UpdatePitchIndicatorsPosition(0.0f);

            // Initialize the constants
            mcGRAVITY_ACCELERATION   = new Vector2(0.0f, 65.0f);
            mrBOW_AND_ARROW_POSITION = new Rectangle(10, 400, 60, 69);

            // Specify the initial Target and Arrow positions
            mrTarget = new Rectangle(650, 250, 128, 128);
            mrArrow  = new RectangleF(10, 10, 60, 11);
            MoveTargetToNewRandomLocation();
            MoveArrowToBow();

            // Set the Arrows initial Velocity and the initial Power
            mcArrowVelocity        = new Vector2();
            mfUnitBowAndArrowPower = 0.0f;

            // Set the initial Bow And Arrow and Arrow Rotations
            miBowAndArrowRotation = miArrowRotation = 0;

            // Initialize the Reset Arrow Wait Time
            mfResetArrowWaitTime = 0.0f;

            // Initialize the Arrow Hit Target variable
            mbArrowHitTarget = false;
        }
Beispiel #9
0
        // Update the Bow And Arrow and the Arrow
        private void UpdateGameObjects(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // If the Player is Aiming
            if (meTargetPracticeState == ETargetPracticeGameStates.Aiming)
            {
                // Use the Players current Pitch as the Bow And Arrow Rotation Amount
                mcPitchMeter.AutoDetectPitchAndUpdateMeter();
                miBowAndArrowRotation = (int)(mcPitchMeter.mfPitchIndicatorUnitPosition * -45.0f);

                // Save the amount of Power being used
                mfUnitBowAndArrowPower = ((CSoundInput.Instance().fAmplitude - 90.0f) / 20.0f);

                // Make sure the Power is in a valid range of Zero to One
                if (mfUnitBowAndArrowPower < 0.0f)
                {
                    mfUnitBowAndArrowPower = 0.0f;
                }
                else if (mfUnitBowAndArrowPower > 1.0f)
                {
                    mfUnitBowAndArrowPower = 1.0f;
                }
            }
            // Else the Arrow has been fired
            else
            {
                // If the Arrow is not "dead" yet
                if (mfResetArrowWaitTime <= 0.0f)
                {
                    // Update the Arrows Velocity by Gravity
                    mcArrowVelocity += (mcGRAVITY_ACCELERATION * fTimeSinceLastUpdateInSeconds);

                    // Calculate the Arrows new Position
                    mrArrow.X += (mcArrowVelocity.X * fTimeSinceLastUpdateInSeconds);
                    mrArrow.Y += (mcArrowVelocity.Y * fTimeSinceLastUpdateInSeconds);

                    // Get the Rotation angle of the Arrow so that it faces the direction it is travelling
                    float fArrowRotationInRadians = 0.0f;
                    bool  bChangeRotation         = true;
                    if (mcArrowVelocity.Y < 0.0f)
                    {
                        fArrowRotationInRadians = (float)(Math.PI + Math.Atan(mcArrowVelocity.X / mcArrowVelocity.Y));
                    }
                    else if (mcArrowVelocity.Y > 0.0f)
                    {
                        fArrowRotationInRadians = (float)(Math.Atan(mcArrowVelocity.X / mcArrowVelocity.Y));
                    }
                    // Else the Arrow has no Y Velocity
                    else
                    {
                        if (mcArrowVelocity.X > 0.0f)
                        {
                            fArrowRotationInRadians = (float)(Math.PI / 2.0f);
                        }
                        else if (mcArrowVelocity.X < 0.0f)
                        {
                            fArrowRotationInRadians = (float)((3.0f * Math.PI) / 2.0f);
                        }
                        // Else the Arrow has no X Velocity
                        else
                        {
                            // Rotation is undefined, so leave rotationa as is
                            bChangeRotation = false;
                        }
                    }

                    // If the Rotation should be updated
                    if (bChangeRotation)
                    {
                        // Convert the Radians to Degrees and store the result
                        miArrowRotation = 90 - (int)(fArrowRotationInRadians * (180.0f / Math.PI));
                    }
                }

                // If the Arrow should be reset
                if (mrArrow.IntersectsWith(mrTarget) || mrArrow.X > 800 || mrArrow.Y > 485)
                {
                    // If the Arrow just "died"
                    if (mfResetArrowWaitTime == 0.0f)
                    {
                        // If the Arrow hit the Target
                        if (mrArrow.IntersectsWith(mrTarget))
                        {
                            // Record it as a hit
                            mbArrowHitTarget = true;

                            // Update the Players Score
                            miScore++;

                            // If the Players Score is more than their current High Score
                            if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreTargetPractice)
                            {
                                // Update the Players High Score and Save
                                CProfiles.Instance().mcCurrentProfile.iScoreTargetPractice = miScore;
                                CProfiles.Instance().SaveProfilesToFile();
                            }

                            // Play the Hit sound
                            CFMOD.PlaySound(msSoundHit, false);
                        }
                        // Else if the Arrow did not hit anything
                        else if (mrArrow.X > 800 || mrArrow.Y > 485)
                        {
                            // Record that it was not a hit
                            mbArrowHitTarget = false;

                            // Reset the Players Score
                            miScore = 0;

                            // Play the Miss sound
                            CFMOD.PlaySound(msSoundMiss, false);
                        }

                        // Reset the Arrows Velocity to zero
                        mcArrowVelocity *= 0.0f;
                    }

                    // Update how long we have waited for
                    mfResetArrowWaitTime += fTimeSinceLastUpdateInSeconds;

                    // If we have waited long enough since the Arrow "died"
                    if (mfResetArrowWaitTime > 1.0f)
                    {
                        // Reset the Arrows Position
                        MoveArrowToBow();

                        // If the Arrow hit the Target
                        if (mbArrowHitTarget)
                        {
                            // Create a new Target to hit
                            MoveTargetToNewRandomLocation();
                        }

                        // Reset the Arrow Wait Time
                        mfResetArrowWaitTime = 0.0f;

                        // Change the Game State to Aiming
                        meTargetPracticeState = ETargetPracticeGameStates.Aiming;
                    }
                }
            }
        }
 // If the Pitch Transition Example button was pressed
 private void buttonPitchTransitionExample_Click(object sender, EventArgs e)
 {
     // Play the Pitch Transition Example sound
     CFMOD.PlaySound(msSoundPitchTransitionExample, true);
 }
Beispiel #11
0
        // Update the Ball and Paddle
        private void UpdateGameObjects(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // Temp local variables
            int       iBallXDistanceTravelled = 0;      // How far the Ball has moved in the X direction
            int       iBallYDistanceTravelled = 0;      // How far the Ball has moved in the Y direction
            Rectangle rBallOldPosition        = mrBall; // Rectangle used to test Ball against collisions
            Rectangle rBallCollisionRect;               // Rectangle used to test Ball against collisions

            // Move the Pitch Meter according to any Input Pitch
            mcPitchMeter.AutoDetectPitchAndUpdateMeter();

            // If some Pitch Input was received
            if (CSoundInput.Instance().bInputReceived)
            {
                // Calculate what Percent of force should be used to move the Paddle
                float fPercentToMove = mcPitchMeter.mfPitchIndicatorUnitPosition - 0.5f;
                fPercentToMove *= 2.0f;

                // Calculate how many pixels to move the Paddle
                float fAmountToMove = fPercentToMove * (-miPADDLE_MAX_SPEED_PER_SECOND * fTimeSinceLastUpdateInSeconds);

                // Move the Paddle
                mrPaddle.Y += (int)fAmountToMove;
            }

            // Calculate how far the Ball should move
            iBallXDistanceTravelled = (int)(mcBallDirection.X * fTimeSinceLastUpdateInSeconds);
            iBallYDistanceTravelled = (int)(mcBallDirection.Y * fTimeSinceLastUpdateInSeconds);

            // Move the Ball
            mrBall.X += iBallXDistanceTravelled;
            mrBall.Y += iBallYDistanceTravelled;

            // Test for collision between the Ball and the Walls

            // Rectangle to use to test collisions against the Ball
            rBallCollisionRect = mrBall;

            // If the Ball has travelled further than it's width or height in the last frame
            if (Math.Abs(iBallXDistanceTravelled) >= mrBall.Width ||
                Math.Abs(iBallYDistanceTravelled) >= mrBall.Height)
            {
                // If the Ball is moving right
                if (iBallXDistanceTravelled > 0)
                {
                    // If the Ball is moving down
                    if (iBallYDistanceTravelled > 0)
                    {
                        rBallCollisionRect.Location = rBallOldPosition.Location;
                        rBallCollisionRect.Width    = mrBall.Right - rBallOldPosition.Left;
                        rBallCollisionRect.Height   = mrBall.Bottom - rBallOldPosition.Top;
                    }
                    // Else the Ball is moving up
                    else
                    {
                        rBallCollisionRect.X      = rBallOldPosition.X;
                        rBallCollisionRect.Y      = mrBall.Top;
                        rBallCollisionRect.Width  = mrBall.Right - rBallOldPosition.Left;
                        rBallCollisionRect.Height = rBallOldPosition.Bottom - mrBall.Top;
                    }
                }
                // Else the Ball is moving left
                else
                {
                    // If the Ball is moving down
                    if (iBallYDistanceTravelled > 0)
                    {
                        rBallCollisionRect.X      = mrBall.Left;
                        rBallCollisionRect.Y      = rBallOldPosition.Top;
                        rBallCollisionRect.Width  = rBallOldPosition.Right - mrBall.Left;
                        rBallCollisionRect.Height = mrBall.Bottom - rBallOldPosition.Top;
                    }
                    // Else the Ball is moving up
                    else
                    {
                        rBallCollisionRect.Location = mrBall.Location;
                        rBallCollisionRect.Width    = rBallOldPosition.Right - mrBall.Left;
                        rBallCollisionRect.Height   = rBallOldPosition.Bottom - mrBall.Top;
                    }
                }
            }

            // If the Ball hit the Top Wall
            if (rBallCollisionRect.IntersectsWith(mrTopWall))
            {
                // Reverse it's Y direction
                mcBallDirection.Y = -mcBallDirection.Y;

                // Place it to be hitting the Wall (not in the Wall)
                mrBall.Y = mrTopWall.Bottom;

                // Play Sound
                CFMOD.PlaySound(msSoundBallBounce, false);
            }
            // If the Ball hit the Bottom Wall
            else if (rBallCollisionRect.IntersectsWith(mrBottomWall))
            {
                // Reverse it's Y direction
                mcBallDirection.Y = -mcBallDirection.Y;

                // Place it to be hitting the Wall (not in the Wall)
                mrBall.Y = mrBottomWall.Top - mrBall.Height;

                // Play Sound
                CFMOD.PlaySound(msSoundBallBounce, false);
            }

            // If the Ball hit the Right wall
            if (rBallCollisionRect.IntersectsWith(mrRightWall))
            {
                // Reverse it's X direction
                mcBallDirection.X = -mcBallDirection.X;

                // Place it to be hitting the Wall (not in the Wall)
                mrBall.X = mrRightWall.Left - mrBall.Width;

                // Play Sound
                CFMOD.PlaySound(msSoundBallBounce, false);
            }

            // Test for collision between the Ball and the Paddle
            // NOTE: Test for collision between Paddle before left wall incase ball is
            //       travelling too fast and would pass through both
            if (rBallCollisionRect.IntersectsWith(mrPaddle))
            {
                // Increase the Balls speed slightly
                float fSpeed = mcBallDirection.Length();
                fSpeed += miBALL_SPEED_INCREMENT;

                // Make sure Ball does not go too fast
                if (fSpeed > miBALL_MAX_SPEED)
                {
                    fSpeed = miBALL_MAX_SPEED;
                }

                // Reverse the Balls X direction
                mcBallDirection.X = -mcBallDirection.X;

                // Add some randomness to the Balls Y direction
                float fRandomness = mcRandom.Next(-25, 25);
                fRandomness /= 100.0f;
                mcBallDirection.Normalize();
                mcBallDirection.Y += fRandomness;

                // Set the Balls speed
                mcBallDirection.Normalize();
                mcBallDirection.Scale(fSpeed);

                // Place the Ball on the Paddle (not inside it)
                mrBall.X = mrPaddle.Right;

                // Play Sound
                CFMOD.PlaySound(msSoundBallBounce, false);
            }
            // Else if the Ball hit the Left wall
            else if (rBallCollisionRect.IntersectsWith(mrLeftWall))
            {
                // Player loses a life
                miLives--;

                // If the Player is dead
                if (miLives == 0)
                {
                    // Save the Players Score
                    int iScore = miScore;

                    // Restart the Game
                    Reset();

                    // Restore the Players Score
                    miScore = iScore;

                    // Play Game Over sound
                    CFMOD.PlaySound(msSoundGameOver, false);

                    // Check if the Player has beat their High Score
                    if (CProfiles.Instance().mcCurrentProfile.iScoreSpong < miScore)
                    {
                        // Save the Players new High Score
                        CProfiles.Instance().mcCurrentProfile.iScoreSpong = miScore;
                        CProfiles.Instance().SaveProfilesToFile();
                    }

                    // Exit this function so the Game restarts now
                    return;
                }

                // Play sound of losing a Ball
                CFMOD.PlaySound(msSoundBallDied, false);

                // Reset the Balls position and direction
                ResetBall();

                // Reset the Next Ball Wait Timer
                mfNextBallWaitTime = 0.0f;

                // Enter the Wait For Next Ball state
                mePongState = EPongGameStates.WaitForNextBall;
            }

            // Update the Players Score
            miScore += (int)(fTimeSinceLastUpdateInSeconds * 1000.0f);
        }
Beispiel #12
0
        // Update Game Information
        void UpdateGame()
        {
            // Calculate how many milliseconds have passed since the last Update
            int iElapsedTime = (int)mcUpdateStopwatch.ElapsedMilliseconds;

            mcUpdateStopwatch.Reset();
            mcUpdateStopwatch.Start();

            // If we should switch Games
            if (msTransition.bSwitchGamesNow)
            {
                // Mark that the Game has been Switched
                msTransition.bSwitchGamesNow = false;

                // Switch Games
                PlayGame(msTransition.eGameToSwitchTo);
            }

            // If we should calculate the FPS
            if (mbShowFPS)
            {
                // Update the Time and Frame count
                miFPSTime += iElapsedTime;
                miFPSFrames++;

                // If a second has passed
                if (miFPSTime > 1000)
                {
                    // Subtract a second from the FPS Time
                    miFPSTime -= 1000;

                    // Record the FPS for the last second and reset the FPS counter
                    miFPS       = miFPSFrames;
                    miFPSFrames = 0;
                }
            }

            // Get input from PD (audio input from player)
            CSoundInput.Instance().GetPDInput(true);

            // Get midi input from PD
            CMidiInput.Instance().GetPDInput();

            // Calculate how much time has passed in seconds since the last Update
            float fElapsedTimeInSeconds = iElapsedTime / 1000.0f;

            // Update the Game
            mcGame.Update(fElapsedTimeInSeconds, mcBackBuffer);

            // If we are in a screen Transition
            if (msTransition.bPerfromingTransition)
            {
                float fProgress = 0.0f;

                // Calculate the Elapsed Time
                msTransition.iElapsedTime += iElapsedTime;

                // If the Transition should happen instantly
                if (msTransition.iDurationInMilliseconds == 0)
                {
                    // Record that we should be at the end of the fade in/out
                    fProgress = 1.0f;
                }
                else
                {
                    // Calculate how far into the Transition we are
                    fProgress = (float)msTransition.iElapsedTime / (float)msTransition.iDurationInMilliseconds;
                    if (fProgress > 1.0f)
                    {
                        fProgress = 1.0f;
                    }
                    else if (fProgress == 0.0f)
                    {
                        fProgress = 0.0001f;
                    }
                }

                // If we are now fading back in
                if (msTransition.bFadeOutComplete)
                {
                    // Bug Workaround - If we are not in the Profile Settings
                    if (mcGame.meGame != EGames.ProfileSettings)
                    {
                        // Reverse the progress so that we fade in instead of out
                        fProgress = 1.0f - fProgress;
                    }
                }

                // Calculate the Transparency to use
                int iOpacity = (int)(fProgress * (msTransition.fEndOpacity * 255.0f));

                // Draw the Transition
                Brush cBrush = new SolidBrush(Color.FromArgb(iOpacity, msTransition.sColor));
                mcBackBuffer.FillRectangle(cBrush, 0, 0, mcBackBufferImage.Width, mcBackBufferImage.Height);
                cBrush.Dispose();

                // If we have faded out all the way
                if (fProgress == 1.0f)
                {
                    // Mark that we have faded out all the way
                    msTransition.bFadeOutComplete = true;

                    // Reset the Elapsed time
                    msTransition.iElapsedTime = 0;

                    // Mark that we should Switch Games Now
                    msTransition.bSwitchGamesNow = true;
                }
                // Else if we haved faded in all the way
                else if (fProgress == 0.0f)
                {
                    // Stop doing the Transition
                    msTransition.Reset();
                }
            }

            // If the FPS should be shown
            if (mbShowFPS)
            {
                // Display the FPS
                Brush cBrush = new SolidBrush(Color.WhiteSmoke);
                mcBackBuffer.DrawString("FPS: " + miFPS.ToString(), mcFontFPS, cBrush, 1, 550);
                cBrush.Dispose();
            }

            // Update FMOD
            CFMOD.CheckResult(CFMOD.GetSystem().update(), "FMOD Update Error");

            // Update the Display by invalidating the Form
            this.Invalidate();
        }