#include "EnemyStates.h"
#include "Enemy.h"
#include "animation_sprite.h"

void EnemyState_Exit(Enemy* self) {}

void EnemyIdle_Enter(Enemy* self) {
    self->currentAnimation = self->idleAnim;
    animation_sprite_play_from(self->currentAnimation, 0.f);
}

const State* EnemyIdle_Update(Enemy* self, float deltaTime) {
    if(self->stun_time > 0.f)
        return EnemyHurt();
    return EnemyIdle();
}

void EnemyWalk_Enter(Enemy* self) {
    self->currentAnimation = self->walkAnim;
    animation_sprite_play_from(self->currentAnimation, 0.f);
}

const State* EnemyWalk_Update(Enemy* self, float deltaTime) {
    return EnemyWalk();
}

void EnemyHurt_Enter(Enemy* self) {
    self->currentAnimation = self->hurtAnim;
    animation_sprite_play_from(self->currentAnimation, 0.f);
}

const State* EnemyHurt_Update(Enemy* self, float deltaTime) {
    const float time = animation_sprite_get_time(self->currentAnimation);
    if(self->stun_time < 0.f)
        return EnemyIdle();
    return EnemyHurt();
}
