abused macros
This commit is contained in:
parent
11b10c227c
commit
7fbb779c5f
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
typedef struct {
|
||||
int _;
|
||||
} DeathPart;
|
||||
|
||||
struct Entity;
|
||||
struct Game;
|
||||
|
||||
void deathpart_init(struct Entity *this, int x, int y);
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
25
src/exit.c
25
src/exit.c
|
@ -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;
|
||||
}
|
||||
|
|
31
src/player.c
31
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;
|
||||
|
|
Loading…
Reference in New Issue