public void Inject(PlayerUnitDI di) { stateMachine = di.stateMachine; physics = di.physics; flip = di.flip; vulnerability = di.vulnerability; }
private void AttackPlayer(PlayerUnitController player) { PlayerVulnerability vulnerability = player.di.vulnerability; Vector2 lookVector = new Vector2(physics.flip.Direction.ToFloat(), 1); if (vulnerability.IsGuardingInOpposingDirection(physics.flip.Direction)) { float recoilTileForce; if (IsFullAssembly(player)) { stateMachine.attack.StartStagger(); recoilTileForce = data.guardFullAssemblyRecoilTileForce; // TODO: short stagger? } else { recoilTileForce = data.guardPartialAssemblyRecoilTileForce; Vector2 playerRecoil = RecoilHelpers.GetRecoilFromTo(player.transform, controller.transform, recoilTileForce); player.di.stateMachine.SetRecoilState(playerRecoil); } } else if (vulnerability.IsVulnerable()) { PlayerDamageModule damage = player.di.damage; Vector2 collisionRecoil = RecoilHelpers.GetRecoilNormalFromTo(player.transform, controller.transform); if (IsFullAssembly(player)) { damage.TakeDamage(data.attackDamage, TileHelpers.TileToWorld(data.attackFullAssemblyRecoilTileForce) * collisionRecoil); } else { damage.TakeDamage(data.attackDamage, TileHelpers.TileToWorld(data.attackPartialAssemblyRecoilTileForce) * collisionRecoil); } } }
public void Inject(PlayerUnitDI di) { physics = di.physics; stateMachine = di.stateMachine; hp = di.hp; vulnerability = di.vulnerability; }
//Revives the player, and moves the submarine upward private IEnumerator ReviveProcess() { //Change the texture to intact, and play the revive particle subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; reviveParticle.Play(); //Reset rotation, and move the submarine up newRotation = new Vector3(0, 0, 0); this.transform.eulerAngles = newRotation; StartCoroutine(FunctionLibrary.MoveElementBy(this.transform, new Vector2(0, Mathf.Abs(this.transform.position.y - maxDepth)), 0.5f)); yield return(new WaitForSeconds(0.5f)); //Reset states playerStatus = PlayerStatus.Idle; playerState = PlayerState.Enabled; playerVulnerability = PlayerVulnerability.Enabled; bubbles.Play(); yield return(new WaitForSeconds(0.5f)); powerupUsage = PowerupUsage.Enabled; reviveParticle.Clear(); }
//Called when the player enters a triggerer zone void OnTriggerEnter2D(Collider2D other) { //If the submarine is collided with a coin if (other.tag == "Coin") { //Notify the level manager, and disable the coin's renderer and collider levelManager.CoinCollected(other.transform.position); other.GetComponent <Renderer>().enabled = false; other.GetComponent <Collider2D>().enabled = false; AudioManager.Instance.PlayCoinCollected(); } //If the submarine is collided with an obstacle else if (other.tag == "Obstacle") { //Notify the level manager, and disable the obstacle's renderer and collider levelManager.Collision(other.name, other.transform.position); other.GetComponent <Renderer>().enabled = false; other.GetComponent <Collider2D>().enabled = false; AudioManager.Instance.PlayExplosion(); //If the obstacle is a torpedo, disable it's child as well if (other.name == "Torpedo") { other.transform.FindChild("TorpedoFire").gameObject.SetActive(false); } //If the player is vulnerable if (playerVulnerability == PlayerVulnerability.Enabled) { //Sink the submarine powerupUsage = PowerupUsage.Disabled; playerVulnerability = PlayerVulnerability.Disabled; playerStatus = PlayerStatus.Sinking; subRenderer.sprite = subTextures[currentSkinID * 2]; bubbles.Stop(); } //If the player is shielded, collapse it else if (playerVulnerability == PlayerVulnerability.Shielded) { CollapseShield(); guiManager.ShowAvailablePowerups(); } } //If the submarine is collided with a powerup else if (other.tag == "Powerup") { //Notify the level manager, and disable the powerup's components other.GetComponent <Renderer>().enabled = false; other.GetComponent <Collider2D>().enabled = false; other.transform.FindChild("Trail").gameObject.SetActive(false); AudioManager.Instance.PlayPowerupCollected(); levelManager.PowerupPickup(other.name); } }
//Raises the shield public void RaiseShield() { playerVulnerability = PlayerVulnerability.Shielded; normalCollider.enabled = false; shieldCollider.enabled = true; StartCoroutine(FunctionLibrary.ScaleTo(shield, new Vector2(1, 1), 0.25f)); }
//Activates the extra speed submarine effects public void ActivateExtraSpeed() { extraSpeedFront.gameObject.SetActive(true); extraSpeedTail.gameObject.SetActive(true); RaiseShield(); playerVulnerability = PlayerVulnerability.Disabled; powerupUsage = PowerupUsage.Disabled; }
public void Inject(PlayerUnitDI di) { stateMachine = di.stateMachine; this.di = di; physics = di.physics; movement = di.abilities.movement; respawnHandler = di.respawnHandler; vulnerability = di.vulnerability; }
private Vector2 startingPos; //Holds the starting position of the submarine #endregion Fields #region Methods //Activates the extra speed submarine effects public void ActivateExtraSpeed() { extraSpeedFront.gameObject.SetActive(true); extraSpeedTail.gameObject.SetActive(true); RaiseShield(); playerVulnerability = PlayerVulnerability.Disabled; powerupUsage = PowerupUsage.Disabled; }
//Collapses the shield public void CollapseShield() { playerVulnerability = PlayerVulnerability.Disabled; normalCollider.enabled = true; shieldCollider.enabled = false; StartCoroutine(FunctionLibrary.ScaleTo(shield, new Vector2(0, 0), 0.25f)); StartCoroutine(EnableVulnerability(0.3f)); }
//Enables the submarine public void EnableSubmarine() { playerStatus = PlayerStatus.Idle; playerState = PlayerState.Enabled; playerVulnerability = PlayerVulnerability.Enabled; powerupUsage = PowerupUsage.Enabled; subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; bubbles.Play(); StartCoroutine(FunctionLibrary.MoveElementBy(this.transform, new Vector2(0.4f, 0.2f), 0.5f)); }
private Vector2 startingPos; //Holds the starting position of the submarine //Used for initialization void Start() { newRotation = new Vector3(); startingPos = this.transform.position; playerStatus = PlayerStatus.Idle; playerState = PlayerState.Disabled; playerVulnerability = PlayerVulnerability.Disabled; powerupUsage = PowerupUsage.Disabled; rotationDiv = maxVerticalSpeed / maxRotation; currentSkinID = SaveManager.currentSkinID; subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; }
//Resets the submarine public void Reset() { playerStatus = PlayerStatus.Idle; playerState = PlayerState.Disabled; playerVulnerability = PlayerVulnerability.Disabled; powerupUsage = PowerupUsage.Disabled; newRotation = new Vector3(0, 0, 0); subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; bubbles.Stop(); bubbles.Clear(); this.transform.position = startingPos; this.transform.eulerAngles = newRotation; }
//Enables player vulnerability after time private IEnumerator EnableVulnerability(float time) { //Declare variables, get the starting position, and move the object float i = 0.0f; float rate = 1.0f / time; while (i < 1.0) { //If the game is not paused, increase t if (playerState == PlayerState.Enabled) { i += Time.deltaTime * rate; } //Wait for the end of frame yield return(0); } playerVulnerability = PlayerVulnerability.Enabled; }
//Raises the shield public void RaiseShield() { // playerVulnerability = PlayerVulnerability.Shielded; // normalCollider.enabled = false; // shieldCollider.enabled = true; //StartCoroutine(FunctionLibrary.ScaleTo(shield, new Vector2(1, 1), 0.25f)); //---------------------------------- playerVulnerability = PlayerVulnerability.Shielded; normalCollider.enabled = false; shieldCollider.enabled = true; Invoke("CollapseShield", 1f); }
//Used for initialization void Start() { newRotation = new Vector3(); startingPos = this.transform.position; playerStatus = PlayerStatus.Idle; playerState = PlayerState.Disabled; playerVulnerability = PlayerVulnerability.Disabled; powerupUsage = PowerupUsage.Disabled; rotationDiv = maxVerticalSpeed / maxRotation; currentSkinID = SaveManager.currentSkinID; subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; }
//Revives the player, and moves the submarine upward private IEnumerator ReviveProcess() { //Change the texture to intact, and play the revive particle subRenderer.sprite = subTextures[currentSkinID * 2 + 1]; reviveParticle.Play(); //Reset rotation, and move the submarine up newRotation = new Vector3(0, 0, 0); this.transform.eulerAngles = newRotation; StartCoroutine(FunctionLibrary.MoveElementBy(this.transform, new Vector2(0, Mathf.Abs(this.transform.position.y - maxDepth)), 0.5f)); yield return new WaitForSeconds(0.5f); //Reset states playerStatus = PlayerStatus.Idle; playerState = PlayerState.Enabled; playerVulnerability = PlayerVulnerability.Enabled; bubbles.Play(); yield return new WaitForSeconds(0.5f); powerupUsage = PowerupUsage.Enabled; reviveParticle.Clear(); }
//Called when the player enters a triggerer zone void OnTriggerEnter2D(Collider2D other) { //If the submarine is collided with a coin if (other.tag == "Coin") { //Notify the level manager, and disable the coin's renderer and collider levelManager.CoinCollected(other.transform.position); other.GetComponent<Renderer>().enabled = false; other.GetComponent<Collider2D>().enabled = false; AudioManager.Instance.PlayCoinCollected(); } //If the submarine is collided with an obstacle else if (other.tag == "Obstacle") { //Notify the level manager, and disable the obstacle's renderer and collider levelManager.Collision(other.name, other.transform.position); other.GetComponent<Renderer>().enabled = false; other.GetComponent<Collider2D>().enabled = false; AudioManager.Instance.PlayExplosion(); //If the obstacle is a torpedo, disable it's child as well if (other.name == "Torpedo") other.transform.FindChild("TorpedoFire").gameObject.SetActive(false); //If the player is vulnerable if (playerVulnerability == PlayerVulnerability.Enabled) { //Sink the submarine powerupUsage = PowerupUsage.Disabled; playerVulnerability = PlayerVulnerability.Disabled; playerStatus = PlayerStatus.Sinking; subRenderer.sprite = subTextures[currentSkinID * 2]; bubbles.Stop(); } //If the player is shielded, collapse it else if (playerVulnerability == PlayerVulnerability.Shielded) { CollapseShield(); guiManager.ShowAvailablePowerups(); } } //If the submarine is collided with a powerup else if (other.tag == "Powerup") { //Notify the level manager, and disable the powerup's components other.GetComponent<Renderer>().enabled = false; other.GetComponent<Collider2D>().enabled = false; other.transform.FindChild("Trail").gameObject.SetActive(false); AudioManager.Instance.PlayPowerupCollected(); levelManager.PowerupPickup(other.name); } }
//Enables player vulnerability after time private IEnumerator EnableVulnerability(float time) { //Declare variables, get the starting position, and move the object float i = 0.0f; float rate = 1.0f / time; while (i < 1.0) { //If the game is not paused, increase t if (playerState == PlayerState.Enabled) i += Time.deltaTime * rate; //Wait for the end of frame yield return 0; } playerVulnerability = PlayerVulnerability.Enabled; }
//Collapses the shield public void CollapseShield() { playerVulnerability = PlayerVulnerability.Disabled; normalCollider.enabled = true; shieldCollider.enabled = false; gonzo.gameObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f); //StartCoroutine(FunctionLibrary.ScaleTo(shield, new Vector2(0, 0), 0.25f)); // StartCoroutine(EnableVulnerability(0.3f)); //guiManager.setTimeScale(1f); }