// Use this for initialization void Start() { UpdateDifficultyOnScripts(); //Setup first level m_nLevelNumber = 1; this.gameObject.GetComponent <FlySwatterGlobalVarScript>().m_fRoundTime = 5.0f; GameObject.Find("3DTextLevelNum").GetComponent <TextMesh>().text = m_nLevelNumber.ToString(); m_eMainGameStates = eGameStates.eRandomiseToAvoid; //Disable renderer for post game answers GameObject.Find("3DTextCharIntValues").GetComponent <MeshRenderer>().renderer.enabled = false; GameObject.Find("3DTextChartIntHeader").GetComponent <MeshRenderer>().renderer.enabled = false; }
protected override void Initialize() { graphics.PreferredBackBufferHeight = GAME_WINDOW_HEIGHT; graphics.PreferredBackBufferWidth = GAME_WINDOW_WIDTH; gamestate = eGameStates.MENU; // Start the game at the menu gamestate player = new Player(); // Initialize the player balls = new List<DodgeBall>(); // Create a new list of balls this.IsMouseVisible = false; // Hide the mouse base.Initialize(); }
void HandleCollision() { for (int i = 0; i <balls.Count;i++) { if(player.CollidesWith(balls[i].Position)) { gamestate = eGameStates.MENU; balls.RemoveRange(0, balls.Count); if (score > highScore) { highScore = score; } score = 0; } } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); HandleCollision(); if (gamestate == eGameStates.PLAY) // Only do this if the gamestate is play, so while the game is running { score += 1; CreateNewBall(gameTime); // Creates new balls constantly DestroyBallAfterUse(); // Destroys balls after they have left the screen Input.Update(); // Update the mouse player.Update(); // Update the player UpdateBalls(gameTime); // Update the balls } if(Keyboard.GetState().IsKeyDown(Keys.Enter)) { gamestate = eGameStates.PLAY; } base.Update(gameTime); }
// Update is called once per frame void Update() { switch(m_eMainGameStates) { case eGameStates.eRandomiseToAvoid: { this.gameObject.GetComponent<FlySwatterCharIntToRememberScript>().GenerateRandomCharInt(); this.gameObject.GetComponent<FlySwatterCharIntToRememberScript>().DisplayCharInt(); GameObject.Find("3DTextHeader1").renderer.enabled = true; GameObject.Find("3DTextHeader2").renderer.enabled = true; GameObject.Find("3DTextHeader3").renderer.enabled = true; GameObject.Find ("3DTextTimeLimitHeader").renderer.enabled = true; GameObject.Find ("3DTextTimeLimitHeader").transform.GetChild(0).renderer.enabled = true; //Show Sidebar every round GameObject.Find("3DTextTimer").GetComponent<TextMesh>().text = GameObject.Find("SceneManager").GetComponent<FlySwatterGlobalVarScript>().m_fRoundTime.ToString(); for(int i = 0; i < 10; i++) { GameObject.Find ("Elements(Sidebar)").transform.GetChild(i).renderer.enabled = true; } this.gameObject.GetComponent<FlySwatterTimerScript>().SetTime(5.0f); m_eMainGameStates = eGameStates.eRevealToAvoid; break; } case eGameStates.eRevealToAvoid: { if(this.gameObject.GetComponent<FlySwatterTimerScript>().HasReachedTime()) { this.gameObject.GetComponent<FlySwatterCharIntToRememberScript>().RemoveRevealCharInt(); GameObject.Find("3DTextHeader1").renderer.enabled = false; GameObject.Find("3DTextHeader2").renderer.enabled = false; GameObject.Find("3DTextHeader3").renderer.enabled = false; GameObject.Find ("3DTextTimeLimitHeader").renderer.enabled = false; GameObject.Find ("3DTextTimeLimitHeader").transform.GetChild(0).renderer.enabled = false; GameObject.Find("3DTextCountdownNum").renderer.enabled = true; this.gameObject.GetComponent<FlySwatterTimerScript>().SetTime (4.0f); m_fCountdownTimer = 4.0f; m_eMainGameStates = eGameStates.ePrelevelCountdown; } //Else continue to show break; } case eGameStates.ePrelevelCountdown: { if(this.gameObject.GetComponent<FlySwatterTimerScript>().HasReachedTime()) { GameObject.Find("3DTextCountdownNum").renderer.enabled = false; float fRoundTime = this.gameObject.GetComponent<FlySwatterGlobalVarScript>().m_fRoundTime; this.gameObject.GetComponent<FlySwatterTimerScript>().SetTime (fRoundTime); this.gameObject.GetComponent<FlySwatterTimerScript>().DisplayTimer(); this.gameObject.GetComponent<FlySwatterScoringScript>().DisplayText(); m_eMainGameStates = eGameStates.eLevelStart; } else { if(m_fCountdownTimer <= 1.0f) { //GameObject.Find("3DTextCountdownNum").transform.localScale = new Vector3(3.0f, 3.0f, 3.0f); GameObject.Find("3DTextCountdownNum").GetComponent<TextMesh>().text = "GO!"; } else { int nSecondsBeforeChange = int.Parse (GameObject.Find("3DTextCountdownNum").GetComponent<TextMesh>().text); GameObject.Find("3DTextCountdownNum").GetComponent<TextMesh>().text = ((int) m_fCountdownTimer).ToString (); if(nSecondsBeforeChange > (int) m_fCountdownTimer) { //GameObject.Find("3DTextCountdownNum").transform.localScale = new Vector3(3.0f, 3.0f, 3.0f); } //GameObject.Find("3DTextCountdownNum").transform.localScale -= new Vector3(0.03f,0.03f, 0.03f); } } m_fCountdownTimer -= Time.deltaTime; break; } case eGameStates.eLevelStart: { //Spawn flies first if(!m_bHasSpawnedFlies) { this.gameObject.GetComponent<FlySwatterFliesManagerScript>().SpawnFlies(m_nLevelNumber); m_fFliesLeft = GameObject.FindGameObjectsWithTag("Fly").Length; m_bHasSpawnedFlies = true; } //Check for mouse down if(Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if(Physics.Raycast(rRay, out rchHit, 100)) { //Input numbers if(rchHit.transform.gameObject.tag == "Fly") { if(!rchHit.transform.gameObject.GetComponent<FlySwatterFlyScript>().GetIsSquished()) { bool bIsCharacter = rchHit.transform.gameObject.GetComponent<FlySwatterFlyScript>().GetIsCharacter(); if(bIsCharacter) { char cFlyChar = rchHit.transform.gameObject.GetComponent<TextMesh>().text[0]; //Hit something that is to be remembered if(this.gameObject.GetComponent<FlySwatterCharIntToRememberScript>().CompareChar(cFlyChar)) { Debug.Log ("NopeNopeNope"); this.gameObject.GetComponent<FlySwatterScoringScript>().DeductScore(); this.gameObject.GetComponent<FlySwatterScoringScript>().ResetVars(); } else { rchHit.transform.gameObject.GetComponent<FlySwatterFlyScript>().TriggerDeath(); m_fFliesLeft--; this.gameObject.GetComponent<FlySwatterScoringScript>().AddScore (); GameObject.Find("Sound_Squish").GetComponent<BasicSoundScript>().PlaySound(); } } else { int cFlyInt = int.Parse(rchHit.transform.gameObject.GetComponent<TextMesh>().text); //Hit something that is to be remembered if(this.gameObject.GetComponent<FlySwatterCharIntToRememberScript>().CompareInt(cFlyInt)) { Debug.Log ("NopeNopeNope"); this.gameObject.GetComponent<FlySwatterScoringScript>().DeductScore(); this.gameObject.GetComponent<FlySwatterScoringScript>().ResetVars(); } else { rchHit.transform.gameObject.GetComponent<FlySwatterFlyScript>().TriggerDeath(); m_fFliesLeft--; this.gameObject.GetComponent<FlySwatterScoringScript>().AddScore (); GameObject.Find("Sound_Squish").GetComponent<BasicSoundScript>().PlaySound(); } } } } } } //Based on level, check for number of flies left if(m_bIsEasyLevel) { if(m_fFliesLeft <= 2) { Debug.Log("Yay Winner"); this.gameObject.GetComponent<FlySwatterTimerScript>().StopTimer (); this.gameObject.GetComponent<FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; if(m_nLevelNumber >= 10) { //SetGameEndMessage(); m_bHasWonAll = true; } m_bHasWonLevel = true; DisplayCrossTick(); GameObject.Find("Sound_Correct").GetComponent<BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } } else { if(m_fFliesLeft <= 4) { Debug.Log("Yay Winner"); this.gameObject.GetComponent<FlySwatterTimerScript>().StopTimer (); this.gameObject.GetComponent<FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; if(m_nLevelNumber >= 10) { //SetGameEndMsessage(); m_bHasWonAll = true; } m_bHasWonLevel = true; DisplayCrossTick(); GameObject.Find("Sound_Correct").GetComponent<BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } } //Check time if(this.gameObject.GetComponent<FlySwatterTimerScript>().HasReachedTime()) { Debug.Log("Uhoh! Times Up!"); this.gameObject.GetComponent<FlySwatterTimerScript>().StopTimer (); this.gameObject.GetComponent<FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; m_bHasWonLevel = false; DisplayCrossTick(); GameObject.Find("Sound_Wrong").GetComponent<BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } break; } case eGameStates.eDisplayCrossTick: { if(m_fTimer <= 0.0f) { if(m_bHasWonLevel) { DestroyCrossTick(); DestroyRemainingFlies(); CleanUpLevel(); ResetVariables(); // if(m_bHasWonAll) // { // this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetSummaryScreen(true); // m_eMainGameStates = eGameStates.eSummary; // } // else //Still has next level { SetNextLevel(); m_eMainGameStates = eGameStates.eRandomiseToAvoid; } } else { DestroyCrossTick(); // DestroyRemainingFlies(); // this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetSummaryScreen(false); // Application.LoadLevel(Application.loadedLevelName); StartCoroutine(DisplayAnswer()); m_eMainGameStates = eGameStates.eTotal; // m_eMainGameStates = eGameStates.eSummary; // GameObject.Find("SceneManager").GetComponent<FlySwatterCharIntToRememberScript>().ShowAnswersPostGame(); } } m_fTimer -= Time.deltaTime; break; } case eGameStates.eSummary: { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInSummaryScreenElements(); //Check for mouse down if(Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if(Physics.Raycast(rRay, out rchHit, 100)) { if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) { if(rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) { Application.LoadLevel(Application.loadedLevel); } else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) { Application.LoadLevel("Game_Flyswatter_Select"); } } else { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); } } } break; } /* case eGameStates.eLevelPass: { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); //Check for mouse down if(Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if(Physics.Raycast(rRay, out rchHit, 100)) { //Input numbers if(rchHit.transform.gameObject != GameObject.Find ("BackButton")) { if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) { CleanUpLevel(); ResetVariables(); SetNextLevel(); m_eMainGameStates = eGameStates.eRandomiseToAvoid; } else { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); } } } } break; //Correct ones DestroyRemainingFlies(); CleanUpLevel(); ResetVariables(); SetNextLevel(); m_eMainGameStates = eGameStates.eRandomiseToAvoid; break; } case eGameStates.eLevelFail: { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); //Check for mouse down if(Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if(Physics.Raycast(rRay, out rchHit, 100)) { if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) { if(rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) { Application.LoadLevel(Application.loadedLevel); } else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) { Application.LoadLevel("Game_Flyswatter_Select"); } } else { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); } } } break; } case eGameStates.eGameEnd: { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); //Check for mouse down if(Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if(Physics.Raycast(rRay, out rchHit, 100)) { if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) { if(rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) { Application.LoadLevel(Application.loadedLevel); } else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) { Application.LoadLevel("Game_Flyswatter_Select"); } } else { this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); } } } break; } */ } }
// Use this for initialization void Start() { UpdateDifficultyOnScripts(); //Setup first level m_nLevelNumber = 1; this.gameObject.GetComponent<FlySwatterGlobalVarScript>().m_fRoundTime = 5.0f; GameObject.Find("3DTextLevelNum").GetComponent<TextMesh>().text = m_nLevelNumber.ToString (); m_eMainGameStates = eGameStates.eRandomiseToAvoid; //Disable renderer for post game answers GameObject.Find("3DTextCharIntValues").GetComponent<MeshRenderer>().renderer.enabled = false; GameObject.Find("3DTextChartIntHeader").GetComponent<MeshRenderer>().renderer.enabled = false; }
// Update is called once per frame void Update() { switch (m_eMainGameStates) { case eGameStates.eRandomiseToAvoid: { this.gameObject.GetComponent <FlySwatterCharIntToRememberScript>().GenerateRandomCharInt(); this.gameObject.GetComponent <FlySwatterCharIntToRememberScript>().DisplayCharInt(); GameObject.Find("3DTextHeader1").renderer.enabled = true; GameObject.Find("3DTextHeader2").renderer.enabled = true; GameObject.Find("3DTextHeader3").renderer.enabled = true; GameObject.Find("3DTextTimeLimitHeader").renderer.enabled = true; GameObject.Find("3DTextTimeLimitHeader").transform.GetChild(0).renderer.enabled = true; //Show Sidebar every round GameObject.Find("3DTextTimer").GetComponent <TextMesh>().text = GameObject.Find("SceneManager").GetComponent <FlySwatterGlobalVarScript>().m_fRoundTime.ToString(); for (int i = 0; i < 10; i++) { GameObject.Find("Elements(Sidebar)").transform.GetChild(i).renderer.enabled = true; } this.gameObject.GetComponent <FlySwatterTimerScript>().SetTime(5.0f); m_eMainGameStates = eGameStates.eRevealToAvoid; break; } case eGameStates.eRevealToAvoid: { if (this.gameObject.GetComponent <FlySwatterTimerScript>().HasReachedTime()) { this.gameObject.GetComponent <FlySwatterCharIntToRememberScript>().RemoveRevealCharInt(); GameObject.Find("3DTextHeader1").renderer.enabled = false; GameObject.Find("3DTextHeader2").renderer.enabled = false; GameObject.Find("3DTextHeader3").renderer.enabled = false; GameObject.Find("3DTextTimeLimitHeader").renderer.enabled = false; GameObject.Find("3DTextTimeLimitHeader").transform.GetChild(0).renderer.enabled = false; GameObject.Find("3DTextCountdownNum").renderer.enabled = true; this.gameObject.GetComponent <FlySwatterTimerScript>().SetTime(4.0f); m_fCountdownTimer = 4.0f; m_eMainGameStates = eGameStates.ePrelevelCountdown; } //Else continue to show break; } case eGameStates.ePrelevelCountdown: { if (this.gameObject.GetComponent <FlySwatterTimerScript>().HasReachedTime()) { GameObject.Find("3DTextCountdownNum").renderer.enabled = false; float fRoundTime = this.gameObject.GetComponent <FlySwatterGlobalVarScript>().m_fRoundTime; this.gameObject.GetComponent <FlySwatterTimerScript>().SetTime(fRoundTime); this.gameObject.GetComponent <FlySwatterTimerScript>().DisplayTimer(); this.gameObject.GetComponent <FlySwatterScoringScript>().DisplayText(); m_eMainGameStates = eGameStates.eLevelStart; } else { if (m_fCountdownTimer <= 1.0f) { //GameObject.Find("3DTextCountdownNum").transform.localScale = new Vector3(3.0f, 3.0f, 3.0f); GameObject.Find("3DTextCountdownNum").GetComponent <TextMesh>().text = "GO!"; } else { int nSecondsBeforeChange = int.Parse(GameObject.Find("3DTextCountdownNum").GetComponent <TextMesh>().text); GameObject.Find("3DTextCountdownNum").GetComponent <TextMesh>().text = ((int)m_fCountdownTimer).ToString(); if (nSecondsBeforeChange > (int)m_fCountdownTimer) { //GameObject.Find("3DTextCountdownNum").transform.localScale = new Vector3(3.0f, 3.0f, 3.0f); } //GameObject.Find("3DTextCountdownNum").transform.localScale -= new Vector3(0.03f,0.03f, 0.03f); } } m_fCountdownTimer -= Time.deltaTime; break; } case eGameStates.eLevelStart: { //Spawn flies first if (!m_bHasSpawnedFlies) { this.gameObject.GetComponent <FlySwatterFliesManagerScript>().SpawnFlies(m_nLevelNumber); m_fFliesLeft = GameObject.FindGameObjectsWithTag("Fly").Length; m_bHasSpawnedFlies = true; } //Check for mouse down if (Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if (Physics.Raycast(rRay, out rchHit, 100)) { //Input numbers if (rchHit.transform.gameObject.tag == "Fly") { if (!rchHit.transform.gameObject.GetComponent <FlySwatterFlyScript>().GetIsSquished()) { bool bIsCharacter = rchHit.transform.gameObject.GetComponent <FlySwatterFlyScript>().GetIsCharacter(); if (bIsCharacter) { char cFlyChar = rchHit.transform.gameObject.GetComponent <TextMesh>().text[0]; //Hit something that is to be remembered if (this.gameObject.GetComponent <FlySwatterCharIntToRememberScript>().CompareChar(cFlyChar)) { Debug.Log("NopeNopeNope"); this.gameObject.GetComponent <FlySwatterScoringScript>().DeductScore(); this.gameObject.GetComponent <FlySwatterScoringScript>().ResetVars(); } else { rchHit.transform.gameObject.GetComponent <FlySwatterFlyScript>().TriggerDeath(); m_fFliesLeft--; this.gameObject.GetComponent <FlySwatterScoringScript>().AddScore(); GameObject.Find("Sound_Squish").GetComponent <BasicSoundScript>().PlaySound(); } } else { int cFlyInt = int.Parse(rchHit.transform.gameObject.GetComponent <TextMesh>().text); //Hit something that is to be remembered if (this.gameObject.GetComponent <FlySwatterCharIntToRememberScript>().CompareInt(cFlyInt)) { Debug.Log("NopeNopeNope"); this.gameObject.GetComponent <FlySwatterScoringScript>().DeductScore(); this.gameObject.GetComponent <FlySwatterScoringScript>().ResetVars(); } else { rchHit.transform.gameObject.GetComponent <FlySwatterFlyScript>().TriggerDeath(); m_fFliesLeft--; this.gameObject.GetComponent <FlySwatterScoringScript>().AddScore(); GameObject.Find("Sound_Squish").GetComponent <BasicSoundScript>().PlaySound(); } } } } } } //Based on level, check for number of flies left if (m_bIsEasyLevel) { if (m_fFliesLeft <= 2) { Debug.Log("Yay Winner"); this.gameObject.GetComponent <FlySwatterTimerScript>().StopTimer(); this.gameObject.GetComponent <FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; if (m_nLevelNumber >= 10) { //SetGameEndMessage(); m_bHasWonAll = true; } m_bHasWonLevel = true; DisplayCrossTick(); GameObject.Find("Sound_Correct").GetComponent <BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } } else { if (m_fFliesLeft <= 4) { Debug.Log("Yay Winner"); this.gameObject.GetComponent <FlySwatterTimerScript>().StopTimer(); this.gameObject.GetComponent <FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; if (m_nLevelNumber >= 10) { //SetGameEndMsessage(); m_bHasWonAll = true; } m_bHasWonLevel = true; DisplayCrossTick(); GameObject.Find("Sound_Correct").GetComponent <BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } } //Check time if (this.gameObject.GetComponent <FlySwatterTimerScript>().HasReachedTime()) { Debug.Log("Uhoh! Times Up!"); this.gameObject.GetComponent <FlySwatterTimerScript>().StopTimer(); this.gameObject.GetComponent <FlySwatterScoringScript>().SetSecondsRemaining(); //Set seconds remaining in level m_fTimer = 1.0f; m_bHasWonLevel = false; DisplayCrossTick(); GameObject.Find("Sound_Wrong").GetComponent <BasicSoundScript>().PlaySound(); m_eMainGameStates = eGameStates.eDisplayCrossTick; } break; } case eGameStates.eDisplayCrossTick: { if (m_fTimer <= 0.0f) { if (m_bHasWonLevel) { DestroyCrossTick(); DestroyRemainingFlies(); CleanUpLevel(); ResetVariables(); // if(m_bHasWonAll) // { // this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetSummaryScreen(true); // m_eMainGameStates = eGameStates.eSummary; // } // else //Still has next level { SetNextLevel(); m_eMainGameStates = eGameStates.eRandomiseToAvoid; } } else { DestroyCrossTick(); // DestroyRemainingFlies(); // this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetSummaryScreen(false); // Application.LoadLevel(Application.loadedLevelName); StartCoroutine(DisplayAnswer()); m_eMainGameStates = eGameStates.eTotal; // m_eMainGameStates = eGameStates.eSummary; // GameObject.Find("SceneManager").GetComponent<FlySwatterCharIntToRememberScript>().ShowAnswersPostGame(); } } m_fTimer -= Time.deltaTime; break; } case eGameStates.eSummary: { this.gameObject.GetComponent <FlySwatterSummaryScreenScript>().FadeInSummaryScreenElements(); //Check for mouse down if (Input.GetMouseButtonDown(0)) { Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rchHit = new RaycastHit(); if (Physics.Raycast(rRay, out rchHit, 100)) { if (this.gameObject.GetComponent <FlySwatterSummaryScreenScript>().m_bHasFadedIn) { if (rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) { Application.LoadLevel(Application.loadedLevel); } else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) { Application.LoadLevel("Game_Flyswatter_Select"); } } else { this.gameObject.GetComponent <FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); } } } break; } /* * case eGameStates.eLevelPass: * { * * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); * * //Check for mouse down * if(Input.GetMouseButtonDown(0)) * { * Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit rchHit = new RaycastHit(); * * if(Physics.Raycast(rRay, out rchHit, 100)) * { * //Input numbers * if(rchHit.transform.gameObject != GameObject.Find ("BackButton")) * { * if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) * { * CleanUpLevel(); * ResetVariables(); * SetNextLevel(); * m_eMainGameStates = eGameStates.eRandomiseToAvoid; * } * else * { * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); * } * } * } * } * break; * * //Correct ones * DestroyRemainingFlies(); * CleanUpLevel(); * ResetVariables(); * SetNextLevel(); * m_eMainGameStates = eGameStates.eRandomiseToAvoid; * * break; * * } * * * case eGameStates.eLevelFail: * { * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); * * //Check for mouse down * if(Input.GetMouseButtonDown(0)) * { * Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit rchHit = new RaycastHit(); * * if(Physics.Raycast(rRay, out rchHit, 100)) * { * if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) * { * if(rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) * { * Application.LoadLevel(Application.loadedLevel); * } * else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) * { * Application.LoadLevel("Game_Flyswatter_Select"); * } * } * else * { * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); * } * } * } * * break; * } * * case eGameStates.eGameEnd: * { * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().FadeInEndLevelElements(); * * //Check for mouse down * if(Input.GetMouseButtonDown(0)) * { * Ray rRay = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit rchHit = new RaycastHit(); * * if(Physics.Raycast(rRay, out rchHit, 100)) * { * if(this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().m_bHasFadedIn) * { * if(rchHit.collider.gameObject == GameObject.Find("RetryButton(Clone)")) * { * Application.LoadLevel(Application.loadedLevel); * } * else if (rchHit.collider.gameObject == GameObject.Find("SelectDifficultyButton(Clone)")) * { * Application.LoadLevel("Game_Flyswatter_Select"); * } * } * else * { * this.gameObject.GetComponent<FlySwatterSummaryScreenScript>().SetElementsMaxAlpha(); * } * } * } * * break; * } * */ } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); KeyboardState state = Keyboard.GetState(); //check if the states should change before updating if (msMenu.shouldChangeState == true) { eCurrentGameState = eGameStates.gamePlay; gsGameplay.initialiseGameWorld(); msMenu.shouldChangeState = false; } else if (gsGameplay.shouldChangeState == true) { eCurrentGameState = eGameStates.gameOver; esGameOver.initialise(); gsGameplay.shouldChangeState = false; } else if (esGameOver.shouldChangeState == true) { eCurrentGameState = eGameStates.mainMenu; msMenu.reinitialiseMenu(); esGameOver.shouldChangeState = false; } //update the states as required if (eCurrentGameState == eGameStates.mainMenu) { msMenu.update(state); if (msMenu.shouldQuit == true) { Exit(); } } else if (eCurrentGameState == eGameStates.gamePlay) { gsGameplay.updateGame(state); } else if (eCurrentGameState == eGameStates.gameOver) { esGameOver.update(state); } //--------------------------------- // TODO: Add your update logic here //--------------------------------- base.Update(gameTime); }