Fill color directive
This commit is contained in:
parent
697272fe06
commit
469d02f166
1
app.c
1
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;
|
||||
|
||||
|
||||
|
5
app.h
5
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();
|
||||
|
21
app_file.c
21
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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
4
player.c
4
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);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <easyx.h>
|
||||
#include <wingdi.h>
|
||||
|
||||
|
||||
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 {
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user