Просмотр исходного кода

update enemy/player attributes

jblanked 1 год назад
Родитель
Сommit
15041c8a28
4 измененных файлов с 9 добавлено и 0 удалено
  1. 5 0
      game/enemy.c
  2. 1 0
      game/enemy.h
  3. 2 0
      game/game.c
  4. 1 0
      game/game.h

+ 5 - 0
game/enemy.c

@@ -171,10 +171,12 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
         if (enemy_context->direction == ENEMY_LEFT && player_pos.x < enemy_pos.x)
         if (enemy_context->direction == ENEMY_LEFT && player_pos.x < enemy_pos.x)
         {
         {
             is_facing_player = true;
             is_facing_player = true;
+            enemy_context->state = ENEMY_ATTACKING;
         }
         }
         else if (enemy_context->direction == ENEMY_RIGHT && player_pos.x > enemy_pos.x)
         else if (enemy_context->direction == ENEMY_RIGHT && player_pos.x > enemy_pos.x)
         {
         {
             is_facing_player = true;
             is_facing_player = true;
+            enemy_context->state = ENEMY_ATTACKING;
         }
         }
 
 
         // If the enemy is facing the player, perform an attack (log message)
         // If the enemy is facing the player, perform an attack (log message)
@@ -199,6 +201,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
                 {
                 {
                     FURI_LOG_I("Game", "Player took %f damage from enemy '%s'", (double)enemy_context->strength, enemy_context->id);
                     FURI_LOG_I("Game", "Player took %f damage from enemy '%s'", (double)enemy_context->strength, enemy_context->id);
                     game_context->player_context->health -= enemy_context->strength;
                     game_context->player_context->health -= enemy_context->strength;
+                    game_context->player_context->state = PLAYER_ATTACKED;
                 }
                 }
             }
             }
             else
             else
@@ -284,10 +287,12 @@ static void enemy_update(Entity *self, GameManager *manager, void *context)
         if (current_pos.y < target_position.y)
         if (current_pos.y < target_position.y)
         {
         {
             direction_vector.y = 1.0f;
             direction_vector.y = 1.0f;
+            enemy_context->direction = ENEMY_DOWN;
         }
         }
         else if (current_pos.y > target_position.y)
         else if (current_pos.y > target_position.y)
         {
         {
             direction_vector.y = -1.0f;
             direction_vector.y = -1.0f;
+            enemy_context->direction = ENEMY_UP;
         }
         }
 
 
         // Normalize direction vector
         // Normalize direction vector

+ 1 - 0
game/enemy.h

@@ -9,6 +9,7 @@ typedef enum
     ENEMY_MOVING_TO_START,
     ENEMY_MOVING_TO_START,
     ENEMY_MOVING_TO_END,
     ENEMY_MOVING_TO_END,
     ENEMY_ATTACKING,
     ENEMY_ATTACKING,
+    ENEMY_ATTACKED,
     ENEMY_DEAD
     ENEMY_DEAD
 } EnemyState;
 } EnemyState;
 
 

+ 2 - 0
game/game.c

@@ -69,11 +69,13 @@ static void player_update(Entity *self, GameManager *manager, void *context)
     {
     {
         pos.y -= 2;
         pos.y -= 2;
         player->dy = -1;
         player->dy = -1;
+        player->direction = PLAYER_UP;
     }
     }
     if (input.held & GameKeyDown)
     if (input.held & GameKeyDown)
     {
     {
         pos.y += 2;
         pos.y += 2;
         player->dy = 1;
         player->dy = 1;
+        player->direction = PLAYER_DOWN;
     }
     }
     if (input.held & GameKeyLeft)
     if (input.held & GameKeyLeft)
     {
     {

+ 1 - 0
game/game.h

@@ -14,6 +14,7 @@ typedef enum
     PLAYER_IDLE,
     PLAYER_IDLE,
     PLAYER_MOVING,
     PLAYER_MOVING,
     PLAYER_ATTACKING,
     PLAYER_ATTACKING,
+    PLAYER_ATTACKED,
     PLAYER_DEAD,
     PLAYER_DEAD,
 } PlayerState;
 } PlayerState;