|
@@ -281,7 +281,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
|
|
|
// 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
|
|
|
enemy_pos.x -= game_context->player_context->dx * enemy_context->radius + game_context->icon_offset;
|
|
enemy_pos.x -= game_context->player_context->dx * enemy_context->radius + game_context->icon_offset;
|
|
|
- enemy_pos.y -= game_context->player_context->dy * enemy_context->radius + game_context->icon_offset;
|
|
|
|
|
|
|
+ // enemy_pos.y -= game_context->player_context->dy * enemy_context->radius + game_context->icon_offset;
|
|
|
entity_pos_set(self, enemy_pos);
|
|
entity_pos_set(self, enemy_pos);
|
|
|
|
|
|
|
|
// Reset enemy's movement direction to prevent immediate re-collision
|
|
// Reset enemy's movement direction to prevent immediate re-collision
|
|
@@ -330,7 +330,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
|
|
|
|
|
|
|
|
// Bounce the player back by X units opposite their last movement direction
|
|
// Bounce the player back by X units opposite their last movement direction
|
|
|
player_pos.x -= game_context->player_context->dx * enemy_context->radius + game_context->icon_offset;
|
|
player_pos.x -= game_context->player_context->dx * enemy_context->radius + game_context->icon_offset;
|
|
|
- player_pos.y -= game_context->player_context->dy * enemy_context->radius + game_context->icon_offset;
|
|
|
|
|
|
|
+ // player_pos.y -= game_context->player_context->dy * enemy_context->radius + game_context->icon_offset;
|
|
|
entity_pos_set(other, player_pos);
|
|
entity_pos_set(other, player_pos);
|
|
|
|
|
|
|
|
// Reset player's movement direction to prevent immediate re-collision
|
|
// Reset player's movement direction to prevent immediate re-collision
|
|
@@ -437,12 +437,12 @@ static void enemy_update(Entity *self, GameManager *manager, void *context)
|
|
|
Vector current_pos = entity_pos_get(self);
|
|
Vector current_pos = entity_pos_get(self);
|
|
|
if (enemy_context->state == ENTITY_ATTACKED)
|
|
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;
|
|
|
|
|
|
|
+ // set direction again
|
|
|
|
|
+ enemy_context->state = enemy_context->direction == ENTITY_LEFT ? ENTITY_MOVING_TO_START : ENTITY_MOVING_TO_END;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
-
|
|
|
|
|
Vector direction_vector = {0, 0};
|
|
Vector direction_vector = {0, 0};
|
|
|
|
|
|
|
|
// Calculate direction towards the target
|
|
// Calculate direction towards the target
|