Fill color directive

This commit is contained in:
Edgaru089 2024-04-15 16:21:24 +08:00
parent 697272fe06
commit 469d02f166
7 changed files with 46 additions and 6 deletions

1
app.c
View File

@ -27,6 +27,7 @@ App *app_NewApp() {
app->particle = particle_NewSystem(app); app->particle = particle_NewSystem(app);
app->switch_level = NULL; app->switch_level = NULL;
app->clear_color = 0;
app->wantQuit = false; app->wantQuit = false;

5
app.h
View File

@ -22,8 +22,9 @@ typedef struct _App {
System_Camera *camera; System_Camera *camera;
System_Particle *particle; System_Particle *particle;
char *switch_level; char *switch_level;
bool wantQuit; uint32_t clear_color;
bool wantQuit;
} App; } App;
App *app_NewApp(); App *app_NewApp();

View File

@ -72,6 +72,13 @@ static inline Box2 readbox2() {
Box2 box = {.lefttop = a, .size = b}; Box2 box = {.lefttop = a, .size = b};
return box; 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, " ") // 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; 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 { else {
WARN("unknown command \"%s\"", cmd); WARN("unknown command \"%s\"", cmd);
} }

View File

@ -1,6 +1,7 @@
#include "app.h" #include "app.h"
#include "camera.h" #include "camera.h"
#include "mapper_misc.h"
#include "particle.h" #include "particle.h"
#include "physics.h" #include "physics.h"
#include "easyx.h" #include "easyx.h"
@ -56,6 +57,8 @@ void app_Render(App *app) {
} }
if (e->misc->trigger_flags & misc_Hazard) if (e->misc->trigger_flags & misc_Hazard)
setlinecolor(RGB(255, 0, 0)); setlinecolor(RGB(255, 0, 0));
if (e->misc->trigger_flags & misc_CameraFocus)
setlinecolor(RGB(0, 255, 255));
if (e->misc->change_level) if (e->misc->change_level)
setlinecolor(RGB(255, 255, 0)); setlinecolor(RGB(255, 255, 0));
Box2 box; Box2 box;
@ -95,6 +98,16 @@ void app_Render(App *app) {
Vec2 pos = {.x = 0.0, .y = 0.0}; Vec2 pos = {.x = 0.0, .y = 0.0};
if (e->position) if (e->position)
pos = e->position->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 // Has bundle
if (r->bundle) if (r->bundle)
render_DrawBundleW(app, r->bundle, pos); render_DrawBundleW(app, r->bundle, pos);

View File

@ -178,8 +178,8 @@ void player_HazardHarm(System_Player *sys) {
sys->player->super->position->position, sys->player->super->position->position,
vec2(speed_linear * cos(angle), speed_linear * sin(angle)), vec2(speed_linear * cos(angle), speed_linear * sin(angle)),
rand_DoubleRange(2, 3), rand_DoubleRange(2, 3),
rand_DoubleRange(5, 30), rand_DoubleRange(5, 28),
rand_DoubleRange(15, 22), rand_DoubleRange(20, 32),
duration_FromSeconds(0), duration_FromSeconds(0),
&render_ModeDefault); &render_ModeDefault);
} }

View File

@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <easyx.h> #include <easyx.h>
#include <wingdi.h>
namespace { namespace {
@ -27,7 +28,7 @@ extern "C" void render_DrawPrimitiveW(App *app, render_Primitive *p, Vec2 offset
Vec2 screenpos; Vec2 screenpos;
if (!app->camera) { if (!app->camera) {
// Really weird // Really weird
fprintf(stderr, "[WARN][render_DrawPrimitiveW] called without a Camera system\n"); WARN("called without a Camera system");
screenpos = realpos; screenpos = realpos;
needDraw = true; needDraw = true;
} else { } else {

View File

@ -15,11 +15,14 @@ typedef void (*render_CustomFunc)(App *app, Entity *e, Vec2 entity_screen_pos, v
// Rendering component. // Rendering component.
// This is mostly for components requiring static renders. // This is mostly for components requiring static renders.
typedef struct { typedef struct {
App *super; Entity *super;
render_Bundle *bundle; // A render bundle, usually found by render_FindBundle() render_Bundle *bundle; // A render bundle, usually found by render_FindBundle()
render_CustomFunc custom; // Custom rendering function render_CustomFunc custom; // Custom rendering function
void *custom_data; // User data for the callback void *custom_data; // User data for the callback
Box2 fillbox; // Fill box
uint32_t fillcolor; // Fill color
} Component_Render; } Component_Render;