feat: tracking facing direction

This commit is contained in:
Sara 2023-11-26 13:12:56 +01:00
parent b82c0a5765
commit 20c5d9dfe1

View file

@ -1,12 +1,15 @@
#include "PlayerStates.h" #include "PlayerStates.h"
#include "Player.h" #include "Player.h"
#include "physics_world.h"
#include "debug.h"
static inline static inline
void InternalSpriteFlipWithMovement(Player* self) { void InternalSpriteFlipWithMovement(Player* self) {
if(self->moveInput.x > 0.f) if(self->moveInput.x > 0.f)
sprite_flip_horizontal(self->sprite, 0); self->facing = 1;
if(self->moveInput.x < -0.1f) if(self->moveInput.x < -0.1f)
sprite_flip_horizontal(self->sprite, 1); self->facing = -1;
sprite_flip_horizontal(self->sprite, self->facing != 1);
} }
void PlayerAnimationExit(Player* self) {} void PlayerAnimationExit(Player* self) {}
@ -51,6 +54,11 @@ void PlayerJabA_Enter(Player* self) {
PlayerAttackEnter(self); PlayerAttackEnter(self);
self->currentAnimation = self->jab_a; self->currentAnimation = self->jab_a;
animation_sprite_play_from(self->currentAnimation, 0.f); animation_sprite_play_from(self->currentAnimation, 0.f);
Collider* found = physics_world_box_query(vaddf(self->transform.position, MakeVector(self->facing * (0.2f + 0.05f), 0.f)),
MakeVector(0.05f, 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 State* PlayerJabA_Update(Player* self, float deltaTime) {