// Use this for initialization void Start() { // start of game we are in the menu game_state = Manager.game_states.MENU; game_timer = game_time; game_center = GameCenterSingleton.Instance; }
// Update is called once per frame void Update() { switch (game_state) { case game_states.MENU: // turn on the GUIText objects SwitchText(true); // store the screen position Vector3 screen_pos; #region iPhone if (Input.touchCount > 0) { if (Input.touches[0].phase == TouchPhase.Ended) { // make sure some time has passed if (Input.touches[0].deltaTime > 0.1) { screen_pos = GetMouseScreenPosition(false); if (start_text.HitTest(screen_pos)) game_state = Manager.game_states.START; //TODO //if (high_scores_text.HitTest(screen_pos)) // game_state = Manager.game_states.HIGH_SCORES; } } } #endregion #region mouse if(Input.GetMouseButtonUp(0)) { screen_pos = GetMouseScreenPosition(true); if (start_text.HitTest(screen_pos)) game_state = Manager.game_states.START; //TODO //if (high_scores_text.HitTest(screen_pos)) // game_state = Manager.game_states.HIGH_SCORES; } #endregion break; case game_states.START: // first turn off the GUIText objects SwitchText(false); // reset game ResetGame(); // change state! game_state = Manager.game_states.IN_GAME; break; case game_states.IN_GAME: // function will check if the game is finished but also do game logicky things if (IsGameComplete()) { // kill the balls // CLEAN UP WITH ILIST ITERATOR for (int i = 0; i < balls_max; i++) if (ball_instances[i]) ball_instances[i].GetComponent<Launcher>().KillMe(); game_state = Manager.game_states.GAME_OVER; } // show the GUI ShowGUIText(true); break; case game_states.GAME_OVER: // for now - // show the GUI ShowGUIText(false); // show the try again button try_again_text.gameObject.SetActive(true); // play again? #region iPhone if (Input.touchCount > 0) { if (Input.touches[0].phase == TouchPhase.Ended) { // make sure some time has passed if (Input.touches[0].deltaTime > 0.1) { screen_pos = GetMouseScreenPosition(false); if (try_again_text.HitTest(screen_pos)) game_state = Manager.game_states.START; } } } #endregion #region mouse if(Input.GetMouseButtonUp(0)) { screen_pos = GetMouseScreenPosition(true); if (try_again_text.HitTest(screen_pos)) game_state = Manager.game_states.START; } #endregion // show the score on a different Text object // allow to enter name // save to sql // show the start button/chamnge game state to start; break; case game_states.HIGH_SCORES: game_center.ShowLeaderboardUI(); break; } }
protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); #region startup screen if (Level_Response == game_states.Startup) { if (Keyboard.GetState().IsKeyDown(Keys.D0)) { buttonRelease = false; myControlType = ControlType._Keyboard; Level_Response = game_states.PlayerSelect; SoundEffect_List[0].Play(); } if (Keyboard.GetState().IsKeyDown(Keys.D1)) { buttonRelease = false; myControlType = ControlType._Gamepad; Level_Response = game_states.PlayerSelect; SoundEffect_List[0].Play(); } if (Keyboard.GetState().IsKeyDown(Keys.D2)) { buttonRelease = false; myControlType = ControlType._Kinect; Level_Response = game_states.PlayerSelect; SoundEffect_List[0].Play(); } } #endregion #region player select if (Level_Response == game_states.PlayerSelect) { if (Keyboard.GetState().IsKeyDown(Keys.D1) & buttonRelease == true) { buttonRelease = false; numberOfPlayers = 1; Level_Response = game_states.Continue; SoundEffect_List[0].Play(); // Create level here :) Game_Level = new Level(1, numberOfPlayers, Model_List, Texture_List, Font_list, SoundEffect_List);//, Animation_List); } if (Keyboard.GetState().IsKeyDown(Keys.D2) & buttonRelease == true) { buttonRelease = false; numberOfPlayers = 2; Level_Response = game_states.Continue; SoundEffect_List[0].Play(); // Create level here :) Game_Level = new Level(1, numberOfPlayers, Model_List, Texture_List, Font_list, SoundEffect_List);//, Animation_List); } } #endregion if (Keyboard.GetState().IsKeyUp(Keys.P) && Keyboard.GetState().IsKeyUp(Keys.R) && Keyboard.GetState().IsKeyUp(Keys.D0) && Keyboard.GetState().IsKeyUp(Keys.D1) && Keyboard.GetState().IsKeyUp(Keys.D2)) buttonRelease = true; #region pausing game if (Level_Response == game_states.Continue) if (Keyboard.GetState().IsKeyDown(Keys.P) & buttonRelease == true) { // to pause game SoundEffect_List[0].Play(); MediaPlayer.Pause(); buttonRelease = false; Level_Response = game_states.Pause; // testing } if (Level_Response == game_states.Pause) { if (Keyboard.GetState().IsKeyDown(Keys.P) & buttonRelease == true) { // unpause SoundEffect_List[0].Play(); MediaPlayer.Resume(); Level_Response = game_states.Continue; // testing buttonRelease = false; } // Show level menu - here have choices } #endregion #region Restarting Game if (Level_Response == game_states.Restart) { // restart game with 2 players at the moment SoundEffect_List[0].Play(); Game_Level = new Level(1, numberOfPlayers, Model_List, Texture_List, Font_list, SoundEffect_List); Level_Response = game_states.Continue; } if (Level_Response == game_states.Failed) { if (Keyboard.GetState().IsKeyDown(Keys.R) & buttonRelease == true) { Level_Response = game_states.Restart; // testing buttonRelease = false; } // tell player game is over } #endregion #region Close Game if (Keyboard.GetState().IsKeyDown(Keys.Escape) & buttonRelease == true) { Level_Response = game_states.Exit; buttonRelease = false; } if (Level_Response == game_states.Exit) { SoundEffect_List[0].Play(); Exit(); } #endregion #region Game Won if (Level_Response == game_states.Complete) { // do somethign if needed - maybe play a sound //MediaPlayer.Stop(); if (endsongflag == true) { MediaPlayer.Play(Win_Song); //MediaPlayer.Resume(); endsongflag = false; } } #endregion if (Level_Response == game_states.Continue) { MediaPlayer.Resume(); // if user decides to use the keyboard // max of 2 players for keyboard #region Keyboard Controlled //Player1 Controls - keyboard if (myControlType == ControlType._Keyboard) { #region Player1 Controls if (Keyboard.GetState().IsKeyDown(Keys.A)) Game_Level.Player_Move_Left(0); if (Keyboard.GetState().IsKeyDown(Keys.D)) Game_Level.Player_Move_Right(0); if (Keyboard.GetState().IsKeyDown(Keys.Space)) Game_Level.Player_Shoot(0); #endregion #region Player2 Controls if (numberOfPlayers > 1) { if (Keyboard.GetState().IsKeyDown(Keys.Left)) Game_Level.Player_Move_Left(1); if (Keyboard.GetState().IsKeyDown(Keys.Right)) Game_Level.Player_Move_Right(1); if (Keyboard.GetState().IsKeyDown(Keys.Enter)) Game_Level.Player_Shoot(1); } #endregion // Update level Level_Response = (game_states)Game_Level.Update_Level(gameTime); // TODO: Add your update logic here } if (Keyboard.GetState().IsKeyDown(Keys.R) & buttonRelease == true) { Level_Response = game_states.Restart; // testing buttonRelease = false; } #endregion #region Kinect Controlled //Player1 Controls - keyboard if (myControlType == ControlType._Kinect) { #region Player1 Controls Game_Level.Player_Move(0,(int)handvalue.X); if (kinectShoot == true) Game_Level.Player_Shoot(0); #endregion // Update level Level_Response = (game_states)Game_Level.Update_Level(gameTime); // TODO: Add your update logic here } #endregion } base.Update(gameTime); }