refactor: invulnerability

This commit is contained in:
cha0s 2024-07-30 17:21:06 -05:00
parent 4b46b2f0ab
commit 83d8924517
2 changed files with 10 additions and 1 deletions

View File

@ -23,6 +23,9 @@ export default class Vulnerable extends Component {
id = 0; id = 0;
Types = DamageTypes; Types = DamageTypes;
damage(specification) { damage(specification) {
if (this.isInvulnerable) {
return;
}
const {Alive} = Component.ecs.get(this.entity); const {Alive} = Component.ecs.get(this.entity);
if (Alive) { if (Alive) {
switch (specification.type) { switch (specification.type) {
@ -39,4 +42,7 @@ export default class Vulnerable extends Component {
} }
}; };
} }
static properties = {
isInvulnerable: {type: 'uint8'},
};
} }

View File

@ -1,4 +1,7 @@
const {Sprite, Ticking} = entity; const {Sprite, Ticking, Vulnerable} = entity;
if (Vulnerable) {
Vulnerable.isInvulnerable = 1;
}
if (Sprite) { if (Sprite) {
const {promise} = transition( const {promise} = transition(
entity.Sprite, entity.Sprite,