From 469d02f166c6159f03f17169693f6ba5fbaa88b0 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Mon, 15 Apr 2024 16:21:24 +0800 Subject: [PATCH] Fill color directive --- app.c | 1 + app.h | 5 +++-- app_file.c | 21 +++++++++++++++++++++ app_render.cpp | 13 +++++++++++++ player.c | 4 ++-- render_bundle_draw.cpp | 3 ++- render_component.h | 5 ++++- 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app.c b/app.c index 57711c6..548c053 100644 --- a/app.c +++ b/app.c @@ -27,6 +27,7 @@ App *app_NewApp() { app->particle = particle_NewSystem(app); app->switch_level = NULL; + app->clear_color = 0; app->wantQuit = false; diff --git a/app.h b/app.h index c26eac6..9727ed9 100644 --- a/app.h +++ b/app.h @@ -22,8 +22,9 @@ typedef struct _App { System_Camera *camera; System_Particle *particle; - char *switch_level; - bool wantQuit; + char *switch_level; + uint32_t clear_color; + bool wantQuit; } App; App *app_NewApp(); diff --git a/app_file.c b/app_file.c index 533fd0d..5f31213 100644 --- a/app_file.c +++ b/app_file.c @@ -72,6 +72,13 @@ static inline Box2 readbox2() { Box2 box = {.lefttop = a, .size = b}; return box; } +static inline uint32_t readcolor() { + int r, g, b; + r = TOKEN_INT; + g = TOKEN_INT; + b = TOKEN_INT; + return (uint32_t)((r) | (g << 8) | (b << 16)); +} // Subsequent tokens can be read by strtok(NULL, " ") @@ -168,6 +175,20 @@ static void _app_LevelCommand(App *app, char *cmd) { app->player->cutoff = TOKEN_DOUBLE; } + CMD("BACKGROUND") { + app->clear_color = readcolor(); + } + + CMD("FILL") { + uint32_t color = readcolor(); + Box2 box = readbox2(); + + Entity *e = entity_Create(app->entity, cmd); + ADD_COMPONENT(e, render); + e->render->fillbox = box; + e->render->fillcolor = color; + } + else { WARN("unknown command \"%s\"", cmd); } diff --git a/app_render.cpp b/app_render.cpp index e0f41fe..4de2969 100644 --- a/app_render.cpp +++ b/app_render.cpp @@ -1,6 +1,7 @@ #include "app.h" #include "camera.h" +#include "mapper_misc.h" #include "particle.h" #include "physics.h" #include "easyx.h" @@ -56,6 +57,8 @@ void app_Render(App *app) { } if (e->misc->trigger_flags & misc_Hazard) setlinecolor(RGB(255, 0, 0)); + if (e->misc->trigger_flags & misc_CameraFocus) + setlinecolor(RGB(0, 255, 255)); if (e->misc->change_level) setlinecolor(RGB(255, 255, 0)); Box2 box; @@ -95,6 +98,16 @@ void app_Render(App *app) { Vec2 pos = {.x = 0.0, .y = 0.0}; if (e->position) pos = e->position->position; + // Has fillbox + if (r->fillbox.size.x > EPS) { + Box2 cam = camera_TransformBox2(app->camera, r->fillbox); + setfillcolor(r->fillcolor); + fillrectangle( + (int)round(cam.lefttop.x), + (int)round(cam.lefttop.y), + (int)round(cam.lefttop.x + cam.size.x), + (int)round(cam.lefttop.y + cam.size.y)); + } // Has bundle if (r->bundle) render_DrawBundleW(app, r->bundle, pos); diff --git a/player.c b/player.c index 04959f9..55374ad 100644 --- a/player.c +++ b/player.c @@ -178,8 +178,8 @@ void player_HazardHarm(System_Player *sys) { sys->player->super->position->position, vec2(speed_linear * cos(angle), speed_linear * sin(angle)), rand_DoubleRange(2, 3), - rand_DoubleRange(5, 30), - rand_DoubleRange(15, 22), + rand_DoubleRange(5, 28), + rand_DoubleRange(20, 32), duration_FromSeconds(0), &render_ModeDefault); } diff --git a/render_bundle_draw.cpp b/render_bundle_draw.cpp index 534f60a..88f21ad 100644 --- a/render_bundle_draw.cpp +++ b/render_bundle_draw.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace { @@ -27,7 +28,7 @@ extern "C" void render_DrawPrimitiveW(App *app, render_Primitive *p, Vec2 offset Vec2 screenpos; if (!app->camera) { // Really weird - fprintf(stderr, "[WARN][render_DrawPrimitiveW] called without a Camera system\n"); + WARN("called without a Camera system"); screenpos = realpos; needDraw = true; } else { diff --git a/render_component.h b/render_component.h index 8204209..7004f70 100644 --- a/render_component.h +++ b/render_component.h @@ -15,11 +15,14 @@ typedef void (*render_CustomFunc)(App *app, Entity *e, Vec2 entity_screen_pos, v // Rendering component. // This is mostly for components requiring static renders. typedef struct { - App *super; + Entity *super; render_Bundle *bundle; // A render bundle, usually found by render_FindBundle() render_CustomFunc custom; // Custom rendering function void *custom_data; // User data for the callback + + Box2 fillbox; // Fill box + uint32_t fillcolor; // Fill color } Component_Render;