Esempio n. 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.J))
        {
            playerAnimation.Defend(true);
            shield.ActivateShield(true);
        }

        if (Input.GetKeyUp(KeyCode.J))
        {
            playerAnimation.UnFreezeAnimation();
            playerAnimation.Defend(false);
            shield.ActivateShield(false);
        }

        if (Input.GetKeyDown(KeyCode.K))
        {
            if (Random.Range(0, 2) > 0)
            {
                playerAnimation.Attack_1();
                soundFX.Attack1();
            }
            else
            {
                playerAnimation.Attack_2();
                soundFX.Attack2();
            }
        }
    }
Esempio n. 2
0
    } // awake

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.J)) // defend
        {
            playerAnimation.Defend(true);

            shield.ActivateShield(true);
        }
        if (Input.GetKeyUp(KeyCode.J)) // defend
        {
            playerAnimation.UnfreezeAnimation();
            playerAnimation.Defend(false);

            shield.ActivateShield(false);
        }

        if (Input.GetKeyDown(KeyCode.K)) // attack
        {
            if (Random.Range(0, 2) > 0)  // Range(inclusive, exclusive) but with float the second param is included
            {
                playerAnimation.Attack_1();
                soundFx.Attack1();
            }
            else
            {
                playerAnimation.Attack_2();
                soundFx.Attack2();
            }
        }
    } // update
Esempio n. 3
0
    void defend()
    {
        CharacterAnimations component = enemyAnimation.GetComponent <CharacterAnimations>();

        playerAnimation.Defend(true);

        shield.ActivateShield(true);

        component.Damage(true);
        StartCoroutine(desactive());
    }
Esempio n. 4
0
    //Function that grabs velocity from the asteroid object and stores it in a var, applies damage to player if velocity is high enough, calculates a force, and subtracts that force from player health
    //Function also calculates if asteroid and player are moving away from each other or are facing
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "SceneLoader")
        {
            SceneManager.LoadScene("TitleMenu");
        }
        else if (col.gameObject.name == "AsteroidPlaceholder")
        {
            float _directionStatus;
            _asteroidInput     = col.gameObject;
            _asteroidRigidbody = _asteroidInput.GetComponent <Rigidbody2D>( );
            _asteroidVelocity  = _asteroidRigidbody.velocity.magnitude;

            //Get direction vector from asteroid to player
            asteroidDirection = (col.transform.position - transform.position).normalized;

            //Find the Dot to see if they are facing the same way, facing opposite ways, etc..
            _directionStatus = Vector2.Dot(asteroidDirection, _asteroidRigidbody.velocity.normalized);

            if (_asteroidVelocity > _asteroidMinimum && _directionStatus >= 0f)             //temporarily set to if the asteroid is moving, it deals damage automatically
            {
                _playerDamaged       = true;
                _asteroidDamageForce = _asteroidVelocity * _ASTEROIDFORCECONSTANT * _directionStatus;                 //Damage to scale; Need requirements for damage
                _tempHealth          = _tempHealth - _asteroidDamageForce;
                print(_playerDamaged);
                print("Velocity= " + _asteroidVelocity);
                print("Player health= " + _tempHealth);
            }
        }
        else if (col.gameObject.name == "Bullet" || col.gameObject.name == "ImprovedBullet")
        {
            float _directionStatus;
            _asteroidInput     = col.gameObject;
            _asteroidRigidbody = _asteroidInput.GetComponent <Rigidbody2D>();
            _asteroidVelocity  = _asteroidRigidbody.velocity.magnitude;

            //Get direction vector from asteroid to player
            asteroidDirection = (col.transform.position - transform.position).normalized;

            //Find the Dot to see if they are facing the same way, facing opposite ways, etc..
            _directionStatus = Vector2.Dot(asteroidDirection, _asteroidRigidbody.velocity.normalized);

            if (_asteroidVelocity > _asteroidMinimum && _directionStatus >= 0f) //temporarily set to if the asteroid is moving, it deals damage automatically
            {
                _playerDamaged       = true;
                _asteroidDamageForce = _asteroidVelocity * _ASTEROIDFORCECONSTANT * _directionStatus; //Damage to scale; Need requirements for damage
                _tempHealth          = _tempHealth - _asteroidDamageForce;
                print(_playerDamaged);
                print("Velocity= " + _asteroidVelocity);
                print("Player health= " + _tempHealth);
            }
        }
        //activate player shield
        if (shield != null)
        {
            //activate shield, send info if player was damaged
            shield.ActivateShield(_playerDamaged);
        }
    }
    void Awake()
    {
        playerAnimation = GetComponent <CharacterAnimations>();
        shield          = GetComponent <PlayerShield>();
        shield.ActivateShield(false);

        soundFX = GetComponentInChildren <CharacterSoundFX>();
    }
Esempio n. 6
0
 public void ActivatePlayerShield(bool damageDealt)
 {
     //activate player shield
     if (shield != null)
     {
         //activate shield, send info if player was damaged
         shield.ActivateShield(damageDealt);
     }
 }