private void EnableDisablePlayObjects(_GameState gameState) { if (gameState == _GameState.Play) { textController.pauseScreenButtonGO.SetActive(true); for (int i = 0; i < textController.playObjects.Count; i++) { TextController.PlayTitleBox playObject = textController.playObjects[i]; playObject.TitleBoxEnabled(true); } } else if (gameState == _GameState.MainMenu) { textController.pauseScreenButtonGO.SetActive(false); for (int i = 0; i < textController.playObjects.Count; i++) { TextController.PlayTitleBox playObject = textController.playObjects[i]; playObject.TitleBoxEnabled(false); } } else { for (int i = 0; i < textController.playObjects.Count; i++) { TextController.PlayTitleBox playObject = textController.playObjects[i]; playObject.TitleBoxEnabled(false); } } }
void OnDeductUnitLife(Unit unit) { for (int i = 0; i < lifeUnit.Count; i++) { if (unit.GetCurrentHP() <= 0 && unit == lifeUnit[i]) { lifeUnit.RemoveAt(i); break; } } if (onLifeE != null) { onLifeE(); } if (lifeUnit.Count == 0) { //game over, player lost gameState = _GameState.Ended; if (onGameOverE != null) { onGameOverE(false); } } }
private void EnableDiableMainMenuObjects(_GameState gameState) { if (textController.mainMenuObjects == null) { Debug.Log("Menu objects not loaded yet."); } else if (gameState == _GameState.MainMenu) { textController.mainMenuButtonGO.SetActive(false); for (int i = 0; i < textController.mainMenuObjects.Count; i++) { GameObject menuObject = textController.mainMenuObjects[i]; menuObject.SetActive(true); } } else { textController.mainMenuButtonGO.SetActive(true); for (int i = 0; i < textController.mainMenuObjects.Count; i++) { GameObject menuObject = textController.mainMenuObjects[i]; menuObject.SetActive(false); } } }
public void OnPauseButton() { _GameState gameState = GameControl.GetGameState(); if (gameState == _GameState.Over) { return; } if (toggleFastForward.isOn) { toggleFastForward.isOn = false; } if (gameState == _GameState.Pause) { GameControl.ResumeGame(); UIPauseMenu.Hide(); } else { GameControl.PauseGame(); UIPauseMenu.Show(); } }
public IEnumerator _GameWon() { ResumeGame(); //call to reset ff speed yield return(new WaitForSeconds(0.0f)); if (gameState == _GameState.Play) { gameState = _GameState.Over; int _cap = GameControl.GetPlayerLifeCap(); int _life = GameControl.GetPlayerLife(); int _star = 3; if (_cap > 0) { float percent = (float)_life / _cap; if (percent < 0.5f) { _star = 1; } else if (percent < 0.9f) { _star = 2; } } if (onGameOverE != null) { onGameOverE(_star); } } }
public void MainMenu() { Debug.Log("GameState is now MainMenu."); gameState = _GameState.MainMenu; EnableDisablePlayObjects(gameState); EnableDiableMainMenuObjects(gameState); }
public void PlayGame() { Debug.Log("GameState now in Play."); gameState = _GameState.Play; EnableDiableMainMenuObjects(gameState); EnableDisablePlayObjects(gameState); }
public void StickerBook() { Debug.Log("GameState now in Stickers."); gameState = _GameState.Stickers; EnableDiableMainMenuObjects(gameState); EnableDisablePlayObjects(gameState); }
/* * private Texture icon; * private bool loadAttempt=false; * void OnGUI(){ * if(icon==null){ * if(!loadAttempt) icon=(Texture)Resources.Load("Title&Icon/icon_free"); * * GUI.Label(new Rect(Screen.width-80, Screen.height-25-25, 100, 30), "TDTK Free"); * } * else{ * //GUIContent guiContent=new GUIContent(" TDTK Free", icon); * //~ GUI.Label(new Rect(Screen.width-100, Screen.height-30-25, 100, 30), guiContent); * GUI.Label(new Rect(Screen.width-65, Screen.height-65-25, 60, 60), icon); * } * } */ void OnWaveStartSpawned(int waveID) { currentWave += 1; //if game is not yet started, start it now if (gameState == _GameState.Idle) { gameState = _GameState.Started; } }
void Awake() { ObjectPoolManager.Init(); gameObject.GetComponent <LayerManager>().Awake(); GameMessage gameMessage = (GameMessage)FindObjectOfType(typeof(GameMessage)); if (gameMessage == null) { GameMessage.Init(); } AudioManager audioManager = (AudioManager)FindObjectOfType(typeof(AudioManager)); if (audioManager == null) { AudioManager.Init(); } //LayerManager.Init(); gameControl = this; gameState = _GameState.Idle; if (rangeIndicatorH) { rangeIndicatorH = (Transform)Instantiate(rangeIndicatorH); rangeIndicatorH.parent = transform; } if (rangeIndicatorConeH) { rangeIndicatorConeH = (Transform)Instantiate(rangeIndicatorConeH); rangeIndicatorConeH.parent = transform; } if (rangeIndicatorF) { rangeIndicatorF = (Transform)Instantiate(rangeIndicatorF); rangeIndicatorF.parent = transform; } ClearIndicator(); //~ OverlayManager.Init(); OverlayManager.SetModifier(buildingBarWidthModifier, buildingBarHeightModifier); OverlayManager.SetOffset(buildingBarPosOffset); gameObject.GetComponent <ResourceManager>().Init(); if (FindObjectOfType(typeof(PerkManager)) == null) { PerkManager.InitResourceModifier(); } }
void onReloadStart(float timeToReload, Gun gun) { GameState = _GameState.IsReloading; if (DBAccess.instance.userPrefs.userGun.model != "Winchester_1912") { audioSources[5].Play(); } else { audioSources[12].Play(); } }
public IEnumerator _GameWon() { ResumeGame(); //call to reset ff speed yield return(new WaitForSeconds(0.0f)); gameState = _GameState.Over; playerWon = true; if (onGameOverE != null) { onGameOverE(playerWon); } }
void OnWaveCleared(int waveID) { Debug.Log("Wave " + waveID + " has been cleared"); if (waveID == totalWaveCount - 1) { //game over, player won gameState = _GameState.Ended; if (onGameOverE != null) { onGameOverE(true); } } }
private void GameStateSetup(_GameState gameState) { switch (gameState) { case _GameState.SingleNeutral: GameStateSingleNeutral(); break; case _GameState.SinglePlanetAttack: GameStateSinglePlanetAttack(); break; case _GameState.SinglePlanetDefend: GameStateSinglePlanetDefend(); break; } }
public IEnumerator _GameOver(bool won) { if (gameOver) { yield break; //stop the coroutine if it has already been called } gameOver = true; Debug.Log("game over - " + (won ? "win" : "lost")); //delay 1.5 second before issuing a global gameover event yield return(new WaitForSeconds(1.5f)); gameState = _GameState.GameOver; TDS.GameOver(won); }
void onEnemyStatsChange(EnemyStats stats, EnemyBase._EnemyState state) { if (state == EnemyBase._EnemyState.Dead) { GameState = _GameState.Results; onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, stats); DBAccess.instance.userPrefs.wins++; if (GameCenterBinding.isPlayerAuthenticated()) { GameCenterBinding.reportScore((long)DBAccess.instance.userPrefs.wins, "Leaderboard_Win"); } } }
void OnUnitReachDestination(UnitCreep unit) { playerLife = Mathf.Max(0, playerLife - unit.lifeCost); if (onLifeE != null) { onLifeE(-unit.lifeCost); } if (playerLife <= 0) { gameState = _GameState.Over; if (onGameOverE != null) { onGameOverE(playerWon); } } }
public void Pause() { if (gameState == _GameState.Paused) { Debug.Log("GameState is now Play."); gameState = _GameState.Play; EnableDisablePlayObjects(gameState); textController.pauseScreenGO.SetActive(false); } else { Debug.Log("GameState is now Paused."); gameState = _GameState.Paused; EnableDisablePlayObjects(gameState); textController.pauseScreenGO.SetActive(true); } }
public _GameState MenuSelection() { if (keyB_state.IsKeyDown(Keys.Up)) { if (KeyPressed(Keys.Up)) { _select_pos -= 1; if (_select_pos < 0) { _select_pos = 0; } } } if (keyB_state.IsKeyDown(Keys.Down)) { if (KeyPressed(Keys.Down)) { _select_pos += 1; if (_select_pos > 3) { _select_pos = 3; } } } if (keyB_state.IsKeyDown(Keys.Space) && _select_pos == 0) { _currentGameState = _GameState.SinglePlayer; } else if (keyB_state.IsKeyDown(Keys.Space) && _select_pos == 1) { _currentGameState = _GameState.MultiPlayer; } else if (keyB_state.IsKeyDown(Keys.Space) && _select_pos == 2) { _currentGameState = _GameState.Credits; } else if (keyB_state.IsKeyDown(Keys.Space) && _select_pos == 3) { _currentGameState = _GameState.Exit; } return(_currentGameState); }
void onPause() { // Disable Pause in Reload Mode // Bugfix hack: Pause does not release in Reload Menu. if (GameState == _GameState.Reload) { UnityEngine.Debug.Log("PlayerController.cs: Bypass Pause in Reload Menu"); return; } if (Time.timeScale == 1) { _cachedAxes = axes; _cachedGameState = GameState; axes = RotationAxes.None; GameState = _GameState.Paused; audioSources[10].mute = true; audioSources[11].mute = true; Time.timeScale = 0; if (Application.platform == RuntimePlatform.IPhonePlayer) { ChartBoostBinding.trackEvent("On Pause Event"); } } else { axes = _cachedAxes; GameState = _cachedGameState; audioSources[10].mute = false; audioSources[11].mute = false; Time.timeScale = 1; } }
void OnDeductLife(int lifeCost) { playerLife -= lifeCost; if (playerLife <= 0) { playerLife = 0; } if (onLifeE != null) { onLifeE(); } if (playerLife == 0) { //game over, player lost gameState = _GameState.Ended; if (onGameOverE != null) { onGameOverE(false); } } }
protected override void Initialize() { // screen 800,480 this.graphics.PreferredBackBufferWidth = 800; this.graphics.PreferredBackBufferHeight = 480; graphics.ApplyChanges(); _currentGameState = _GameState.SplashScreen; _move_down = true; _move_right = true; _middle_position = new Vector2(380, 40); _pallet1_position = new Vector2(40, 200); _pallet2_position = new Vector2(760, 200); _ball_position = new Vector2(370, 200); _DEV_ball_position = new Vector2(0, 0); _score_position = new Vector2(30, 200); _single_position = new Vector2(220, 230); _multi_position = new Vector2(240, 270); _credits_position = new Vector2(310, 310); _exit_position = new Vector2(350, 350); _scoreP1 = 0; _scoreP2 = 0; base.Initialize(); }
void Awake() { ObjectPoolManager.Init(); GameMessage gameMessage=(GameMessage)FindObjectOfType(typeof(GameMessage)); if(gameMessage==null){ GameMessage.Init(); } AudioManager audioManager=(AudioManager)FindObjectOfType(typeof(AudioManager)); if(audioManager==null){ AudioManager.Init(); } //LayerManager.Init(); gameControl=this; gameState=_GameState.Idle; if(rangeIndicatorH){ rangeIndicatorH=(Transform)Instantiate(rangeIndicatorH); rangeIndicatorH.parent=transform; } if(rangeIndicatorF){ rangeIndicatorF=(Transform)Instantiate(rangeIndicatorF); rangeIndicatorF.parent=transform; } ClearIndicator(); OverlayManager.SetModifier(buildingBarWidthModifier, buildingBarHeightModifier); OverlayManager.SetOffset(buildingBarPosOffset); }
void OnDeductLife(int waveID) { playerLife-=1; if(playerLife<=0) playerLife=0; if(onLifeE!=null) onLifeE(); if(playerLife==0){ //game over, player lost gameState=_GameState.Ended; if(onGameOverE!=null) onGameOverE(false); } }
public void PlayerStateChange(_GameState gameState) { switch (gameState) { case _GameState.SingleNeutral: switch (playerNumber) { case 0: //player playerSetupSP.EnableSpaceGraphics(); instance.transform.position = GameData.instance.spaceSpawnPoints[playerSetupSP.playerNumber].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControlSP.EnableSpaceControl(); playerCameraSP.EnableSpaceCamera(); break; case 1: //computer opponent opponentController.EnableSpaceContainer(); break; } break; case _GameState.SinglePlanetAttack: switch (playerNumber) { case 0: //player playerSetupSP.EnablePlanetGraphics(); instance.transform.position = GameData.instance.planetSpawnPoints[playerSetupSP.playerNumber].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControlSP.EnablePlanetControl(); playerCameraSP.EnablePlanetCameraAttacker(); break; case 1: //computer opponent opponentController.EnableDefensiveContainer(); break; } break; case _GameState.SinglePlanetDefend: switch (playerNumber) { case 0: //player playerSetupSP.DisableAllGraphics(); playerControlSP.EnablePlanetDefenseControl(); playerCameraSP.EnablePlanetCameraDefender(); break; case 1: //computer opponent opponentController.EnableOffensiveContainer(); break; } break; case _GameState.MultiNeutral: playerSetup.EnableSpaceGraphics(); instance.transform.position = GameData.instance.spaceSpawnPoints[playerSetup.playerNumber].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControl.EnableSpaceControl(); playerCamera.EnableSpaceCamera(); break; case _GameState.MultiPlayerOnePlanet: switch (playerNumber) { case 0: playerSetup.DisableAllGraphics(); instance.transform.position = GameData.instance.planetSpawnPoints[0].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControl.EnablePlanetDefenseControl(); playerCamera.EnablePlanetCameraDefender(); break; case 1: playerSetup.EnablePlanetGraphics(); instance.transform.position = GameData.instance.planetSpawnPoints[0].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControl.EnablePlanetControl(); playerCamera.EnablePlanetCameraAttacker(); break; } break; case _GameState.MultiPlayerTwoPlanet: switch (playerNumber) { case 0: playerSetup.EnablePlanetGraphics(); instance.transform.position = GameData.instance.planetSpawnPoints[0].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControl.EnablePlanetControl(); playerCamera.EnablePlanetCameraAttacker(); break; case 1: playerSetup.DisableAllGraphics(); instance.transform.position = GameData.instance.planetSpawnPoints[0].position; instance.transform.rotation = Quaternion.Euler(Vector3.zero); playerControl.EnablePlanetDefenseControl(); playerCamera.EnablePlanetCameraDefender(); break; } break; } }
void OnUnitReachDestination(UnitCreep unit) { playerLife=Mathf.Max(0, playerLife-unit.lifeCost); if(onLifeE!=null) onLifeE(-unit.lifeCost); if(playerLife<=0){ if (gameState != _GameState.Over) { gameState = _GameState.Over; StopGame(false); } } }
public IEnumerator _GameWon() { ResumeGame(); //call to reset ff speed yield return new WaitForSeconds(0.0f); gameState=_GameState.Over; playerWon=true; if(onGameOverE!=null) onGameOverE(playerWon); }
private void RpcGameStateSetup(_GameState gameState) { switch (gameState) { case _GameState.MultiNeutral: GameStateMultiNeutral(); break; case _GameState.MultiPlayerOnePlanet: GameStateMultiPlayerOnePlanet(); break; case _GameState.MultiPlayerTwoPlanet: GameStateMultiPlayerTwoPlanet(); break; } }
protected override void Update(GameTime gameTime) { keyB_prev = keyB_state; // keyB_state = Keyboard.GetState(); // selection between splash screen , menu, etc. switch (_currentGameState) { case _GameState.SplashScreen: float time_pass = (float)gameTime.ElapsedGameTime.TotalSeconds; time -= time_pass; // time + 1; if (time < 0) { _isSplahon = false; _currentGameState = _GameState.PressToContinue; } break; case _GameState.PressToContinue: if (keyB_state.IsKeyDown(Keys.Enter)) { _currentGameState = _GameState.Menu; } break; case _GameState.Menu: _scoreP1 = 0; _scoreP2 = 0; // select control MenuSelection(); break; case _GameState.SinglePlayer: //p1 controller //ControlsArrow(_pallet1_position, 10.0f); AI_Mov(); if (!IsOver()) { Movements(); Score(); if (CollitionP1() || CollitionP2_AI()) { if (_move_right) { _move_right = !_move_right; _SE_hit.Play(); } else { _move_right = true; _SE_hit.Play(); } } } else { _currentGameState = _GameState.GameOver; } break; case _GameState.MultiPlayer: if (keyB_state.IsKeyDown(Keys.W)) { _pallet2_position.Y -= 10.0f; } if (keyB_state.IsKeyDown(Keys.S)) { _pallet2_position.Y += 10.0f; } Movements(); if (!IsOver()) { Movements(); Score(); if (CollitionP1() || CollitionP2_AI()) { if (_move_right) { _move_right = !_move_right; _SE_hit.Play(); } else { _move_right = true; _SE_hit.Play(); } } } else { _currentGameState = _GameState.GameOver; } break; case _GameState.Credits: if (keyB_state.IsKeyDown(Keys.Enter)) { if (KeyPressed(Keys.Enter)) { _currentGameState = _GameState.Menu; } } break; case _GameState.GameOver: if (keyB_state.IsKeyDown(Keys.Enter)) { _currentGameState = _GameState.Menu; } break; case _GameState.Exit: if (keyB_state.IsKeyDown(Keys.Enter) || keyB_state.IsKeyDown(Keys.Space)) { Exit(); } break; default: Exit(); break; } //_ball_position.X += speedX; //if (_ball_position.X > Window.ClientBounds.Width - _ball.Width || _ball_position.X < 0) //{ speedX *= -1f; } base.Update(gameTime); }
void onEnemyStatsChange( EnemyStats stats, EnemyBase._EnemyState state ) { if( state == EnemyBase._EnemyState.Dead ) { GameState = _GameState.Results; onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, stats ); DBAccess.instance.userPrefs.wins++; if( GameCenterBinding.isPlayerAuthenticated() ) GameCenterBinding.reportScore( (long)DBAccess.instance.userPrefs.wins, "Leaderboard_Win"); } }
void onPause() { // Disable Pause in Reload Mode // Bugfix hack: Pause does not release in Reload Menu. if (GameState == _GameState.Reload) { UnityEngine.Debug.Log("PlayerController.cs: Bypass Pause in Reload Menu"); return; } if( Time.timeScale == 1 ) { _cachedAxes = axes; _cachedGameState = GameState; axes = RotationAxes.None; GameState = _GameState.Paused; audioSources[10].mute = true; audioSources[11].mute = true; Time.timeScale = 0; if( Application.platform == RuntimePlatform.IPhonePlayer ) ChartBoostBinding.trackEvent( "On Pause Event" ); } else { axes = _cachedAxes; GameState = _cachedGameState; audioSources[10].mute = false; audioSources[11].mute = false; Time.timeScale = 1; } }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); if (_isSplahon) { spriteBatch.Draw(_splashcreen, new Vector2(250, 150), Color.White); } switch (_currentGameState) { case _GameState.PressToContinue: spriteBatch.Draw(_title, new Vector2(110, 15), Color.White); spriteBatch.Draw(_start, new Vector2(300, 300), Color.White); break; case _GameState.Menu: spriteBatch.Draw(_title, new Vector2(110, 15), Color.White); spriteBatch.Draw(select, _select_position[_select_pos], Color.White); spriteBatch.Draw(_single, _single_position, Color.White); spriteBatch.Draw(_multi, _multi_position, Color.White); spriteBatch.Draw(_credits, _credits_position, Color.White); spriteBatch.Draw(_exit, _exit_position, Color.White); break; case _GameState.SinglePlayer: case _GameState.MultiPlayer: if (!IsOver()) { // Update(GameTime gameTime); spriteBatch.Draw(_middle, _middle_position, Color.White); spriteBatch.Draw(_pallet_P1, _pallet1_position, Color.White); spriteBatch.Draw(_pallet_P2, _pallet2_position, Color.White); spriteBatch.Draw(_ball, _ball_position, Color.White); // dev stuff //spriteBatch.Draw(_DEV_ball, _DEV_ball_position, Color.Fuchsia); // spriteBatch.DrawString(_DEV_info, "position:" + time, new Vector2(20, 420), Color.Red); //fonts spriteBatch.DrawString(_score_fontP1, "" + _scoreP1, new Vector2(260, 60), Color.White); spriteBatch.DrawString(_score_fontP2, "" + _scoreP2, new Vector2(470, 60), Color.White); } else { _currentGameState = _GameState.GameOver; } break; case _GameState.Credits: spriteBatch.Draw(_by, new Vector2(200, 150), Color.White); break; case _GameState.GameOver: spriteBatch.Draw(_over, new Vector2(200, 100), Color.White); //this.Exit(); break; } spriteBatch.DrawString(_DEV_info, "", new Vector2(20, 420), Color.Red); spriteBatch.End(); base.Draw(gameTime); }
// Method for when hit by Enemy bullet or projectile private void hitByEnemy( EnemyStats stats ) { //Debug.Log("Player: OUCH, I GOT HIT"); iTween.ShakePosition(gameObject, iTween.Hash( "amount", new Vector3( 0.4f, 0.4f, 0.4f ), "time", 0.5f, "oncompletetarget", gameObject, "oncomplete", "resetPos" )); DBAccess.instance.userPrefs.health -= stats.damage; audioSources[Random.Range(3,5)].Play(); if( DBAccess.instance.userPrefs.health > 0 ) { if( onHitByEnemy != null ) onHitByEnemy( DBAccess.instance.userPrefs.health ); } else { if( Application.platform == RuntimePlatform.IPhonePlayer ) ChartBoostBinding.trackEvent( "Player Loss" ); if( onHitByEnemy != null ) onHitByEnemy( DBAccess.instance.userPrefs.health ); GameState = _GameState.Dead; cameraAnimNode.animation.Play("CameraDeath"); // Death Sound audioSources[7].Play(); // Stop Heartbeat audioSources[9].Stop(); // Fade Music if( audioSources[10].isPlaying ) iTween.AudioTo( gameObject, iTween.Hash( "audiosource", audioSources[10], "volume", 0f, "time", 1f, "easetype", iTween.EaseType.linear ) ); if( audioSources[11].isPlaying ) iTween.AudioTo( gameObject, iTween.Hash( "audiosource", audioSources[11], "volume", 0, "time", 1f, "easetype", iTween.EaseType.linear ) ); GameObject.Find("Crosshair").GetComponent<UISprite>().enabled = false; StartCoroutine( deathRoutine() ); onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, stats ); } int randRange = Random.Range( 0, 101 ); if( randRange < 33 ) splatCam.onHitByRayCast(); }
void Update() { if (isCalibrating) { if (Input.GetMouseButtonUp(0)) { Ray ray = UICam2D.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { if (hit.collider.name == "WindowBG(Calibrate)") { hit.collider.SendMessage("onHitByRayCast", this, SendMessageOptions.DontRequireReceiver); CalibrateAccelerometer(); } } } } if (!isCalibrating) { #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX if (GameState != _GameState.Dead && GameState != _GameState.Results && GameState != _GameState.None && GameState != _GameState.Paused) { if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationX = ClampAngle(rotationX, ROTATION_MIN_Y, ROTATION_MAX_Y); rotationY = ClampAngle(rotationY, ROTATION_MIN_X, ROTATION_MAX_X); Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, -Vector3.right); transform.localRotation = originalRotation * xQuaternion * yQuaternion; } else if (axes == RotationAxes.MouseX) { rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationX = ClampAngle(rotationX, ROTATION_MIN_Y, ROTATION_MAX_Y); Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); transform.localRotation = originalRotation * xQuaternion; } else { rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationY = ClampAngle(rotationY, ROTATION_MIN_X, ROTATION_MAX_X); Quaternion yQuaternion = Quaternion.AngleAxis(-rotationY, Vector3.right); transform.localRotation = originalRotation * yQuaternion; } if (rotationY < -25f && GameState != _GameState.Reload && GameState != _GameState.IsReloading) { GameState = _GameState.Reload; lastAmmoHit = null; if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } gunModel.animation.Stop(); gunModel.animation.Play("ReloadStart"); } if (rotationY > -25f && (GameState == _GameState.Reload || GameState == _GameState.IsReloading)) { if (!DBAccess.instance.userPrefs.userGun.isReloading) { GameState = _GameState.Active; if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } if (lastAmmoHit == null) { gunModel.animation.Play("ReloadEnd"); } else if (lastAmmoHit != null && lastAmmoHit.name != "ActiveAmmo") { gunModel.animation.Play("ReloadEnd"); } } else { if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } } } } #elif UNITY_IPHONE || UNITY_ANDROID if (GameState != _GameState.Dead && GameState != _GameState.Results && GameState != _GameState.None && GameState != _GameState.Paused) { if (axes == RotationAxes.MouseXAndY) { // Store movement into temporary Vector3 to be applied to transform localRotation.y -= Input.acceleration.y * speed; localRotation.x += FixAcceleration(Input.acceleration).x *speed; // Clamp rotation within set field of view localRotation.y = ClampAngle(localRotation.y, ROTATION_MIN_Y, ROTATION_MAX_Y); localRotation.x = ClampAngle(localRotation.x, ROTATION_MIN_X, ROTATION_MAX_X); //Debug.Log( "Y : " + localRotation.y ); //Debug.Log( "X : " + localRotation.x ); // Apply new cached rotation to transform rotation transform.localEulerAngles = localRotation; } else if (axes == RotationAxes.MouseX) { localRotation.y -= Input.acceleration.y * speed; localRotation.y = ClampAngle(localRotation.y, ROTATION_MIN_Y, ROTATION_MAX_Y); transform.localEulerAngles = localRotation; } else if (axes == RotationAxes.MouseY) { localRotation.x += FixAcceleration(Input.acceleration).x *speed; localRotation.x = ClampAngle(localRotation.x, ROTATION_MIN_X, ROTATION_MAX_X); transform.localEulerAngles = localRotation; } if (localRotation.x > 25f && GameState != _GameState.Reload && GameState != _GameState.IsReloading) { GameState = _GameState.Reload; lastAmmoHit = null; if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } gunModel.animation.Play("ReloadStart"); } if (localRotation.x < 25f && (GameState == _GameState.Reload || GameState == _GameState.IsReloading)) { if (!DBAccess.instance.userPrefs.userGun.isReloading) { GameState = _GameState.Active; if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } if (lastAmmoHit == null) { gunModel.animation.Play("ReloadEnd"); } else if (lastAmmoHit != null && lastAmmoHit.name != "ActiveAmmo") { gunModel.animation.Play("ReloadEnd"); } } else { if (onUIUpdate != null) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); } } } } #endif if (Input.GetMouseButtonUp(0)) { if (GameState == _GameState.Active || GameState == _GameState.Paused) { // If user hits ammo sprite, reload instead of shooting Ray ray = UICam.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, UIMask3D)) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null); lastAmmoHit = hit.collider.gameObject; } else if (DBAccess.instance.userPrefs.userGun.capacity > 0 && GameState == _GameState.Active) { // If not in reload or pause, shoot gun. Gun will take care of bullets remaining logic. if (DBAccess.instance.userPrefs.userGun.model == "Winchester_1912") { DBAccess.instance.userPrefs.userGun.ShootShotgun(transform, capsulCastMask, gunModel); } else { DBAccess.instance.userPrefs.userGun.Shoot(transform, rayCastmask, gunModel); } onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); BroadcastMessage("applyRecoil"); if (DBAccess.instance.userPrefs.userGun.gunID == 1) { audioSources[0].Play(); } if (DBAccess.instance.userPrefs.userGun.gunID == 2) { audioSources[1].Play(); } if (DBAccess.instance.userPrefs.userGun.gunID == 3) { audioSources[2].Play(); } } else if (GameState == _GameState.Active) { audioSources[6].Play(); } } if (GameState == _GameState.Reload || GameState == _GameState.Results || GameState == _GameState.Dead || GameState == _GameState.None) { if (Application.platform == RuntimePlatform.IPhonePlayer) { ChartBoostBinding.trackEvent("Secondary Reload Screen Use"); } Ray ray = UICam.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, UIMask3D)) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null); lastAmmoHit = hit.collider.gameObject; } } if (GameState == _GameState.Dead || GameState == _GameState.Results) { Ray ray = UICam2D.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null); } } } } }
// Method for when hit by Enemy bullet or projectile private void hitByEnemy(EnemyStats stats) { //Debug.Log("Player: OUCH, I GOT HIT"); iTween.ShakePosition(gameObject, iTween.Hash( "amount", new Vector3(0.4f, 0.4f, 0.4f), "time", 0.5f, "oncompletetarget", gameObject, "oncomplete", "resetPos" )); DBAccess.instance.userPrefs.health -= stats.damage; audioSources[Random.Range(3, 5)].Play(); if (DBAccess.instance.userPrefs.health > 0) { if (onHitByEnemy != null) { onHitByEnemy(DBAccess.instance.userPrefs.health); } } else { if (Application.platform == RuntimePlatform.IPhonePlayer) { ChartBoostBinding.trackEvent("Player Loss"); } if (onHitByEnemy != null) { onHitByEnemy(DBAccess.instance.userPrefs.health); } GameState = _GameState.Dead; cameraAnimNode.animation.Play("CameraDeath"); // Death Sound audioSources[7].Play(); // Stop Heartbeat audioSources[9].Stop(); // Fade Music if (audioSources[10].isPlaying) { iTween.AudioTo(gameObject, iTween.Hash( "audiosource", audioSources[10], "volume", 0f, "time", 1f, "easetype", iTween.EaseType.linear ) ); } if (audioSources[11].isPlaying) { iTween.AudioTo(gameObject, iTween.Hash( "audiosource", audioSources[11], "volume", 0, "time", 1f, "easetype", iTween.EaseType.linear ) ); } GameObject.Find("Crosshair").GetComponent <UISprite>().enabled = false; StartCoroutine(deathRoutine()); onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, stats); } int randRange = Random.Range(0, 101); if (randRange < 33) { splatCam.onHitByRayCast(); } }
void OnWaveCleared(int waveID) { Debug.Log("Wave "+waveID+" has been cleared"); if(waveID==totalWaveCount-1){ //game over, player won gameState=_GameState.Ended; if(onGameOverE!=null) onGameOverE(true); } }
void onReloadStart( float timeToReload, Gun gun ) { GameState = _GameState.IsReloading; if( DBAccess.instance.userPrefs.userGun.model != "Winchester_1912") audioSources[5].Play(); else audioSources[12].Play(); }
void OnWaveStartSpawned(int waveID) { currentWave+=1; //if game is not yet started, start it now if(gameState==_GameState.Idle) gameState=_GameState.Started; }
void _ControlObjectHit() { playerLife=Mathf.Max(0, playerLife-1); if(onLifeE!=null) onLifeE(-1); if(playerLife<=0){ if (gameState != _GameState.Over) { gameState=_GameState.Over; StopGame(false); } } }
void Update () { if( isCalibrating ) { if( Input.GetMouseButtonUp(0) ) { Ray ray = UICam2D.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100f ) ) { if( hit.collider.name == "WindowBG(Calibrate)" ) { hit.collider.SendMessage( "onHitByRayCast", this, SendMessageOptions.DontRequireReceiver ); CalibrateAccelerometer(); } } } } if( !isCalibrating ) { #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX if( GameState != _GameState.Dead && GameState != _GameState.Results && GameState != _GameState.None && GameState != _GameState.Paused) { if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationX = ClampAngle (rotationX, ROTATION_MIN_Y, ROTATION_MAX_Y); rotationY = ClampAngle (rotationY, ROTATION_MIN_X, ROTATION_MAX_X); Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right); transform.localRotation = originalRotation * xQuaternion * yQuaternion; } else if (axes == RotationAxes.MouseX) { rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationX = ClampAngle (rotationX, ROTATION_MIN_Y, ROTATION_MAX_Y); Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); transform.localRotation = originalRotation * xQuaternion; } else { rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationY = ClampAngle (rotationY, ROTATION_MIN_X, ROTATION_MAX_X); Quaternion yQuaternion = Quaternion.AngleAxis (-rotationY, Vector3.right); transform.localRotation = originalRotation * yQuaternion; } if( rotationY < -25f && GameState != _GameState.Reload && GameState != _GameState.IsReloading ) { GameState = _GameState.Reload; lastAmmoHit = null; if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); gunModel.animation.Stop(); gunModel.animation.Play("ReloadStart"); } if( rotationY > -25f && ( GameState == _GameState.Reload || GameState == _GameState.IsReloading ) ) { if( !DBAccess.instance.userPrefs.userGun.isReloading ) { GameState = _GameState.Active; if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); if( lastAmmoHit == null ) gunModel.animation.Play("ReloadEnd"); else if( lastAmmoHit != null && lastAmmoHit.name != "ActiveAmmo" ) gunModel.animation.Play("ReloadEnd"); } else { if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); } } } #elif UNITY_IPHONE || UNITY_ANDROID if( GameState != _GameState.Dead && GameState != _GameState.Results && GameState != _GameState.None && GameState != _GameState.Paused ) { if( axes == RotationAxes.MouseXAndY ) { // Store movement into temporary Vector3 to be applied to transform localRotation.y -= Input.acceleration.y * speed; localRotation.x += FixAcceleration( Input.acceleration ).x * speed; // Clamp rotation within set field of view localRotation.y = ClampAngle( localRotation.y, ROTATION_MIN_Y, ROTATION_MAX_Y ); localRotation.x = ClampAngle( localRotation.x, ROTATION_MIN_X, ROTATION_MAX_X ); //Debug.Log( "Y : " + localRotation.y ); //Debug.Log( "X : " + localRotation.x ); // Apply new cached rotation to transform rotation transform.localEulerAngles = localRotation; } else if( axes == RotationAxes.MouseX ) { localRotation.y -= Input.acceleration.y * speed; localRotation.y = ClampAngle( localRotation.y, ROTATION_MIN_Y, ROTATION_MAX_Y ); transform.localEulerAngles = localRotation; } else if( axes == RotationAxes.MouseY ) { localRotation.x += FixAcceleration( Input.acceleration ).x * speed; localRotation.x = ClampAngle( localRotation.x, ROTATION_MIN_X, ROTATION_MAX_X ); transform.localEulerAngles = localRotation; } if( localRotation.x > 25f && GameState != _GameState.Reload && GameState != _GameState.IsReloading ) { GameState = _GameState.Reload; lastAmmoHit = null; if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); gunModel.animation.Play("ReloadStart"); } if( localRotation.x < 25f && ( GameState == _GameState.Reload || GameState == _GameState.IsReloading ) ) { if( !DBAccess.instance.userPrefs.userGun.isReloading ) { GameState = _GameState.Active; if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); if( lastAmmoHit == null ) gunModel.animation.Play("ReloadEnd"); else if( lastAmmoHit != null && lastAmmoHit.name != "ActiveAmmo" ) gunModel.animation.Play("ReloadEnd"); } else { if( onUIUpdate != null ) onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, null, null ); } } } #endif if( Input.GetMouseButtonUp(0) ) { if( GameState == _GameState.Active || GameState == _GameState.Paused ) { // If user hits ammo sprite, reload instead of shooting Ray ray = UICam.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100f, UIMask3D ) ) { onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null ); lastAmmoHit = hit.collider.gameObject; } else if( DBAccess.instance.userPrefs.userGun.capacity > 0 && GameState == _GameState.Active ) { // If not in reload or pause, shoot gun. Gun will take care of bullets remaining logic. if( DBAccess.instance.userPrefs.userGun.model == "Winchester_1912") DBAccess.instance.userPrefs.userGun.ShootShotgun( transform, capsulCastMask, gunModel ); else DBAccess.instance.userPrefs.userGun.Shoot(transform,rayCastmask,gunModel); onUIUpdate(DBAccess.instance.userPrefs.userGun, GameState, null, null); BroadcastMessage( "applyRecoil" ); if( DBAccess.instance.userPrefs.userGun.gunID == 1 ) audioSources[0].Play(); if( DBAccess.instance.userPrefs.userGun.gunID == 2 ) audioSources[1].Play(); if( DBAccess.instance.userPrefs.userGun.gunID == 3 ) audioSources[2].Play(); } else if( GameState == _GameState.Active ) audioSources[6].Play(); } if( GameState == _GameState.Reload || GameState == _GameState.Results || GameState == _GameState.Dead || GameState == _GameState.None ) { if( Application.platform == RuntimePlatform.IPhonePlayer ) ChartBoostBinding.trackEvent( "Secondary Reload Screen Use" ); Ray ray = UICam.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100f, UIMask3D ) ) { onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null ); lastAmmoHit = hit.collider.gameObject; } } if( GameState == _GameState.Dead || GameState == _GameState.Results ) { Ray ray = UICam2D.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100f ) ) { onUIUpdate( DBAccess.instance.userPrefs.userGun, GameState, hit.collider.gameObject, null ); } } } } }
public IEnumerator _StopGame(bool isWin) { Time.timeScale=1; FPSControl.Hide(); yield return new WaitForSeconds(0.0f); gameState=_GameState.Over; playerWon=isWin; if(onGameOverE!=null) onGameOverE(playerWon, playerScore); }
void OnUnitReachDestination(UnitCreep unit) { playerLife=Mathf.Max(0, playerLife-unit.lifeCost); if(onLifeE!=null) onLifeE(-unit.lifeCost); if(playerLife<=0){ gameState=_GameState.Over; if(onGameOverE!=null) onGameOverE(playerWon); } }
public IEnumerator _GameOver(bool won) { if(gameOver) yield break; //stop the coroutine if it has already been called gameOver=true; Debug.Log("game over - "+(won ? "win" : "lost")); //delay 1.5 second before issuing a global gameover event yield return new WaitForSeconds(1.5f); gameState=_GameState.GameOver; TDS.GameOver(won); }