// Function to Read and Store the OSC Bundles Contents private void ReadAndStoreOSCBundleContents(Ventuz.OSC.OscBundle cOSCBundle) { string sInfo = ""; // Temp variable to display read in values CMidiInfo cMidiInfo = new CMidiInfo(); // Temp variable to hold the read in Midi Info // Initialize the variables used to hold the Notes Time int iHour = 0, iMinute = 0, iSecond = 0, iMillisecond = 0; try { // Get the Elements from the PD Bundle System.Collections.ArrayList cElementList = (System.Collections.ArrayList)cOSCBundle.Elements; // Loop through all Elements recieved from PD foreach (Ventuz.OSC.OscElement cElement in cElementList) { // Loop through each of the Elements Arguments foreach (object cObject in cElement.Args) { // Check which type of message this is and store its value appropriately switch (cElement.Address.ToString()) { case "/Hour": // Read in and store the Hour iHour = int.Parse(cObject.ToString()); break; case "/Minute": // Read in and store the Hour iMinute = int.Parse(cObject.ToString()); break; case "/Second": // Read in and store the Hour iSecond = int.Parse(cObject.ToString()); break; case "/Millisecond": // Read in and store the Hour iMillisecond = int.Parse(cObject.ToString()); break; case "/Velocity": // Read in and store the Velocity cMidiInfo.iVelocity = int.Parse(cObject.ToString()); break; case "/Note": // Read in and store the Note value cMidiInfo.iNote = int.Parse(cObject.ToString()); break; case "/Channel": // Read in and store the Channel value cMidiInfo.iChannel = int.Parse(cObject.ToString()); break; default: MessageBox.Show("Unknown PD Address: " + cElement.Address.ToString(), "ERROR"); break; } sInfo += cElement.Address.ToString() + ":" + cObject.ToString() + " "; } } } // Catch all exceptions catch (Exception e) { // Display the error message MessageBox.Show(e.ToString(), "ERROR"); } // If this was not a Note Off message if (cMidiInfo.iVelocity > 0) { // Set the Time of this Midi Note DateTime cTempDate = DateTime.Now; cMidiInfo.cTime = new DateTime(cTempDate.Year, cTempDate.Month, cTempDate.Day, iHour, iMinute, iSecond, iMillisecond); // Store the read in Midi Info cMidiInfoList.Add(cMidiInfo); // Output the found values for debugging purposes // int iRow = listBox1.Items.Add(sInfo); // listBox1.SetSelected(iRow, true); Console.WriteLine(sInfo); } }
// 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(); } } }