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(); }
// 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); }
// 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(); }
// 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); }
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; }
// 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(); }