jblanked hai 1 ano
pai
achega
342dc614a3
Modificáronse 6 ficheiros con 0 adicións e 604 borrados
  1. 0 80
      draw/draw.c
  2. 0 33
      draw/draw.h
  3. 0 214
      draw/world.c
  4. 0 8
      draw/world.h
  5. 0 252
      game.c
  6. 0 17
      game.h

+ 0 - 80
draw/draw.c

@@ -1,80 +0,0 @@
-#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);
-        }
-    }
-}
-const Icon *get_icon(char *name)
-{
-    if (strcmp(name, "earth") == 0)
-    {
-        return &I_icon_earth;
-    }
-    if (strcmp(name, "home") == 0)
-    {
-        return &I_icon_home;
-    }
-    if (strcmp(name, "info") == 0)
-    {
-        return &I_icon_info;
-    }
-    if (strcmp(name, "man") == 0)
-    {
-        return &I_icon_man;
-    }
-    if (strcmp(name, "plant") == 0)
-    {
-        return &I_icon_plant;
-    }
-    if (strcmp(name, "tree") == 0)
-    {
-        return &I_icon_tree;
-    }
-    if (strcmp(name, "woman") == 0)
-    {
-        return &I_icon_woman;
-    }
-    return NULL;
-}

+ 0 - 33
draw/draw.h

@@ -1,33 +0,0 @@
-#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);
-const Icon *get_icon(char *name);
-
-// create custom icons at https://lopaka.app/sandbox

+ 0 - 214
draw/world.c

@@ -1,214 +0,0 @@
-#include <draw/world.h>
-
-void draw_bounds(Canvas *canvas)
-{
-    // 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);
-}
-
-void draw_example_world(Level *level)
-{
-    spawn_icon(level, &I_icon_earth, 112, 56, 15, 16);
-    spawn_icon(level, &I_icon_home, 128, 24, 15, 16);
-    spawn_icon(level, &I_icon_info, 144, 24, 15, 16);
-    spawn_icon(level, &I_icon_man, 160, 56, 7, 16);
-    spawn_icon(level, &I_icon_woman, 168, 56, 9, 16);
-    spawn_icon(level, &I_icon_plant, 168, 32, 16, 16);
-}
-
-/* JSON of the draw_example_world with fields icon, x, y, width, height
-{
-    "name": "Example World",
-    "author": "JBlanked",
-    "json_data": [
-        {
-            "icon": "earth",
-            "x": 112,
-            "y": 56,
-            "width": 15,
-            "height": 16
-        },
-        {
-            "icon": "home",
-            "x": 128,
-            "y": 24,
-            "width": 15,
-            "height": 16
-        },
-        {
-            "icon": "info",
-            "x": 144,
-            "y": 24,
-            "width": 15,
-            "height": 16
-        },
-        {
-            "icon": "man",
-            "x": 160,
-            "y": 56,
-            "width": 7,
-            "height": 16
-        },
-        {
-            "icon": "woman",
-            "x": 168,
-            "y": 56,
-            "width": 9,
-            "height": 16
-        },
-        {
-            "icon": "plant",
-            "x": 168,
-            "y": 32,
-            "width": 16,
-            "height": 16
-        }
-    ]
-}
-
-*/
-
-bool draw_json_world(Level *level, FuriString *json_data)
-{
-    for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
-    {
-        char *data = get_json_array_value("json_data", i, (char *)furi_string_get_cstr(json_data), MAX_WORLD_TOKENS);
-        if (data == NULL)
-        {
-            break;
-        }
-        char *icon = get_json_value("icon", data, 64);
-        char *x = get_json_value("x", data, 64);
-        char *y = get_json_value("y", data, 64);
-        char *width = get_json_value("width", data, 64);
-        char *height = get_json_value("height", data, 64);
-        if (icon == NULL || x == NULL || y == NULL || width == NULL || height == NULL)
-        {
-            return false;
-        }
-        spawn_icon(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height));
-    }
-    return true;
-}
-
-void draw_tree_world(Level *level)
-{
-    // Spawn two full left/up tree lines
-    for (int i = 0; i < 2; i++)
-    {
-        for (int j = 0; j < 22; j++)
-        {
-            spawn_icon(level, &I_icon_tree, 5 + j * 17, 2 + i * 17, 16, 16); // Horizontal lines
-        }
-        for (int j = 0; j < 11; j++)
-        {
-            spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + j * 17, 16, 16); // Vertical lines
-        }
-    }
-
-    // Spawn two full down tree lines
-    for (int i = 9; i < 11; i++)
-    {
-        for (int j = 0; j < 22; j++)
-        {
-            spawn_icon(level, &I_icon_tree, 5 + j * 17, 2 + i * 17, 16, 16); // Horizontal lines
-        }
-    }
-
-    // Spawn two full right tree lines
-    for (int i = 20; i < 22; i++)
-    {
-        for (int j = 0; j < 8; j++)
-        {
-            spawn_icon(level, &I_icon_tree, 5 + i * 17, 50 + j * 17, 16, 16); // Vertical lines
-        }
-    }
-
-    // Spawn labyrinth lines
-    // Third line (14 left, 3 middle, 0 right) - exit line
-    for (int i = 0; i < 14; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 2 * 17, 16, 16);
-    }
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 16 * 17 + i * 17, 2 + 2 * 17, 16, 16);
-    }
-
-    // Fourth line (3 left, 6 middle, 4 right)
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 3 * 17, 16, 16); // 3 left
-    }
-    for (int i = 0; i < 6; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 7 * 17 + i * 17, 2 + 3 * 17, 16, 16); // 6 middle
-    }
-    for (int i = 0; i < 4; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 15 * 17 + i * 17, 2 + 3 * 17, 16, 16); // 4 right
-    }
-
-    // Fifth line (6 left, 7 middle, 0 right)
-    for (int i = 0; i < 6; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 4 * 17, 16, 16); // 6 left
-    }
-    for (int i = 0; i < 7; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 7 * 17 + i * 17, 2 + 4 * 17, 16, 16); // 7 middle
-    }
-
-    // Sixth line (5 left, 6 middle, 7 right)
-    for (int i = 0; i < 5; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 5 * 17, 16, 16); // 5 left
-    }
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 7 * 17 + i * 17, 2 + 5 * 17, 16, 16); // 3 middle
-    }
-    for (int i = 0; i < 7; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 15 * 17 + i * 17, 2 + 5 * 17, 16, 16); // 7 right
-    }
-
-    // Seventh line (0 left, 7 middle, 4 right)
-    for (int i = 0; i < 7; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 6 * 17 + i * 17, 2 + 6 * 17, 16, 16); // 7 middle
-    }
-    for (int i = 0; i < 4; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 14 * 17 + i * 17, 2 + 6 * 17, 16, 16); // 4 right
-    }
-
-    // Eighth line (4 left, 3 middle, 4 right)
-    for (int i = 0; i < 4; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 7 * 17, 16, 16); // 4 left
-    }
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 7 * 17 + i * 17, 2 + 7 * 17, 16, 16); // 3 middle
-    }
-    for (int i = 0; i < 4; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 15 * 17 + i * 17, 2 + 7 * 17, 16, 16); // 4 right
-    }
-
-    // Ninth line (3 left, 2 middle, 3 right)
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + i * 17, 2 + 8 * 17, 16, 16); // 3 left
-    }
-    for (int i = 0; i < 1; i++) // 2 middle
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 5 * 17 + i * 17, 2 + 8 * 17, 16, 16);
-    }
-    for (int i = 0; i < 3; i++)
-    {
-        spawn_icon(level, &I_icon_tree, 5 + 11 * 17 + i * 17, 2 + 8 * 17, 16, 16); // 3 right
-    }
-}

+ 0 - 8
draw/world.h

@@ -1,8 +0,0 @@
-#pragma once
-#include <draw/draw.h>
-#include <game.h>
-#include <flip_world.h>
-void draw_bounds(Canvas *canvas);
-void draw_example_world(Level *level);
-void draw_tree_world(Level *level);
-bool draw_json_world(Level *level, FuriString *json_data);

+ 0 - 252
game.c

@@ -1,252 +0,0 @@
-#include "game.h"
-#include "flip_world.h"
-#include "flip_world_icons.h"
-
-// Background rendering function
-// TODO: each object needs a collision box so we can detect collisions and prevent movement through walls.
-static void background_render(Canvas *canvas, Vector pos)
-{
-    // Clear the canvas
-    canvas_clear(canvas);
-
-    // Calculate camera offset to center the player
-    camera_x = pos.x - (SCREEN_WIDTH / 2);
-    camera_y = pos.y - (SCREEN_HEIGHT / 2);
-
-    // Clamp camera position to prevent showing areas outside the world
-    camera_x = CLAMP(camera_x, WORLD_WIDTH - SCREEN_WIDTH, 0);
-    camera_y = CLAMP(camera_y, WORLD_HEIGHT - SCREEN_HEIGHT, 0);
-
-    // Draw the outer bounds adjusted by camera offset
-    draw_bounds(canvas);
-}
-
-/****** Entities: Player ******/
-
-typedef struct
-{
-    Vector trajectory; // Direction player would like to move.
-    float radius;      // collision radius
-    int8_t dx;         // x direction
-    int8_t dy;         // y direction
-    Sprite *sprite;    // player sprite
-} PlayerContext;
-
-// Forward declaration of player_desc, because it's used in player_spawn function.
-static const EntityDescription player_desc;
-
-static void player_spawn(Level *level, GameManager *manager)
-{
-    Entity *player = level_add_entity(level, &player_desc);
-
-    // Set player position.
-    // Depends on your game logic, it can be done in start entity function, but also can be done here.
-    entity_pos_set(player, (Vector){WORLD_WIDTH / 2, WORLD_HEIGHT / 2});
-
-    // Add collision box to player entity
-    // Box is centered in player x and y, and it's size is 10x10
-    entity_collider_add_rect(player, 10, 10);
-
-    // Get player context
-    PlayerContext *player_context = entity_context_get(player);
-
-    // Load player sprite
-    player_context->sprite = game_manager_sprite_load(manager, "player.fxbm");
-}
-
-// Modify player_update to track direction
-static void player_update(Entity *self, GameManager *manager, void *context)
-{
-    PlayerContext *player = (PlayerContext *)context;
-    InputState input = game_manager_input_get(manager);
-    Vector pos = entity_pos_get(self);
-
-    // Reset direction each frame
-    player->dx = 0;
-    player->dy = 0;
-
-    if (input.held & GameKeyUp)
-    {
-        pos.y -= 2;
-        player->dy = -1;
-    }
-    if (input.held & GameKeyDown)
-    {
-        pos.y += 2;
-        player->dy = 1;
-    }
-    if (input.held & GameKeyLeft)
-    {
-        pos.x -= 2;
-        player->dx = -1;
-    }
-    if (input.held & GameKeyRight)
-    {
-        pos.x += 2;
-        player->dx = 1;
-    }
-
-    pos.x = CLAMP(pos.x, WORLD_WIDTH - 5, 5);
-    pos.y = CLAMP(pos.y, WORLD_HEIGHT - 5, 5);
-
-    entity_pos_set(self, pos);
-
-    if (input.pressed & GameKeyBack)
-    {
-        game_manager_game_stop(manager);
-    }
-}
-
-static void player_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
-{
-    // Get player context
-    UNUSED(manager);
-    PlayerContext *player = context;
-
-    // Get player position
-    Vector pos = entity_pos_get(self);
-
-    // Draw background (updates camera_x and camera_y)
-    background_render(canvas, pos);
-
-    // Draw player sprite relative to camera
-    canvas_draw_sprite(canvas, player->sprite, pos.x - camera_x - 5, pos.y - camera_y - 5);
-}
-
-static const EntityDescription player_desc = {
-    .start = NULL,                         // called when entity is added to the level
-    .stop = NULL,                          // called when entity is removed from the level
-    .update = player_update,               // called every frame
-    .render = player_render,               // called every frame, after update
-    .collision = NULL,                     // called when entity collides with another entity
-    .event = NULL,                         // called when entity receives an event
-    .context_size = sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
-};
-
-/****** Level ******/
-
-static void level_alloc(Level *level, GameManager *manager, void *context)
-{
-    UNUSED(manager);
-    UNUSED(context);
-
-    // Add player entity to the level
-    player_spawn(level, manager);
-
-    draw_tree_world(level);
-    // draw_example_world(level);
-}
-
-static const LevelBehaviour level = {
-    .alloc = level_alloc, // called once, when level allocated
-    .free = NULL,         // called once, when level freed
-    .start = NULL,        // called when level is changed to this level
-    .stop = NULL,         // called when level is changed from this level
-    .context_size = 0,    // size of level context, will be automatically allocated and freed
-};
-
-// Forward declaration of icon_desc
-static const EntityDescription icon_desc;
-
-static void icon_collision(Entity *self, Entity *other, GameManager *manager, void *context)
-{
-    UNUSED(manager);
-    UNUSED(self);
-    IconContext *icon = (IconContext *)context;
-    UNUSED(icon);
-    if (entity_description_get(other) == &player_desc)
-    {
-        PlayerContext *player = (PlayerContext *)entity_context_get(other);
-        if (player)
-        {
-            Vector pos = entity_pos_get(other);
-            // Bounce the player back by 3 units opposite their last movement direction
-            pos.x -= player->dx * 3;
-            pos.y -= player->dy * 3;
-            entity_pos_set(other, pos);
-        }
-    }
-}
-
-static void icon_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
-{
-    UNUSED(manager);
-    IconContext *icon_ctx = (IconContext *)context;
-    Vector pos = entity_pos_get(self);
-    canvas_draw_icon(canvas, pos.x - camera_x - 8, pos.y - camera_y - 8, icon_ctx->icon);
-}
-
-static void icon_start(Entity *self, GameManager *manager, void *context)
-{
-    UNUSED(manager);
-    UNUSED(context);
-    // Just add the collision rectangle for 16x16 icon
-    entity_collider_add_rect(self, 16, 16);
-}
-
-static const EntityDescription icon_desc = {
-    .start = icon_start,
-    .stop = NULL,
-    .update = NULL,
-    .render = icon_render,
-    .collision = icon_collision,
-    .event = NULL,
-    .context_size = sizeof(IconContext),
-};
-
-// Helper function to spawn an icon entity at a given position
-void spawn_icon(Level *level, const Icon *icon, float x, float y, uint8_t width, uint8_t height)
-{
-    Entity *e = level_add_entity(level, &icon_desc);
-    IconContext *icon_ctx = entity_context_get(e);
-    icon_ctx->icon = icon;
-    icon_ctx->width = width;
-    icon_ctx->height = height;
-    // Set the entity position to the center of the icon
-    entity_pos_set(e, (Vector){x + 8, y + 8});
-}
-
-/****** Game ******/
-
-/*
-    Write here the start code for your game, for example: creating a level and so on.
-    Game context is allocated (game.context_size) and passed to this function, you can use it to store your game data.
-*/
-static void game_start(GameManager *game_manager, void *ctx)
-{
-    UNUSED(game_manager);
-
-    // Do some initialization here, for example you can load score from storage.
-    // For simplicity, we will just set it to 0.
-    GameContext *game_context = ctx;
-    game_context->score = 0;
-
-    // Add level to the game
-    game_manager_add_level(game_manager, &level);
-}
-
-/*
-    Write here the stop code for your game, for example, freeing memory, if it was allocated.
-    You don't need to free level, sprites or entities, it will be done automatically.
-    Also, you don't need to free game_context, it will be done automatically, after this function.
-*/
-static void game_stop(void *ctx)
-{
-    UNUSED(ctx);
-    // GameContext *game_context = ctx;
-    //  Do some deinitialization here, for example you can save score to storage.
-    //  For simplicity, we will just print it.
-    // FURI_LOG_I("Game", "Your score: %lu", game_context->score);
-}
-
-/*
-    Your game configuration, do not rename this variable, but you can change its content here.
-*/
-const Game game = {
-    .target_fps = 60,                    // target fps, game will try to keep this value
-    .show_fps = false,                   // show fps counter on the screen
-    .always_backlight = true,            // keep display backlight always on
-    .start = game_start,                 // will be called once, when game starts
-    .stop = game_stop,                   // will be called once, when game stops
-    .context_size = sizeof(GameContext), // size of game context
-};

+ 0 - 17
game.h

@@ -1,17 +0,0 @@
-#pragma once
-#include "engine/engine.h"
-#include <draw/world.h>
-
-void spawn_icon(Level *level, const Icon *icon, float x, float y, uint8_t width, uint8_t height);
-
-typedef struct
-{
-    uint32_t score;
-} GameContext;
-
-typedef struct
-{
-    const Icon *icon;
-    uint8_t width;
-    uint8_t height;
-} IconContext;