diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-18 21:54:01 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-18 21:55:14 +0100 |
commit | 7fbb779c5f1055461b0f38d83035725ff7cd3b77 (patch) | |
tree | 5464128ba864878f252ed8b4ee6072a6618a2716 | |
parent | 11b10c227cfccec717b8b7206f33a8bce24a54dc (diff) | |
download | hyperultra-7fbb779c5f1055461b0f38d83035725ff7cd3b77.tar.gz |
abused macros
-rw-r--r-- | src/deathpart.c | 14 | ||||
-rw-r--r-- | src/deathpart.h | 10 | ||||
-rw-r--r-- | src/entity.h | 7 | ||||
-rw-r--r-- | src/entityimpl.h | 16 | ||||
-rw-r--r-- | src/exit.c | 25 | ||||
-rw-r--r-- | src/player.c | 31 |
6 files changed, 56 insertions, 47 deletions
diff --git a/src/deathpart.c b/src/deathpart.c new file mode 100644 index 0000000..e7a9dab --- /dev/null +++ b/src/deathpart.c @@ -0,0 +1,14 @@ +#include "entityimpl.h" + +IMPL_UPDATE() +} + +IMPL_DRAW() + LZY_DrawSetColor(BLACK); + LZY_DrawRect(this->pos[0] - this->width / 2, + this->pos[1] - this->height / 2, + this->width, this->height); +} + +IMPL_INIT(deathpart) +} diff --git a/src/deathpart.h b/src/deathpart.h new file mode 100644 index 0000000..fa6c432 --- /dev/null +++ b/src/deathpart.h @@ -0,0 +1,10 @@ +#pragma once + +typedef struct { + int _; +} DeathPart; + +struct Entity; +struct Game; + +void deathpart_init(struct Entity *this, int x, int y); diff --git a/src/entity.h b/src/entity.h index f8ab5ad..8878778 100644 --- a/src/entity.h +++ b/src/entity.h @@ -1,14 +1,16 @@ #pragma once #include "player.h" #include "exit.h" +#include "deathpart.h" #include <stdbool.h> struct Game; typedef enum { ET_NONE, - ET_PLAYER, - ET_EXIT + ET_player, + ET_exit, + ET_deathpart } EntityType; typedef struct Entity Entity; @@ -27,6 +29,7 @@ struct Entity { union { Player player; Exit exit; + DeathPart deathpart; }; }; diff --git a/src/entityimpl.h b/src/entityimpl.h new file mode 100644 index 0000000..2a866a0 --- /dev/null +++ b/src/entityimpl.h @@ -0,0 +1,16 @@ +#pragma once +#include "game.h" +#include "cfg.h" +#include "lzy.h" +#include <string.h> + +#define IMPL_UPDATE() static void update(Entity*this,Game*g){(void)this,(void)g; +#define IMPL_DRAW() static void draw(Entity*this,Game*g){(void)this,(void)g; +#define IMPL_INIT(X) void X##_init(Entity *this, int x, int y) { do { \ + memset(this, 0, sizeof(*this)); \ + this->update = update; \ + this->draw = draw; \ + this->pos[0] = x; \ + this->pos[1] = y; \ + this->type = ET_##X; \ +} while(0); @@ -1,29 +1,16 @@ -#include "exit.h" -#include "entity.h" -#include "game.h" -#include "cfg.h" -#include "lzy.h" -#include <string.h> +#include "entityimpl.h" -static void -exit_draw(Entity *this, Game *g) -{ - (void)g; +IMPL_UPDATE() +} + +IMPL_DRAW() LZY_DrawSetColor(BLACK); LZY_DrawRect(this->pos[0] - this->width / 2, this->pos[1] - this->height / 2, this->width, this->height); } -void -exit_init(Entity *this, int x, int y) -{ - memset(this, 0, sizeof(*this)); - this->pos[0] = x; - this->pos[1] = y; - this->type = ET_EXIT; - this->update = NULL; - this->draw = exit_draw; +IMPL_INIT(exit) this->width = 12; this->height = 12; } diff --git a/src/player.c b/src/player.c index 70ccb20..24d61b0 100644 --- a/src/player.c +++ b/src/player.c @@ -1,15 +1,8 @@ -#include "player.h" -#include "entity.h" -#include "game.h" -#include "lzy.h" -#include "cfg.h" +#include "entityimpl.h" #include "input.h" -#include <string.h> #include <math.h> -static void -player_update(Entity *this, Game *g) -{ +IMPL_UPDATE() const int on_ground = entity_collide(this, g, 0, 1); this->vel[0] = 2.0 * this->player.dirx; @@ -52,14 +45,11 @@ player_update(Entity *this, Game *g) if (this->bonk_ceiling) g->queue_restart_scene = true; - if (entity_place_meeting(this, g, ET_EXIT) != NULL) + if (entity_place_meeting(this, g, ET_exit) != NULL) g->queue_next_scene = true; } -static void -player_draw(Entity *this, Game *g) -{ - (void)g; +IMPL_DRAW() LZY_DrawSetColor(BLACK); int width = (int)(this->width / 2) * this->player.scale_x; int height = (int)(this->height / 2) * this->player.scale_y; @@ -68,20 +58,9 @@ player_draw(Entity *this, Game *g) LZY_DrawRect(this->pos[0] - width / 2, this->pos[1] - height / 2, width, height); - //LZY_DrawRect(this->pos[0] - width / 2 + 1, - // this->pos[1] - height / 2 + 1, - // width - 2, height - 2); } -void -player_init(Entity *this, int x, int y) -{ - memset(this, 0, sizeof(*this)); - this->pos[0] = x; - this->pos[1] = y; - this->type = ET_PLAYER; - this->update = player_update; - this->draw = player_draw; +IMPL_INIT(player) this->width = 12; this->height = 12; this->player.scale_x = 1.0; |