feat: reworked PlayerAttackTrigger into PlayerHurtbox
This commit is contained in:
parent
3f5ff9da55
commit
f50d6a0b93
|
@ -59,25 +59,18 @@ void PlayerAttackEnter(Player* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void PlayerAttackTrigger(Player* self, DamageEventData* damage, Vector hitbox_size) {
|
void PlayerHurtbox(Player* self, DamageEventData damage, Vector hitbox_size, Vector offset) {
|
||||||
Vector collider_edge = self->facing
|
offset.x *= self->facing;
|
||||||
? shape_get_max_extent(collider_get_shape(self->physicsCollider), &self->transform)
|
offset = vaddf(self->transform.position, offset);
|
||||||
: shape_get_min_extent(collider_get_shape(self->physicsCollider), &self->transform);
|
Collider* found = physics_world_box_query(offset, hitbox_size, PHYSICS_LAYER_COMBAT, self->rigidbody);
|
||||||
//Vector hitbox_size = MakeVector(0.1f, 0.06f);
|
|
||||||
Vector hitbox_position = vaddf(self->transform.position, MakeVector(0.1f + collider_edge.x, 0.0f));
|
|
||||||
Collider* found = physics_world_box_query(vaddf(self->transform.position, hitbox_position), hitbox_size, PHYSICS_LAYER_COMBAT, self->rigidbody);
|
|
||||||
if(found != NULL) {
|
if(found != NULL) {
|
||||||
PhysicsEntity entity = collider_get_owner(found);
|
PhysicsEntity entity = collider_get_owner(found);
|
||||||
const IDamagable* damagable = mirror_get_typeclass(entity.data, entity.mirror, "Damagable");
|
const IDamagable* damagable = mirror_get_typeclass(entity.data, entity.mirror, "Damagable");
|
||||||
if(damagable) {
|
if(damagable) {
|
||||||
DamageEventData data = {
|
damage.origin = self->transform.position;
|
||||||
.damageAmount = 1,
|
damagable->damage(entity.data, &damage);
|
||||||
.origin = self->transform.position
|
|
||||||
};
|
|
||||||
damagable->damage(entity.data, &data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++self->animationTriggers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerJabA_Enter(Player* self) {
|
void PlayerJabA_Enter(Player* self) {
|
||||||
|
@ -87,9 +80,12 @@ void PlayerJabA_Enter(Player* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const State* PlayerJabA_Update(Player* self, float deltaTime) {
|
const State* PlayerJabA_Update(Player* self, float deltaTime) {
|
||||||
|
const static DamageEventData damage = {.damageAmount = 1};
|
||||||
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
||||||
if(self->animationTriggers == 0 && ntime > 0.33f)
|
if(self->animationTriggers == 0 && ntime > 0.33f) {
|
||||||
PlayerAttackTrigger(self);
|
PlayerHurtbox(self, damage, MakeVector(0.1f, 0.06f), MakeVector(0.3f, 0.06f));
|
||||||
|
++self->animationTriggers;
|
||||||
|
}
|
||||||
if(ntime > 1.0f) {
|
if(ntime > 1.0f) {
|
||||||
if(self->attackInput == 1)
|
if(self->attackInput == 1)
|
||||||
return PlayerJabB();
|
return PlayerJabB();
|
||||||
|
@ -110,9 +106,12 @@ void PlayerJabB_Enter(Player* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const State* PlayerJabB_Update(Player* self, float deltaTime) {
|
const State* PlayerJabB_Update(Player* self, float deltaTime) {
|
||||||
|
static const DamageEventData damage = {.damageAmount = 1};
|
||||||
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
||||||
if(self->animationTriggers == 0 && ntime > 0.33f)
|
if(self->animationTriggers == 0 && ntime > 0.33f) {
|
||||||
PlayerAttackTrigger(self);
|
PlayerHurtbox(self, damage, MakeVector(0.1f, 0.06f), MakeVector(0.3f, 0.0f));
|
||||||
|
++self->animationTriggers;
|
||||||
|
}
|
||||||
if(ntime > 1.0f) {
|
if(ntime > 1.0f) {
|
||||||
if(self->attackInput == 1)
|
if(self->attackInput == 1)
|
||||||
return PlayerJabA();
|
return PlayerJabA();
|
||||||
|
@ -133,12 +132,17 @@ void PlayerKickA_Enter(Player* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const State* PlayerKickA_Update(Player* self, float deltaTime) {
|
const State* PlayerKickA_Update(Player* self, float deltaTime) {
|
||||||
|
static const DamageEventData damage = {.damageAmount = 3};
|
||||||
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
||||||
|
if(ntime > 0.25f && self->animationTriggers == 0) {
|
||||||
|
PlayerHurtbox(self, damage, MakeVector(0.1f, 0.06f), MakeVector(0.3f, 0.0f));
|
||||||
|
++self->animationTriggers;
|
||||||
|
}
|
||||||
if(ntime > 1.0f && self->attackInput == 1)
|
if(ntime > 1.0f && self->attackInput == 1)
|
||||||
return PlayerJabA();
|
return PlayerJabA();
|
||||||
if(!veqf(self->moveInput, ZeroVector) && ntime > 1.05f)
|
if(!veqf(self->moveInput, ZeroVector) && ntime > 1.05f)
|
||||||
return PlayerWalk();
|
return PlayerWalk();
|
||||||
if(ntime >= 2.0f)
|
if(ntime >= 1.f)
|
||||||
return PlayerIdle();
|
return PlayerIdle();
|
||||||
return PlayerKickA();
|
return PlayerKickA();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue