jblanked 1 год назад
Родитель
Сommit
ca6840b74c
7 измененных файлов с 134 добавлено и 108 удалено
  1. 48 0
      draw/draw.c
  2. 32 0
      draw/draw.h
  3. 39 0
      draw/world.c
  4. 4 0
      draw/world.h
  5. 8 0
      flip_world.h
  6. 2 80
      game.c
  7. 1 28
      game.h

+ 48 - 0
draw/draw.c

@@ -0,0 +1,48 @@
+#include <draw/draw.h>
+
+// Global variables to store camera position
+int camera_x = 0;
+int camera_y = 0;
+
+// Draw a line of icons (16 width)
+void draw_icon_line(Canvas *canvas, Vector pos, int amount, bool horizontal, const Icon *icon)
+{
+    for (int i = 0; i < amount; i++)
+    {
+        if (horizontal)
+        {
+            // check if element is outside the world
+            if (pos.x + (i * 17) > WORLD_WIDTH)
+            {
+                break;
+            }
+
+            canvas_draw_icon(canvas, pos.x + (i * 17) - camera_x, pos.y - camera_y, icon);
+        }
+        else
+        {
+            // check if element is outside the world
+            if (pos.y + (i * 17) > WORLD_HEIGHT)
+            {
+                break;
+            }
+
+            canvas_draw_icon(canvas, pos.x - camera_x, pos.y + (i * 17) - camera_y, icon);
+        }
+    }
+}
+// Draw a half section of icons (16 width)
+void draw_icon_half_world(Canvas *canvas, bool right, const Icon *icon)
+{
+    for (int i = 0; i < 10; i++)
+    {
+        if (right)
+        {
+            draw_icon_line(canvas, (Vector){WORLD_WIDTH / 2 + 6, i * 19 + 2}, 11, true, icon);
+        }
+        else
+        {
+            draw_icon_line(canvas, (Vector){0, i * 19 + 2}, 11, true, icon);
+        }
+    }
+}

+ 32 - 0
draw/draw.h

@@ -0,0 +1,32 @@
+#pragma once
+#include "engine/engine.h"
+#include "flip_world.h"
+#include "flip_world_icons.h"
+
+typedef enum
+{
+    // system draw objects
+    DRAW_DOT,        // canvas_draw_dot
+    DRAW_LINE,       // canvas_draw_line
+    DRAW_BOX,        // canvas_draw_box
+    DRAW_FRAME,      // canvas_draw_frame
+    DRAW_CIRCLE,     // canvas_draw_circle
+    DRAW_XBM,        // canvas_draw_xbm
+                     // custom draw objects
+    DRAW_ICON_EARTH, // 	canvas_draw_icon
+    DRAW_ICON_HOME,  // 	canvas_draw_icon
+    DRAW_ICON_INFO,  // 	canvas_draw_icon
+    DRAW_ICON_MAN,   // 	canvas_draw_man
+    DRAW_ICON_PLANT, // 	canvas_draw_icon
+    DRAW_ICON_TREE,  // 	canvas_draw_icon
+    DRAW_ICON_WOMAN, // 	canvas_draw_icon
+} FlipWorldDrawObjects;
+
+// Global variables to store camera position
+extern int camera_x;
+extern int camera_y;
+
+void draw_icon_line(Canvas *canvas, Vector pos, int amount, bool horizontal, const Icon *icon);
+void draw_icon_half_world(Canvas *canvas, bool right, const Icon *icon);
+
+// create custom icons at https://lopaka.app/sandbox

+ 39 - 0
draw/world.c

@@ -0,0 +1,39 @@
+#include <draw/world.h>
+
+void draw_world_example(Canvas *canvas)
+{
+    // Draw other elements adjusted by camera offset
+    // Static Dot at (72, 40)
+    canvas_draw_dot(canvas, 72 - camera_x, 40 - camera_y);
+
+    // Static Circle at (16, 16) with radius 4
+    canvas_draw_circle(canvas, 16 - camera_x, 16 - camera_y, 4);
+
+    // Static 8x8 Rectangle Frame at (96, 48)
+    canvas_draw_frame(canvas, 96 - camera_x, 48 - camera_y, 8, 8);
+
+    // Static earth icon at (112, 56)
+    canvas_draw_icon(canvas, 112 - camera_x, 56 - camera_y, &I_icon_earth);
+
+    // static home icon at (128, 24)
+    canvas_draw_icon(canvas, 128 - camera_x, 24 - camera_y, &I_icon_home);
+
+    // static menu icon at (144, 24)
+    canvas_draw_icon(canvas, 144 - camera_x, 24 - camera_y, &I_icon_info);
+
+    // static man icon at (160, 56)
+    canvas_draw_icon(canvas, 160 - camera_x, 56 - camera_y, &I_icon_man);
+
+    // static woman icon at (208, 56)
+    canvas_draw_icon(canvas, 168 - camera_x, 56 - camera_y, &I_icon_woman);
+
+    // static plant icon at (168, 32)
+    canvas_draw_icon(canvas, 168 - camera_x, 32 - camera_y, &I_icon_plant);
+
+    // tree world
+    draw_icon_half_world(canvas, true, &I_icon_tree);
+
+    // Draw the outer bounds adjusted by camera offset
+    // we draw this last to ensure users can see the bounds
+    canvas_draw_frame(canvas, -camera_x, -camera_y, WORLD_WIDTH, WORLD_HEIGHT);
+}

+ 4 - 0
draw/world.h

@@ -0,0 +1,4 @@
+#pragma once
+#include <draw/draw.h>
+
+void draw_world_example(Canvas *canvas);

+ 8 - 0
flip_world.h

@@ -14,6 +14,14 @@
 #define TAG "FlipWorld"
 #define VERSION_TAG "FlipWorld v0.1"
 
+// Screen size
+#define SCREEN_WIDTH 128
+#define SCREEN_HEIGHT 64
+
+// World size (3x3)
+#define WORLD_WIDTH 384
+#define WORLD_HEIGHT 192
+
 // Define the submenu items for our FlipWorld application
 typedef enum
 {

+ 2 - 80
game.c

@@ -37,52 +37,7 @@ Wall walls[] = {
     WALL(false, 26, 60, 6),
 };
 
-// Global variables to store camera position
-static int camera_x = 0;
-static int camera_y = 0;
-
-// Draw a line of icons (16 width)
-static void draw_icon_line(Canvas *canvas, Vector pos, int amount, bool horizontal, const Icon *icon)
-{
-    for (int i = 0; i < amount; i++)
-    {
-        if (horizontal)
-        {
-            // check if element is outside the world
-            if (pos.x + (i * 17) > WORLD_WIDTH)
-            {
-                break;
-            }
-
-            canvas_draw_icon(canvas, pos.x + (i * 17) - camera_x, pos.y - camera_y, icon);
-        }
-        else
-        {
-            // check if element is outside the world
-            if (pos.y + (i * 17) > WORLD_HEIGHT)
-            {
-                break;
-            }
-
-            canvas_draw_icon(canvas, pos.x - camera_x, pos.y + (i * 17) - camera_y, icon);
-        }
-    }
-}
-// Draw a half section of icons (16 width)
-void draw_icon_half_world(Canvas *canvas, bool right, const Icon *icon)
-{
-    for (int i = 0; i < 10; i++)
-    {
-        if (right)
-        {
-            draw_icon_line(canvas, (Vector){WORLD_WIDTH / 2 + 6, i * 19 + 2}, 11, true, icon);
-        }
-        else
-        {
-            draw_icon_line(canvas, (Vector){0, i * 19 + 2}, 11, true, icon);
-        }
-    }
-}
+// Tree World
 
 // Background rendering function
 // TODO: each object needs a collision box so we can detect collisions and prevent movement through walls.
@@ -99,40 +54,7 @@ static void background_render(Canvas *canvas, Vector pos)
     camera_x = CLAMP(camera_x, WORLD_WIDTH - SCREEN_WIDTH, 0);
     camera_y = CLAMP(camera_y, WORLD_HEIGHT - SCREEN_HEIGHT, 0);
 
-    // Draw other elements adjusted by camera offset
-    // Static Dot at (72, 40)
-    canvas_draw_dot(canvas, 72 - camera_x, 40 - camera_y);
-
-    // Static Circle at (16, 16) with radius 4
-    canvas_draw_circle(canvas, 16 - camera_x, 16 - camera_y, 4);
-
-    // Static 8x8 Rectangle Frame at (96, 48)
-    canvas_draw_frame(canvas, 96 - camera_x, 48 - camera_y, 8, 8);
-
-    // Static earth icon at (112, 56)
-    canvas_draw_icon(canvas, 112 - camera_x, 56 - camera_y, &I_icon_earth_15x16);
-
-    // static home icon at (128, 24)
-    canvas_draw_icon(canvas, 128 - camera_x, 24 - camera_y, &I_icon_home_15x16);
-
-    // static menu icon at (144, 24)
-    canvas_draw_icon(canvas, 144 - camera_x, 24 - camera_y, &I_icon_info_15x16);
-
-    // static man icon at (160, 56)
-    canvas_draw_icon(canvas, 160 - camera_x, 56 - camera_y, &I_icon_man_7x16);
-
-    // static woman icon at (208, 56)
-    canvas_draw_icon(canvas, 168 - camera_x, 56 - camera_y, &I_icon_woman_9x16);
-
-    // static plant icon at (168, 32)
-    canvas_draw_icon(canvas, 168 - camera_x, 32 - camera_y, &I_icon_plant_16x16);
-
-    // tree world
-    draw_icon_half_world(canvas, true, &I_icon_tree_16x16);
-
-    // Draw the outer bounds adjusted by camera offset
-    // we draw this last to ensure users can see the bounds
-    canvas_draw_frame(canvas, -camera_x, -camera_y, WORLD_WIDTH, WORLD_HEIGHT);
+    draw_world_example(canvas);
 }
 
 /****** Entities: Player ******/

+ 1 - 28
game.h

@@ -1,12 +1,6 @@
 #pragma once
 #include "engine/engine.h"
-
-// Screen size
-#define SCREEN_WIDTH 128
-#define SCREEN_HEIGHT 64
-// World size (3x3)
-#define WORLD_WIDTH 384
-#define WORLD_HEIGHT 192
+#include <draw/world.h>
 
 // from https://github.com/jamisonderek/flipper-zero-tutorials/blob/main/vgm/apps/air_labyrinth/walls.h
 typedef struct
@@ -27,24 +21,3 @@ typedef struct
 {
     uint32_t score;
 } GameContext;
-
-typedef enum
-{
-    // system draw objects
-    DRAW_DOT,        // canvas_draw_dot
-    DRAW_LINE,       // canvas_draw_line
-    DRAW_BOX,        // canvas_draw_box
-    DRAW_FRAME,      // canvas_draw_frame
-    DRAW_CIRCLE,     // canvas_draw_circle
-    DRAW_XBM,        // canvas_draw_xbm
-                     // custom draw objects
-    DRAW_ICON_EARTH, // 	canvas_draw_icon
-    DRAW_ICON_HOME,  // 	canvas_draw_icon
-    DRAW_ICON_INFO,  // 	canvas_draw_icon
-    DRAW_ICON_MAN,   // 	canvas_draw_man
-    DRAW_ICON_PLANT, // 	canvas_draw_icon
-    DRAW_ICON_TREE,  // 	canvas_draw_icon
-    DRAW_ICON_WOMAN, // 	canvas_draw_icon
-} FlipWorldDrawObjects;
-
-// create custom icons at https://lopaka.app/sandbox