Пример #1
0
 public void Inject(PlayerUnitDI di)
 {
     stateMachine  = di.stateMachine;
     physics       = di.physics;
     flip          = di.flip;
     vulnerability = di.vulnerability;
 }
Пример #2
0
    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);
            }
        }
    }
Пример #3
0
 public void Inject(PlayerUnitDI di)
 {
     physics       = di.physics;
     stateMachine  = di.stateMachine;
     hp            = di.hp;
     vulnerability = di.vulnerability;
 }
Пример #4
0
    //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();
    }
Пример #5
0
    //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);
        }
    }
Пример #6
0
    //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));
    }
Пример #7
0
    //Activates the extra speed submarine effects
    public void ActivateExtraSpeed()
    {
        extraSpeedFront.gameObject.SetActive(true);
        extraSpeedTail.gameObject.SetActive(true);
        RaiseShield();

        playerVulnerability = PlayerVulnerability.Disabled;
        powerupUsage        = PowerupUsage.Disabled;
    }
Пример #8
0
 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;
    }
Пример #10
0
    //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));
    }
Пример #11
0
    //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));
    }
Пример #12
0
    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];
    }
Пример #13
0
    //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;
    }
Пример #14
0
    //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;

        StartCoroutine(FunctionLibrary.ScaleTo(shield, new Vector2(0, 0), 0.25f));
        StartCoroutine(EnableVulnerability(0.3f));
    }
Пример #16
0
    //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;
    }
    //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;
    }
    //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));
    }
    //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));
    }
Пример #24
0
    //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);
    }