feat: drag for enemy is now calculated in EnemyUpdate
instead of separately in the states
This commit is contained in:
parent
73104a02c4
commit
a27acee155
|
@ -95,6 +95,10 @@ Enemy* SpawnEnemy(Vector location, const State* entryState) {
|
||||||
void EnemyStart(Enemy* self) {}
|
void EnemyStart(Enemy* self) {}
|
||||||
|
|
||||||
void EnemyUpdate(Enemy* self, float deltaTime) {
|
void EnemyUpdate(Enemy* self, float deltaTime) {
|
||||||
|
// apply drag
|
||||||
|
Vector velocity = vmovetowardsf(rigidbody_get_velocity(self->rigidbody), ZeroVector, 0.1f);
|
||||||
|
rigidbody_set_velocity(self->rigidbody, velocity);
|
||||||
|
// update state machine
|
||||||
state_machine_update(self->behaviour, deltaTime);
|
state_machine_update(self->behaviour, deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +146,7 @@ int EnemyDamage(Enemy* self, DamageEventData* data) {
|
||||||
// get stunned
|
// get stunned
|
||||||
self->stun_time = game_time() + data->stun;
|
self->stun_time = game_time() + data->stun;
|
||||||
// calculate which direction the damage is coming from
|
// calculate which direction the damage is coming from
|
||||||
float direction = ((data->origin.x - self->transform.position.x) > 0) * 2 - 1;
|
const float direction = (data->origin.x - self->transform.position.x) >= 0.0f ? 1.0f : -1.0f;
|
||||||
// face the direction damage is coming from
|
// face the direction damage is coming from
|
||||||
self->facing = direction;
|
self->facing = direction;
|
||||||
// add knockback according to damage data in the calculated direction
|
// add knockback according to damage data in the calculated direction
|
||||||
|
|
|
@ -11,9 +11,6 @@ void EnemyIdle_Enter(Enemy* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const State* EnemyIdle_Update(Enemy* self, float deltaTime) {
|
const State* EnemyIdle_Update(Enemy* self, float deltaTime) {
|
||||||
// apply drag
|
|
||||||
Vector velocity = vmovetowardsf(rigidbody_get_velocity(self->rigidbody), ZeroVector, 0.1f);
|
|
||||||
rigidbody_set_velocity(self->rigidbody, velocity);
|
|
||||||
// state transitions
|
// state transitions
|
||||||
if(self->stun_time >= game_time())
|
if(self->stun_time >= game_time())
|
||||||
return EnemyHurt();
|
return EnemyHurt();
|
||||||
|
@ -36,9 +33,6 @@ void EnemyHurt_Enter(Enemy* self) {
|
||||||
|
|
||||||
const State* EnemyHurt_Update(Enemy* self, float deltaTime) {
|
const State* EnemyHurt_Update(Enemy* self, float deltaTime) {
|
||||||
const float time = animation_sprite_get_time(self->currentAnimation);
|
const float time = animation_sprite_get_time(self->currentAnimation);
|
||||||
// apply drag
|
|
||||||
Vector velocity = vmovetowardsf(rigidbody_get_velocity(self->rigidbody), ZeroVector, 0.1f);
|
|
||||||
rigidbody_set_velocity(self->rigidbody, velocity);
|
|
||||||
// state transitions
|
// state transitions
|
||||||
if(self->stun_time < game_time())
|
if(self->stun_time < game_time())
|
||||||
return EnemyIdle();
|
return EnemyIdle();
|
||||||
|
|
Loading…
Reference in a new issue