Ejemplo n.º 1
0
        // Get Midi input from PD
        public void GetPDInput()
        {
            // Clear any previous Midi input
            CMidiInput.Instance().cMidiInfoList.Clear();

            try
            {
                // Get any PD messages that might have been sent
                Ventuz.OSC.OscBundle cOSCBundle = mcUDPReader.ReceiveBundle();

                // If there are no messages to retrieve
                if (cOSCBundle == null || cOSCBundle.Elements == null || cOSCBundle.Elements.Count <= 0)
                {
                    // Exit the function
                    return;
                }

                // Read in and Store all of the OSC Bundles contents
                while (cOSCBundle != null)
                {
                    // Read in and Store the Contents of the OSC Bundle
                    ReadAndStoreOSCBundleContents(cOSCBundle);

                    // Get the next OSC Bundle from the queue
                    cOSCBundle = mcUDPReader.ReceiveBundle();
                }
            }
            // Catch all exceptions
            catch (Exception e)
            {
                // Display the error message
                MessageBox.Show(e.ToString(), "ERROR");
            }
        }
Ejemplo n.º 2
0
        // Return the singleton Instance of this class
        public static CMidiInput Instance()
        {
            // Lock the Instance so only one thread can use it at a time
            lock (Lock)
            {
                // If this class Instance hasn't been created yet
                if (mcInstance == null)
                {
                    // Create the Instance
                    mcInstance = new CMidiInput();
                }

                return(mcInstance);
            }
        }
Ejemplo n.º 3
0
        // Function to Update all of the Game Objects
        private void UpdateGameObjects(float fTimeSinceLastUpdateInSeconds, Graphics cBackBuffer)
        {
            // Loop through Midi Data and create new Targets if necessary
            int iMidiIndex         = 0;
            int iNumberOfMidiNotes = CMidiInput.Instance().cMidiInfoList.Count;

            for (iMidiIndex = 0; iMidiIndex < iNumberOfMidiNotes; iMidiIndex++)
            {
                // Create a handle to the current Midi Info for readability
                CMidiInfo cMidiInfo = CMidiInput.Instance().cMidiInfoList[iMidiIndex];

                // Filter Midi Notes based on which Music is playing
                // If this Midi Note is not on the Channel we want
                if (cMidiInfo.iChannel != mcCurrentMusic.iChannelToUse && cMidiInfo.iChannel > 0)
                {
                    // Move to the next Midi Note (only keep Notes on the desired Channel)
                    continue;
                }

                // Create a new Target
                CTarget cNewTarget = new CTarget();

                // Specify Target Width and Height
                cNewTarget.rRect.Width  = 70;
                cNewTarget.rRect.Height = 80;

                // Determine which Row the Target should be in
                // If it should be in the bottom Row
                if (cMidiInfo.iNote < mcCurrentMusic.iLowPitchCeiling)
                {
                    cNewTarget.rRect.Y = miBOTTOM_ROW_Y;
                }
                // Else if it should be in the middle Row
                else if (cMidiInfo.iNote < mcCurrentMusic.iMiddlePitchCeiling)
                {
                    cNewTarget.rRect.Y = miMIDDLE_ROW_Y;
                }
                // Else it should be in the top Row
                else
                {
                    cNewTarget.rRect.Y = miTOP_ROW_Y;
                }

                // Calculate the Targets velocity based on the Midi Note's Velocity
                cNewTarget.sVelocity.X = cMidiInfo.iVelocity + 140;
                cNewTarget.sVelocity.Y = 0.0f;

                // 50/50 chance of Target approaching from left/right side
                bool bApproachFromRight = (mcRandom.Next(0, 2) == 0) ? true : false;
                bApproachFromRight = false;

                // If this Target is approaching from the Right
                if (bApproachFromRight)
                {
                    // Reverse it's X Velocity
                    cNewTarget.sVelocity.X = -cNewTarget.sVelocity.X;

                    // Record that it should be Facing Left
                    cNewTarget.bFacingLeft = true;
                }

                // Save the Targets Starting Velocity
                cNewTarget.sStartingVelocity = cNewTarget.sVelocity;

                // Calculate the Time when the Target should reach the center of the screen
                cNewTarget.cTimeToBeAtCenter = cMidiInfo.cTime.AddSeconds(3.0);

                // Calculate how long between the current Time and the time the target
                // should be in the middle of the screen
                TimeSpan cTimeSpanToReachCenter = cNewTarget.cTimeToBeAtCenter - DateTime.Now;
                float    fTimeToReachCenter     = (float)(cTimeSpanToReachCenter.TotalMilliseconds / 1000.0f);

                // Calculate where it should be placed to reach the middle of the screen at the desired time
                cNewTarget.rRect.X = (int)(miCENTER_OF_SCREEN_X - (cNewTarget.sVelocity.X * fTimeToReachCenter)) + (cNewTarget.rRect.Width / 2.0f);

                // Add the new Target to the Target List
                mcTargetList.Add(cNewTarget);
            }

            // Temp variable to keep track of which Row the Players Pitch is in
            ETargetRows ePlayersPitchRow;

            // If the Player is making a sound
            if (CSoundInput.Instance().bInputReceived)
            {
                // If the Song is not still loading
                if (mcWindowsMediaPlayer.status != "Connecting...")
                {
                    // Duduct from their Score (so they don't make sounds the whole time)
                    miScore--;
                }

                // Save which Row their Pitch corresponds to
                // If the Pitch corresponds to the Bottom Row
                if (CSoundInput.Instance().fPitch < CSoundInput.Instance().iOneThirdOfPitchRange)
                {
                    ePlayersPitchRow = ETargetRows.Bottom;
                }
                // Else if the Pitch corresponds to the Middle Row
                else if (CSoundInput.Instance().fPitch < CSoundInput.Instance().iTwoThirdsOfPitchRange)
                {
                    ePlayersPitchRow = ETargetRows.Middle;
                }
                // Else the Pitch corresponds to the Top Row
                else
                {
                    ePlayersPitchRow = ETargetRows.Top;
                }
            }
            // Else no input was recieved
            else
            {
                ePlayersPitchRow = ETargetRows.None;
            }

            // 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];

                // Make sure the Targets Velocity will still put them at the
                // center of the screen at the correct time

                // If this target has not passed the middle of the screen yet
                if (cTarget.cTimeToBeAtCenter > DateTime.Now)
                {
                    // Calculate how long between the current Time and the time the target
                    // should be in the middle of the screen
                    TimeSpan cTimeSpanToReachCenter = cTarget.cTimeToBeAtCenter - DateTime.Now;
                    float    fTimeToReachCenter     = (float)(cTimeSpanToReachCenter.TotalMilliseconds / 1000.0f);

                    // Calculate the Distance this Target is from the Center of the screen
                    float fDistanceToCenter = miCENTER_OF_SCREEN_X - (cTarget.rRect.X + (cTarget.rRect.Width / 2.0f));

                    // Calculate where it should be placed to reach the middle of the screen at the desired time
                    cTarget.sVelocity.X = fDistanceToCenter / fTimeToReachCenter;

                    // If the Velocity should be negative and it isn't, or it should be positive and it isn't
                    if ((cTarget.sStartingVelocity.X < 0.0f && cTarget.sVelocity.X > 0.0f) ||
                        (cTarget.sStartingVelocity.X > 0.0f && cTarget.sVelocity.X < 0.0f))
                    {
                        // Make the Velocity
                        cTarget.sVelocity.X *= -1;
                    }
                }
                // Else it has passed the middle of the screen
                else
                {
                    // So make sure it is using it's original velocity
                    cTarget.sVelocity = cTarget.sStartingVelocity;
                }

                // Update the Position of this Target
                cTarget.rRect.X += (cTarget.sVelocity.X * fTimeSinceLastUpdateInSeconds);
                cTarget.rRect.Y += (cTarget.sVelocity.Y * fTimeSinceLastUpdateInSeconds);

                // Store which Row this Target is in
                ETargetRows eTargetRow;

                // If the Target is in the Top Row
                if (cTarget.rRect.Y == miTOP_ROW_Y)
                {
                    eTargetRow = ETargetRows.Top;
                }
                // Else if the Target is in the Middle Row
                else if (cTarget.rRect.Y == miMIDDLE_ROW_Y)
                {
                    eTargetRow = ETargetRows.Middle;
                }
                // Else the Target is in the Bottom Row
                else
                {
                    eTargetRow = ETargetRows.Bottom;
                }

                // Calculate the middle position of the Target
                float fMiddlePosition = cTarget.rRect.X + (cTarget.rRect.Width / 2.0f);

                // If the Player is making a Pitch correspond to the Row this Target is in
                // AND the Target is in the shooting area
                if (ePlayersPitchRow == eTargetRow &&
                    fMiddlePosition >= miSHOOT_TARGET_AREA_LEFT && fMiddlePosition <= miSHOOT_TARGET_AREA_RIGHT)
                {
                    // Give the Player some Points for hitting this Target
                    miScore += 25;

                    // Kill this Target by moving it off the screen
                    cTarget.rRect.X += (cTarget.sVelocity.X * 10.0f);
                }
            }

            // Remove all Targets from the List which have moved off the screen
            mcTargetList.RemoveAll(delegate(CTarget cTarget)
            {
                // Return if the Target has moved off the screen or not yet
                return((cTarget.sVelocity.X > 0.0f && cTarget.rRect.X > 800) ||
                       (cTarget.sVelocity.X < 0.0f && (cTarget.rRect.X + cTarget.rRect.Width) < 0));
            });

            // If the Song is finished playing
            if (mcWindowsMediaPlayer.status == "Stopped")
            {
                // Sum the amount of time passed since the song finished playing
                mfSecondsSongHasBeenCompleteFor += fTimeSinceLastUpdateInSeconds;

                // If the Song has been finished for 7 seconds
                if (mfSecondsSongHasBeenCompleteFor >= 7.0f)
                {
                    // Check which Song is being played
                    switch (mcCurrentMusic.eMusic)
                    {
                    default:
                    case EMusic.Simple:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong1)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong1 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;

                    case EMusic.DansMario:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong2)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong2 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;

                    case EMusic.Mario:
                        // Save the Players Score if it's better than their old one
                        if (miScore > CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong3)
                        {
                            // Save the Players new High Score
                            CProfiles.Instance().mcCurrentProfile.iScoreShootingGallerySong3 = miScore;
                            CProfiles.Instance().SaveProfilesToFile();
                        }
                        break;
                    }

                    // Restart the game
                    Reset();
                }
            }
        }
Ejemplo n.º 4
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();
        }