|
@@ -263,7 +263,6 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
|
|
|
|
|
|
|
|
if (enemy_context->health <= 0)
|
|
if (enemy_context->health <= 0)
|
|
|
{
|
|
{
|
|
|
- FURI_LOG_I("Game", "Enemy '%s' is dead.. resetting enemy position and health", enemy_context->id);
|
|
|
|
|
enemy_context->state = ENTITY_DEAD;
|
|
enemy_context->state = ENTITY_DEAD;
|
|
|
|
|
|
|
|
// Reset enemy position and health
|
|
// Reset enemy position and health
|
|
@@ -278,7 +277,6 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- FURI_LOG_I("Game", "Enemy '%s' took %f damage from player", enemy_context->id, (double)game_context->player_context->strength);
|
|
|
|
|
enemy_context->state = ENTITY_ATTACKED;
|
|
enemy_context->state = ENTITY_ATTACKED;
|
|
|
// Vector old_pos = entity_pos_get(self);
|
|
// Vector old_pos = entity_pos_get(self);
|
|
|
// Bounce the enemy back by X units opposite their last movement direction
|
|
// Bounce the enemy back by X units opposite their last movement direction
|
|
@@ -350,10 +348,6 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
|
|
|
game_context->player_context->dy = 0;
|
|
game_context->player_context->dy = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Reset enemy's state
|
|
|
|
|
- enemy_context->state = ENTITY_IDLE;
|
|
|
|
|
- enemy_context->elapsed_move_timer = 0.0f;
|
|
|
|
|
-
|
|
|
|
|
if (game_context->player_context->state == ENTITY_DEAD)
|
|
if (game_context->player_context->state == ENTITY_DEAD)
|
|
|
{
|
|
{
|
|
|
// Reset player's position and health
|
|
// Reset player's position and health
|
|
@@ -437,12 +431,18 @@ static void enemy_update(Entity *self, GameManager *manager, void *context)
|
|
|
|
|
|
|
|
case ENTITY_MOVING_TO_END:
|
|
case ENTITY_MOVING_TO_END:
|
|
|
case ENTITY_MOVING_TO_START:
|
|
case ENTITY_MOVING_TO_START:
|
|
|
|
|
+ case ENTITY_ATTACKED:
|
|
|
{
|
|
{
|
|
|
|
|
+ // Get current position
|
|
|
|
|
+ Vector current_pos = entity_pos_get(self);
|
|
|
|
|
+ if (enemy_context->state == ENTITY_ATTACKED)
|
|
|
|
|
+ {
|
|
|
|
|
+ enemy_context->state = current_pos.x > (enemy_context->start_position.x - enemy_context->end_position.x) ? ENTITY_MOVING_TO_END : ENTITY_MOVING_TO_START;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Determine the target position based on the current state
|
|
// Determine the target position based on the current state
|
|
|
Vector target_position = (enemy_context->state == ENTITY_MOVING_TO_END) ? enemy_context->end_position : enemy_context->start_position;
|
|
Vector target_position = (enemy_context->state == ENTITY_MOVING_TO_END) ? enemy_context->end_position : enemy_context->start_position;
|
|
|
|
|
|
|
|
- // Get current position
|
|
|
|
|
- Vector current_pos = entity_pos_get(self);
|
|
|
|
|
Vector direction_vector = {0, 0};
|
|
Vector direction_vector = {0, 0};
|
|
|
|
|
|
|
|
// Calculate direction towards the target
|
|
// Calculate direction towards the target
|