Procházet zdrojové kódy

switch to SpriteID enum

jblanked před 9 měsíci
rodič
revize
8e5dee34d8
3 změnil soubory, kde provedl 27 přidání a 26 odebrání
  1. 9 9
      game/enemy.c
  2. 5 4
      game/npc.c
  3. 13 13
      game/player.h

+ 9 - 9
game/enemy.c

@@ -7,7 +7,7 @@
 static EntityContext *enemy_context_generic;
 // Allocation function
 static EntityContext *enemy_generic_alloc(
-    const char *id,
+    SpriteID id,
     int index,
     Vector size,
     Vector start_position,
@@ -29,7 +29,7 @@ static EntityContext *enemy_generic_alloc(
         FURI_LOG_E("Game", "Failed to allocate EntityContext");
         return NULL;
     }
-    snprintf(enemy_context_generic->id, sizeof(enemy_context_generic->id), "%s", id);
+    enemy_context_generic->id = id;
     enemy_context_generic->index = index;
     enemy_context_generic->size = size;
     enemy_context_generic->start_position = start_position;
@@ -78,7 +78,7 @@ static void enemy_start(Entity *self, GameManager *manager, void *context)
 
     EntityContext *enemy_context = (EntityContext *)context;
     // Copy fields from generic context
-    snprintf(enemy_context->id, sizeof(enemy_context->id), "%s", enemy_context_generic->id);
+    enemy_context->id = enemy_context_generic->id;
     enemy_context->index = enemy_context_generic->index;
     enemy_context->size = enemy_context_generic->size;
     enemy_context->start_position = enemy_context_generic->start_position;
@@ -185,7 +185,7 @@ static void atk_notify(GameContext *game_context, EntityContext *enemy_context,
         {
             notification_message(notifications, &sequence_blink_blue_100);
         }
-        FURI_LOG_I("Game", "Player attacked enemy '%s'!", enemy_context->id);
+        FURI_LOG_I("Game", "Player attacked enemy '%d'!", enemy_context->id);
     }
     else
     {
@@ -207,7 +207,7 @@ static void atk_notify(GameContext *game_context, EntityContext *enemy_context,
             notification_message(notifications, &sequence_blink_red_100);
         }
 
-        FURI_LOG_I("Game", "Enemy '%s' attacked the player!", enemy_context->id);
+        FURI_LOG_I("Game", "Enemy '%d' attacked the player!", enemy_context->id);
     }
 
     // close the notifications
@@ -267,7 +267,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
         {
             if (game_context->game_mode == GAME_MODE_STORY && game_context->tutorial_step == 4)
             {
-                // FURI_LOG_I("Game", "Player attacked enemy '%s'!", enemy_context->id);
+                // FURI_LOG_I("Game", "Player attacked enemy '%d'!", enemy_context->id);
                 game_context->tutorial_step++;
             }
             // Reset last button
@@ -334,7 +334,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
             }
             else
             {
-                FURI_LOG_I("Game", "Player attack on enemy '%s' is on cooldown: %f seconds remaining", enemy_context->id, (double)(player_context->attack_timer - player_context->elapsed_attack_timer));
+                FURI_LOG_I("Game", "Player attack on enemy '%d' is on cooldown: %f seconds remaining", enemy_context->id, (double)(player_context->attack_timer - player_context->elapsed_attack_timer));
             }
         }
         // Handle Enemy Attacking Player (enemy facing player)
@@ -377,7 +377,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
                 }
                 else
                 {
-                    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 '%d'", (double)enemy_context->strength, enemy_context->id);
                     player_context->state = ENTITY_ATTACKED;
 
                     // Bounce the player back by X units opposite their last movement direction
@@ -732,7 +732,7 @@ const EntityDescription *enemy(
 
     // Allocate a new EntityContext with provided parameters
     enemy_context_generic = enemy_generic_alloc(
-        id,
+        sprite_context->id,
         index,
         (Vector){sprite_context->width, sprite_context->height},
         start_position,

+ 5 - 4
game/npc.c

@@ -3,7 +3,7 @@ static EntityContext *npc_context_generic;
 
 // Allocation function
 static EntityContext *npc_generic_alloc(
-    const char *id,
+    SpriteID id,
     int index,
     Vector size,
     Vector start_position,
@@ -21,7 +21,7 @@ static EntityContext *npc_generic_alloc(
         FURI_LOG_E("Game", "Failed to allocate EntityContext");
         return NULL;
     }
-    snprintf(npc_context_generic->id, sizeof(npc_context_generic->id), "%s", id);
+    npc_context_generic->id = id;
     npc_context_generic->index = index;
     npc_context_generic->size = size;
     npc_context_generic->start_position = start_position;
@@ -57,7 +57,7 @@ static void npc_start(Entity *self, GameManager *manager, void *context)
 
     EntityContext *npc_context = (EntityContext *)context;
     // Copy fields from generic context
-    snprintf(npc_context->id, sizeof(npc_context->id), "%s", npc_context_generic->id);
+    npc_context->id = npc_context_generic->id;
     snprintf(npc_context->message, sizeof(npc_context->message), "%s", npc_context_generic->message);
     npc_context->index = npc_context_generic->index;
     npc_context->size = npc_context_generic->size;
@@ -343,7 +343,7 @@ const EntityDescription *npc(
 
     // Allocate a new EntityContext with provided parameters
     npc_context_generic = npc_generic_alloc(
-        id,
+        sprite_context->id,
         index,
         (Vector){sprite_context->width, sprite_context->height},
         start_position,
@@ -439,4 +439,5 @@ void spawn_npc(Level *level, GameManager *manager, FuriString *json)
     furi_string_free(end_position_y);
     furi_string_free(move_timer);
     furi_string_free(speed);
+    furi_string_free(message);
 }

+ 13 - 13
game/player.h

@@ -8,10 +8,22 @@
 #define MAX_LEVELS 5
 #define MAX_NPCS 1
 
+typedef enum
+{
+    SPRITE_ID_AXE,
+    SPRITE_ID_BOW,
+    SPRITE_ID_NAKED,
+    SPRITE_ID_SWORD,
+    SPRITE_ID_CYCLOPS,
+    SPRITE_ID_GHOST,
+    SPRITE_ID_OGRE,
+    SPRITE_ID_FUNNY
+} SpriteID;
+
 // EntityContext definition
 typedef struct
 {
-    char id[32];                // Unique ID for the entity type
+    SpriteID id;                // Unique ID for the entity type
     uint8_t index;              // Index for the specific entity instance
     Vector size;                // Size of the entity
     Sprite *sprite_right;       // Entity sprite when looking right
@@ -109,18 +121,6 @@ typedef struct
     FlipperHTTP *fhttp;
 } GameContext;
 
-typedef enum
-{
-    SPRITE_ID_AXE,
-    SPRITE_ID_BOW,
-    SPRITE_ID_NAKED,
-    SPRITE_ID_SWORD,
-    SPRITE_ID_CYCLOPS,
-    SPRITE_ID_GHOST,
-    SPRITE_ID_OGRE,
-    SPRITE_ID_FUNNY
-} SpriteID;
-
 typedef struct
 {
     SpriteID id;