Ejemplo n.º 1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        healthbar = GetNode <TextureProgress>("Health");
        ammobar   = GetNode <TextureProgress>("Ammo");

        SendHealthEvent.RegisterListener(UpdateHealth);
        SendAmmoEvent.RegisterListener(UpdateAmmo);
    }
Ejemplo n.º 2
0
    private void OnHit(HitEvent hei)
    {
        if (GetParent().Name == hei.target.Name)
        {
            //Reduce the tanks health with the given amount
            health -= hei.damage;

            //Check if the health has gone down to zero
            CheckHealth();

            if (hei.target.IsInGroup("Player"))
            {
                //Broadcast the health after it has been modified to anyone who is listening
                SendHealthEvent shei = new SendHealthEvent();
                shei.health = health;
                shei.target = hei.target;
                shei.FireEvent();
            }
        }
    }
Ejemplo n.º 3
0
 public override void _ExitTree()
 {
     SendHealthEvent.UnregisterListener(UpdateHealth);
     SendAmmoEvent.UnregisterListener(UpdateAmmo);
 }
Ejemplo n.º 4
0
 private void UpdateHealth(SendHealthEvent shei)
 {
     healthbar.Value = shei.health;
 }