Esempio n. 1
0
    private void Start()
    {
        hp = maxHp;
        healthBar.ChangeHealth(hp, maxHp);

        target = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
        sp     = GetComponent <SpriteRenderer>();
    }
Esempio n. 2
0
    private void Start()
    {
        rb   = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();

        //health init
        hp = maxHp;
        healthBar.ChangeHealth(hp, maxHp);
    }
Esempio n. 3
0
 public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
 {
     
     healthBar.Update(new Vector2(position.X, position.Y - sprite.Height / 2 - 10));
     healthBar.ChangeHealth((float)((health / maxHealth) * 1.5));
     if(!IsDark)
     healthBar.Draw(gameTime, spriteBatch);
     position -= new Vector2(0, sprite.Height / 2 - new Tile().Sprite.Height / 2);
     base.Draw(gameTime, spriteBatch);
     position += new Vector2(0, sprite.Height / 2 - new Tile().Sprite.Height / 2);
 }
Esempio n. 4
0
    public void TakeDamage(int damage)
    {
        float percentageDamage = (damage / health) * -1f;

        healthBar.ChangeHealth(percentageDamage);
        //health -= damage;
        if (health <= 0)
        {
            Die();
        }
    }
Esempio n. 5
0
 public void TakeDamage(float damage)
 {
     if (!invulnerable)
     {
         playerHealth -= damage;
         healthBar.ChangeHealth(playerHealth);
         if (playerHealth < 10)
         {
             indicatorText.ShowText("Health Low!", 2);
         }
     }
 }
Esempio n. 6
0
 public void Damage(float dmg, Vector3 position, Vector3 force)
 {
     health -= dmg;
     hpBar.ChangeHealth(health / startHealth);
     if (health <= 0)
     {
         health = 0;
         Destroy(this.gameObject);
         //Effects and stuff here
         Instantiate(deadModel, transform.position, transform.rotation);
     }
 }
Esempio n. 7
0
 void OnTriggerEnter(Collider collider)
 {
     if ((collider.gameObject.CompareTag("Projectile") && collider.gameObject.GetComponent <BasicProjectile> ().owner == BasicProjectile.Owner.Player) || (!gameObject.CompareTag("Friendly") && collider.gameObject.CompareTag("Player")))
     {
         //player projectile or player collide with Enemy
         if (!colliding)               //prevent multiple collisions per frame
         {
             colliding = true;
             float damage;
             if (collider.gameObject.CompareTag("Player"))
             {
                 damage = healthBar.health;                        //kill self if hit player, player takes damage equal to current health
                 EnemyController.Instance.EnemyKilled(gameObject); //remove enemy from screen
                 if (PlayerController.Instance.health > 0)
                 {
                     PlayerController.Instance.EnemyKilled();                          //add score if player isn't dead
                     LevelController.Instance.EnemyKilled();
                     PickupController.Instance.NewPickup(transform.position);
                 }
             }
             else
             {
                 damage = collider.gameObject.GetComponent <BasicProjectile> ().Damage;
                 //if (projectiles != null)
                 //projectiles.Remove (collider.gameObject); //remove from list
                 Destroy(collider.gameObject);                      //destroy projectile
                 healthBar.ChangeHealth(-damage);
                 healthBar.UpdateHealthBar();
                 if (healthBar.isDead())
                 {
                     LevelController.Instance.EnemyKilled();
                     EnemyController.Instance.EnemyKilled(gameObject);
                     PlayerController.Instance.EnemyKilled();
                     PickupController.Instance.NewPickup(transform.position);
                 }
             }
         }
     }
 }
Esempio n. 8
0
 void OnTriggerEnter(Collider collider)
 {
     if ((collider.gameObject.CompareTag("Projectile") && collider.gameObject.GetComponent <BasicProjectile> ().owner == BasicProjectile.Owner.Player) || (!gameObject.CompareTag("Friendly") && collider.gameObject.CompareTag("Player")))
     {
         //Disparo do Jogador colide com o inimigo.
         if (!colliding)               //Previne varias colisoes por Frame
         {
             colliding = true;
             float damage;
             if (collider.gameObject.CompareTag("Player"))
             {
                 damage = healthBar.health;                        //Mata Jogador se o Dano for igual á vida do Jogador
                 EnemyController.Instance.EnemyKilled(gameObject); //Retira inimigos do ecra
                 if (PlayerController.Instance.health > 0)
                 {
                     PlayerController.Instance.EnemyKilled();                          //Adiciona Resultado se o jogador nao estiver morto
                     LevelController.Instance.EnemyKilled();
                     PickupController.Instance.NewPickup(transform.position);
                 }
             }
             else
             {
                 damage = collider.gameObject.GetComponent <BasicProjectile> ().Damage;
                 //if (projectiles != null)
                 //projectiles.Remove (collider.gameObject); //remove from list
                 Destroy(collider.gameObject);                      //destroy projectile
                 healthBar.ChangeHealth(-damage);
                 healthBar.UpdateHealthBar();
                 if (healthBar.isDead())
                 {
                     LevelController.Instance.EnemyKilled();
                     EnemyController.Instance.EnemyKilled(gameObject);
                     PlayerController.Instance.EnemyKilled();
                     PickupController.Instance.NewPickup(transform.position);
                 }
             }
         }
     }
 }
Esempio n. 9
0
    public override void Update(GameTime gameTime)
    {
        actionString = null;
        checkIfInDiscoveredAreaTimer.Update(gameTime);
        if (checkIfInDiscoveredAreaTimer.Ended)
        {
            Point p = new Point((int)this.Position.X, (int)this.Position.Y);
            if (GameData.LevelGrid.GetTile(p) != null)
            {
                if (GameData.LevelGrid.GetTile(p).Discovered)
                {
                    InDiscoveredArea = true;
                }
                else
                {
                    InDiscoveredArea = false;
                }
            }
        }
        if (!frozen && (Faction == Player.Faction.humanity || Faction == Player.Faction.nature))
        {
            attackTimer.Update(gameTime);
            if (targetUnit != null)
            {
                MoveToUnit();
            }


            else if (targetPosition != Vector2.Zero)
            {
                MoveToTile();
            }
            base.Update(gameTime);
        }
        healthBar.Update(new Vector2(position.X, position.Y - sprite.Height / 2 - 10));
        healthBar.ChangeHealth((float)((health / maxHealth) * 1.5));
    }
Esempio n. 10
0
    private void OnTriggerEnter(Collider other)
    {
        if (!dead)
        {
            if (other.transform.tag.Equals("enemyAttack"))
            {
                print("player lost health");
                PlayerHealth.ChangeHealth(-25f);
                healthLost += 25;
                if (PlayerHealth.GetValue() < 1)
                {
                    anim.SetTrigger("die");
                    dead = true;
                    CC.Move(new Vector3(0f, 0f, 0f));
                    Velocity.y = -2f;
                    Camera.GetComponent <ShoulderCam>().ChangeDead();
                    DeathMenu.SetActive(true);
                    Camera.GetComponent <ShoulderCam>().crossHairObject.SetActive(false);
                    Cursor.lockState = CursorLockMode.None;
                    Cursor.visible   = true;
                }
            }
            if (other.transform.tag.Equals("ammopower"))
            {
                Destroy(other.gameObject);
                Camera.GetComponent <ShoulderCam>().ammoCapacity += Camera.GetComponent <ShoulderCam>().originalMagazineSize;
                Camera.GetComponent <ShoulderCam>().ammoLeft.text = Camera.GetComponent <ShoulderCam>().ammoCapacity.ToString();
            }
            if (other.transform.tag.Equals("heart"))
            {
                Destroy(other.gameObject);
                PlayerHealth.ChangeHealth(25f);
                print("gained health");
            }
            if (other.transform.tag.Equals("vial"))
            {
                Destroy(other.gameObject);
                GameObject.Find("Controller").GetComponent <LevelTwoController>().addVial();
                print("gained vial");
            }
            if (other.transform.tag.Equals("key"))
            {
                Destroy(other.gameObject);
                GameObject.Find("Controller").GetComponent <LevelTwoController>().FoundKey();
                print("gained key");
            }
            if (other.transform.tag.Equals("ammobox"))
            {
                other.gameObject.SetActive(false);
                GameObject.FindGameObjectWithTag("MainCamera").GetComponent <ShoulderCam>().fillAmmo();
                print("filled ammo");
                StartCoroutine(EnableAmmoBox(other.gameObject));
            }
        }
        IEnumerator EnableAmmoBox(GameObject obj)
        {
            yield return(new WaitForSeconds(20f));

            obj.SetActive(true);
        }
    }
Esempio n. 11
0
 public void Health(int change)
 {
     character.stats.health -= change;
     healthBar.ChangeHealth(Health());
 }