Esempio n. 1
0
        public override void _Ready()
        {
            CharacterSprite = this.GetChildNode <Sprite>(nameof(CharacterSprite));

            AnimationPlayer  = this.GetChildNode <AnimationPlayer>();
            CollisionShape2D = this.GetChildNode <CollisionShape2D>(nameof(CollisionShape2D));

            State = this.GetChildNode <StateComponent>();

            Stats           = this.GetChildNode <Stats>();
            CharacterHitBox = this.GetChildNode <CharacterHitBox>();
            CharacterHitBox.Disable();

            CharacterHurtBox     = this.GetChildNode <CharacterHurtBox>();
            BlinkAnimationPlayer = this.GetChildNodeOrNull <AnimationPlayer>(nameof(BlinkAnimationPlayer));

            CharacterHurtBox.Connect(nameof(CharacterHurtBox.DamageReceived), this, nameof(ReceiveDamage));

            HpIndicator         = this.GetChildNode <HpIndicator>();
            HpIndicator.Visible = true;
            Stats.Connect(nameof(Stats.HpWasChanged), HpIndicator, nameof(HpIndicator.OnChangeHp));
            Stats.Connect(nameof(Stats.MaxHpWasChanged), HpIndicator, nameof(HpIndicator.OnChangeMaxHP));
            HpIndicator.UpdateHealthIndication();

            InvincibilityComponent = this.GetChildNode <InvincibilityComponent>();
            InvincibilityComponent.Connect(nameof(InvincibilityComponent.InvincibilityStarted), this, nameof(StartInvincibility));
            InvincibilityComponent.Connect(nameof(InvincibilityComponent.InvincibilityEnded), this, nameof(EndInvincibility));
        }
        public override void ReceiveDamage(int damageAmount, Vector2 knockbackPower)
        {
            Stats.Hp -= damageAmount;

            if (Stats.Hp <= 0)
            {
                PushState(new DeathState(this));
                return;
            }

            InvincibilityComponent.StartInvincibility();
            PushState(new KnockbackState(this, knockbackPower));
        }
        public override void ReceiveDamage(int damageAmount, Vector2 knockbackPower)
        {
            Stats.Hp -= damageAmount;

            if (Stats.Hp > 0)
            {
                AnimationPlayer.Play("Hit");
                InvincibilityComponent.StartInvincibility();
                PushState(new KnockbackState(this, knockbackPower));

                return;
            }


            PushState(new DeathState(this));
        }