feat: player attacks now have better timing for the attack frame
This commit is contained in:
parent
53af5fb66d
commit
02f48c5fb3
|
@ -12,7 +12,9 @@ void InternalSpriteFlipWithMovement(Player* self) {
|
|||
sprite_flip_horizontal(self->sprite, self->facing != 1);
|
||||
}
|
||||
|
||||
void PlayerAnimationExit(Player* self) {}
|
||||
void PlayerAnimationExit(Player* self) {
|
||||
self->animationTriggers = 0;
|
||||
}
|
||||
|
||||
void PlayerIdleEnter(Player* self) {
|
||||
self->currentAnimation = self->idle;
|
||||
|
@ -49,26 +51,34 @@ void PlayerAttackEnter(Player* self) {
|
|||
InternalSpriteFlipWithMovement(self);
|
||||
}
|
||||
|
||||
static
|
||||
void PlayerAttackTrigger(Player* self) {
|
||||
Collider* found = physics_world_box_query(vaddf(self->transform.position, MakeVector(self->facing * (0.2f + 0.1f), 0.f)),
|
||||
MakeVector(0.1f, 0.06f), PHYSICS_LAYER_DEFAULT, self->rigidbody);
|
||||
if(found != NULL) {
|
||||
PhysicsEntity entity = collider_get_owner(found);
|
||||
int damage_amount = 10;
|
||||
entity.message_receiver->handle_message(entity.data, 1, &damage_amount);
|
||||
}
|
||||
++self->animationTriggers;
|
||||
}
|
||||
|
||||
void PlayerJabA_Enter(Player* self) {
|
||||
PlayerAttackEnter(self);
|
||||
self->currentAnimation = self->jab_a;
|
||||
animation_sprite_play_from(self->currentAnimation, 0.f);
|
||||
|
||||
Collider* found = physics_world_box_query(vaddf(self->transform.position, MakeVector(self->facing * (0.2f + 0.1f), 0.f)),
|
||||
MakeVector(0.1f, 0.06f), PHYSICS_LAYER_DEFAULT, self->rigidbody);
|
||||
|
||||
if(found != NULL)
|
||||
LOG_INFO("Query returned %p", found);
|
||||
}
|
||||
|
||||
const State* PlayerJabA_Update(Player* self, float deltaTime) {
|
||||
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
||||
if(ntime >= 2.0f)
|
||||
return PlayerIdle();
|
||||
if(self->animationTriggers <= 0 && ntime > 0.5f)
|
||||
PlayerAttackTrigger(self);
|
||||
if(self->attackInput && ntime > 1.0f)
|
||||
return PlayerJabB();
|
||||
if(!veqf(self->moveInput, ZeroVector) && ntime > 1.05f)
|
||||
return PlayerWalk();
|
||||
if(ntime >= 2.0f)
|
||||
return PlayerIdle();
|
||||
return PlayerJabA();
|
||||
}
|
||||
|
||||
|
@ -80,11 +90,13 @@ void PlayerJabB_Enter(Player* self) {
|
|||
|
||||
const State* PlayerJabB_Update(Player* self, float deltaTime) {
|
||||
const float ntime = animation_sprite_get_time_normalized(self->currentAnimation);
|
||||
if(ntime >= 2.f)
|
||||
return PlayerIdle();
|
||||
if(self->animationTriggers <= 0 && ntime > 0.5f)
|
||||
PlayerAttackTrigger(self);
|
||||
if(self->attackInput && ntime > 1.0f)
|
||||
return PlayerJabA();
|
||||
if(!veqf(self->moveInput, ZeroVector) && ntime > 1.05f)
|
||||
return PlayerWalk();
|
||||
if(ntime >= 2.0f)
|
||||
return PlayerIdle();
|
||||
return PlayerJabB();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue