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

update stats display and sprite drawing condition

jblanked 11 месяцев назад
Родитель
Сommit
a2f5b7a332
5 измененных файлов с 21 добавлено и 8 удалено
  1. 2 2
      flip_world.h
  2. 3 0
      game/draw.c
  3. 8 3
      game/enemy.c
  4. 7 2
      game/icon.c
  5. 1 1
      game/player.c

+ 2 - 2
flip_world.h

@@ -14,8 +14,8 @@
 #define FURI_LOG_D(tag, msg, ...)
 #define FURI_LOG_D(tag, msg, ...)
 //
 //
 
 
-#define TAG         "FlipWorld"
-#define VERSION     0.5
+#define TAG "FlipWorld"
+#define VERSION 0.5
 #define VERSION_TAG TAG " " FAP_VERSION
 #define VERSION_TAG TAG " " FAP_VERSION
 
 
 // Define the submenu items for our FlipWorld application
 // Define the submenu items for our FlipWorld application

+ 3 - 0
game/draw.c

@@ -185,6 +185,9 @@ void background_render(Canvas *canvas, GameManager *manager)
                 0,
                 0,
                 &I_icon_world_change_128x64px);
                 &I_icon_world_change_128x64px);
         }
         }
+
+        // Draw user stats
+        draw_user_stats(canvas, (Vector){0, 50}, manager);
     }
     }
     else
     else
     {
     {

+ 8 - 3
game/enemy.c

@@ -99,6 +99,14 @@ static void enemy_render(Entity *self, GameManager *manager, Canvas *canvas, voi
     // Get the position of the enemy
     // Get the position of the enemy
     Vector pos = entity_pos_get(self);
     Vector pos = entity_pos_get(self);
 
 
+    // Get the camera position
+    int x_pos = pos.x - camera_x - enemy_context->size.x / 2;
+    int y_pos = pos.y - camera_y - enemy_context->size.y / 2;
+
+    // check if position is within the screen
+    if (x_pos + enemy_context->size.x < 0 || x_pos > SCREEN_WIDTH || y_pos + enemy_context->size.y < 0 || y_pos > SCREEN_HEIGHT)
+        return;
+
     // Choose sprite based on direction
     // Choose sprite based on direction
     Sprite *current_sprite = NULL;
     Sprite *current_sprite = NULL;
     if (enemy_context->direction == ENTITY_LEFT)
     if (enemy_context->direction == ENTITY_LEFT)
@@ -121,9 +129,6 @@ static void enemy_render(Entity *self, GameManager *manager, Canvas *canvas, voi
     char health_str[32];
     char health_str[32];
     snprintf(health_str, sizeof(health_str), "%.0f", (double)enemy_context->health);
     snprintf(health_str, sizeof(health_str), "%.0f", (double)enemy_context->health);
     draw_username(canvas, pos, health_str);
     draw_username(canvas, pos, health_str);
-
-    // Draw user stats (this has to be done for all enemies)
-    draw_user_stats(canvas, (Vector){0, 50}, manager);
 }
 }
 
 
 static void atk_notify(GameContext *game_context, EntityContext *enemy_context, bool player_attacked)
 static void atk_notify(GameContext *game_context, EntityContext *enemy_context, bool player_attacked)

+ 7 - 2
game/icon.c

@@ -24,9 +24,14 @@ static void icon_render(Entity *self, GameManager *manager, Canvas *canvas, void
 {
 {
     UNUSED(manager);
     UNUSED(manager);
     IconContext *ictx = (IconContext *)context;
     IconContext *ictx = (IconContext *)context;
+    furi_check(ictx, "Icon context is NULL");
     Vector pos = entity_pos_get(self);
     Vector pos = entity_pos_get(self);
-    if (ictx)
-        canvas_draw_icon(canvas, pos.x - camera_x - ictx->size.x / 2, pos.y - camera_y - ictx->size.y / 2, ictx->icon);
+    int x_pos = pos.x - camera_x - ictx->size.x / 2;
+    int y_pos = pos.y - camera_y - ictx->size.y / 2;
+    // check if position is within the screen
+    if (x_pos + ictx->size.x < 0 || x_pos > SCREEN_WIDTH || y_pos + ictx->size.y < 0 || y_pos > SCREEN_HEIGHT)
+        return;
+    canvas_draw_icon(canvas, x_pos, y_pos, ictx->icon);
 }
 }
 
 
 static void icon_start(Entity *self, GameManager *manager, void *context)
 static void icon_start(Entity *self, GameManager *manager, void *context)

+ 1 - 1
game/player.c

@@ -445,7 +445,7 @@ static void player_render(Entity *self, GameManager *manager, Canvas *canvas, vo
     // Draw the outer bounds adjusted by camera offset
     // Draw the outer bounds adjusted by camera offset
     canvas_draw_frame(canvas, -camera_x, -camera_y, WORLD_WIDTH, WORLD_HEIGHT);
     canvas_draw_frame(canvas, -camera_x, -camera_y, WORLD_WIDTH, WORLD_HEIGHT);
 
 
-    // Draw the user stats (health, xp, and level)
+    // render background
     background_render(canvas, manager);
     background_render(canvas, manager);
 }
 }