Esempio n. 1
0
    private void Start()
    {
        string path = Application.persistentDataPath + "\\PlayerData.txt";

        if (File.Exists(path))
        {
            StreamReader file = new StreamReader(path);
            string       data = file.ReadLine();
            currentLevel  = Int32.Parse(data.Split(';')[0]);
            currentHealth = Int32.Parse(data.Split(';')[1]);
            currentXP     = Int32.Parse(data.Split(';')[2]);
            DateTime saveTime = DateTime.Parse(data.Split(';')[3]);
            if ((DateTime.Now - saveTime).TotalDays >= 1)
            {
                currentHealth = currentHealth - 2;
            }
        }
        else
        {
            StreamWriter file = File.CreateText(path);
            file.WriteLine("1;20;0;" + DateTime.Now);
            file.Close();
            currentHealth = maxHealth;
            currentXP     = 0;
            currentLevel  = 1;
        }
        XPBar.SetMaxXP(maxXP);
        healthBar.SetMaxHealth(maxHealth);
        XPBar.SetXP(currentXP);
        healthBar.SetHealth(currentHealth);
        level.GetComponent <TextMeshProUGUI>().SetText("LVL " + currentLevel);
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Vector2.Distance(transform.position, playerObj.transform.position) < 30)
        {
            eagleUI.gameObject.SetActive(true);
        }
        else
        {
            eagleUI.gameObject.SetActive(false);
        }

        if (transform.position.x - playerObj.transform.position.x > -3 && transform.position.x - playerObj.transform.position.x < 3 && playerObj.transform.position.y > transform.position.y && !player.immune)
        {
            playerAttack.gameObject.SetActive(true);
            if (Input.GetKeyDown("space"))
            {
                isAttacked    = true;
                player.immune = true;
                Invoke("AttackEagle", 0.1f);
            }
        }
        else
        {
            playerAttack.gameObject.SetActive(false);
        }

        if (!isAttacked)
        {
            EagleMovement();
        }
        else
        {
            Invoke("EagleMovement", 2);
        }

        if (eagleStats.health <= 0)
        {
            Vector2 pos = transform.position;

            for (int i = 0; i < 5; i++)
            {
                pos = new Vector2(transform.position.x + i * 2, transform.position.y + 1);
                Instantiate(diamond, pos, Quaternion.identity);
            }

            playerAttack.gameObject.SetActive(false);
            eagleUI.gameObject.SetActive(false);
            Destroy(this.gameObject);
        }
        else
        {
            healthBar.SetHealth(eagleStats.health);
        }
    }
Esempio n. 3
0
 private void Start()
 {
     /*if (PhotonNetwork.IsMasterClient)
      *  otherPlayer = GameObject.Find("Player 2").GetComponent<PlayerController>();
      * else
      *  otherPlayer = GameObject.Find("Player 1").GetComponent<PlayerController>();*/
     // Instantiate variables on creation
     sprite        = GetComponent <SpriteRenderer>();
     rb            = GetComponent <Rigidbody2D>();
     anim          = GetComponent <Animator>();
     currentHealth = maxHealth;
     healthBarController.SetHealth(currentHealth);
     SkillSelectionManager.instance.AssignSkills(playerNo);
     godMode = false;
 }
Esempio n. 4
0
    public void TakeDamage()
    {
        if (currentHealth <= 0)
        {
            healthBarController.SetHealth(currentHealth);
            Destroy(gameObject);

            popUpController.FadeToBlack(true);
        }
        else
        {
            currentHealth--;
            healthBarController.SetHealth(currentHealth);
        }
    }
Esempio n. 5
0
        public void Update()
        {
            healthBarController.SetHealth(currentHealth);
            // combo system
            if (combatState == CombatState.Attacking)
            {
                if (playerInput.AttemptAttack)
                {
                    attack.Cast(otherPlayer);
                }
            }

            // if the player is dead, the player state should not be updated
            if (combatState == CombatState.Dead)
            {
                return;
            }
            // the player can only move, block and roll while hurt
            if (combatState == CombatState.Hurt)
            {
                ListenForRoll();
                ListenForBlock();
                Move();
            }
            else if (combatState == CombatState.NonCombat)
            {
                ListenForRoll();
                ListenForAttack();
                ListenForBlock();
                ListenForSkill();
                Move();
            }
        }
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Enemy" && canBeHit && !previouslyHit)
     {
         canBeHit      = false;
         previouslyHit = true;
         currentHealth--;
         healthBar.SetHealth(currentHealth);
         StartCoroutine(HitCooldown());
         if (currentHealth <= 0)
         {
             Destroy(gameObject);
             GameController.instance.EndGame();
         }
     }
 }
Esempio n. 7
0
    private void InitHealth()
    {
        healthBarController = healthBar.GetComponent <HealthBarController>();
        healthBarController.SetMaxHealth(maxHealth);
        healthBarController.SetHealth(maxHealth);

        currentHealth = maxHealth;
    }
Esempio n. 8
0
    public void TakeDamage(int _damage)
    {
        if (!isInvincible)
        {
            player.currentHealth -= _damage;
            healthBar.SetHealth(player.currentHealth);

            if (player.currentHealth <= 0)
            {
                Die();
                return;
            }

            isInvincible = true;
            StartCoroutine(StartInvincibility());
            StartCoroutine(StopInvincibility());
        }
    }
Esempio n. 9
0
 public void DoDamage(float value)
 {
     Health -= value;
     _healthBarController.SetHealth(Health / MaxHealth);
     if (Health <= 0)
     {
         _gameStateController.LoseGame();
     }
 }
Esempio n. 10
0
    //Inflict damage to enemy
    public void TakeDamage(int damage)
    {
        currentHealth -= damage;
        healthBar.SetHealth(currentHealth);

        //Destroy enemy with 0 health
        if (currentHealth <= 0)
        {
            Destroy(this.gameObject);
        }
    }
Esempio n. 11
0
    public void ChangeHealth(int amount)
    {
        // if (amount < 0)
        // {
        //     if (isInv)
        //     {
        //         return;

        //         isInv = true;
        //         timeInv = invTimer;
        //     }
        // }

        currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);
        HealthBar.SetHealth(currentHealth);
    }
Esempio n. 12
0
 void Update()
 {
     UpdateScene();
     healthBar.SetHealth(CurrentEnemy.CurrentHealth);
 }
Esempio n. 13
0
 public void HurtEnemy(int damage)
 {
     curHealth -= damage;
     healthBar.SetHealth(curHealth);
 }
 //Damage handler
 public void TakeDamage(int damage)
 {
     currentHealth -= damage;
     healthBar.SetHealth(currentHealth);
 }