summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/src/game.c b/src/game.c
index 5f18fe9..9663a1d 100644
--- a/src/game.c
+++ b/src/game.c
@@ -15,6 +15,8 @@ void g_map_next() {
}
void g_map_restart() {
+ setbgcolor(1, 1, 1);
+ setfgcolor(0, 0, 0);
g_spawn_entities();
}
@@ -22,11 +24,11 @@ Map *g_map() {
return VecMap_get(g->maps, g->map_id);
}
-#define PROCESS(X) \
- repeat (i, MAX_ENTITIES) { \
- const auto e = &g->entities[i]; \
- if (e->table != nullptr) \
- entity_method(e, #X); \
+#define PROCESS(X) \
+ repeat(i, MAX_ENTITIES) { \
+ const auto e = &g->entities[i]; \
+ if (e->table != nullptr) \
+ entity_method(e, #X); \
}
void g_update() {
@@ -35,7 +37,7 @@ void g_update() {
PROCESS(update);
PROCESS(update_post);
memset(&g->ev, 0, sizeof(g->ev));
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
auto e = &g->entities[i];
e->visible = e->visible_next;
}
@@ -54,8 +56,10 @@ void g_update() {
}
void g_draw(int x, int y) {
- int cx = g_map()->t2c->width * cfg.tile_width/2 - cfg.display_width/2;
- int cy = g_map()->t2c->height * cfg.tile_height/2 - cfg.display_height/2;
+ int cx =
+ g_map()->t2c->width * cfg.tile_width / 2 - cfg.display_width / 2;
+ int cy =
+ g_map()->t2c->height * cfg.tile_height / 2 - cfg.display_height / 2;
if (g->shake) {
cx += g->shake - rand() % (g->shake * 2);
cy += g->shake - rand() % (g->shake * 2);
@@ -71,7 +75,7 @@ void g_draw(int x, int y) {
Entity *g_new_entity(const char *type, bool init) {
assert(type != nullptr);
Entity *e = nullptr;
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
if (g->entities[i].table == nullptr) {
e = &g->entities[i];
break;
@@ -125,8 +129,9 @@ Entity *g_new_entity_t2c(const Tiled2cObject *t2c) {
type = "tile";
if (e_t2c->numobjects) {
Entity *e = nullptr;
- rfor (i, 0u, e_t2c->numobjects) {
- e = g_new_entity_t2c(&e_t2c->objects[i]);
+ rfor(i, 0u, e_t2c->numobjects) {
+ e = g_new_entity_t2c(
+ &e_t2c->objects[i]);
if (e == nullptr)
break;
e->pos.x += x - t2c->width / 2;
@@ -144,8 +149,7 @@ Entity *g_new_entity_t2c(const Tiled2cObject *t2c) {
e->t2c = t2c;
e->tile = t2c->tile;
- repeat (i, MAX_GROUP_WORDS)
- e->group[i] = groups.group[i];
+ repeat(i, MAX_GROUP_WORDS) e->group[i] = groups.group[i];
e->pos.x = x;
e->pos.y = y;
e->dim.x = (i32)t2c->width;
@@ -157,7 +161,7 @@ Entity *g_new_entity_t2c(const Tiled2cObject *t2c) {
}
Entity *g_get_entity(const char *type) {
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table != nullptr && !strcasecmp(e->table->name, type))
return e;
@@ -166,7 +170,7 @@ Entity *g_get_entity(const char *type) {
}
Entity *g_get_entity_t2c(u32 id) {
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table != nullptr && e->t2c && e->t2c->id == id)
return e;
@@ -175,7 +179,7 @@ Entity *g_get_entity_t2c(u32 id) {
}
void g_clear_entities() {
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table != nullptr)
entity_method(e, "deinit");
@@ -185,24 +189,25 @@ void g_clear_entities() {
void g_spawn_entities() {
g_clear_entities();
const auto map = g_map();
- rfor (i, 0u, map->t2c->numobjects) {
+ rfor(i, 0u, map->t2c->numobjects) {
const auto obj = &map->t2c->objects[i];
g_new_entity_t2c(obj);
}
- rfor (i, 0u, map->t2c->numlayers) {
+ rfor(i, 0u, map->t2c->numlayers) {
const auto lay = &map->t2c->layers[i];
if (!map_object_layer(lay))
continue;
Entity groups = {};
entity_append_groups(&groups, lay->class);
const auto visible = lay->visible && lay->opacity > .8;
- rfor (y, 0u, map->t2c->height) {
- rfor (x, 0u, map->t2c->width) {
+ rfor(y, 0u, map->t2c->height) {
+ rfor(x, 0u, map->t2c->width) {
const auto tile =
- lay->tilelayer.data[x + y*map->t2c->width];
+ lay->tilelayer
+ .data[x + y * map->t2c->width];
if (!tile)
continue;
- with (e, g_new_entity(lay->class, false)) {
+ with(e, g_new_entity(lay->class, false)) {
e->tile = visible ? tile : 0;
e->pos.x = x * map->t2c->tilewidth +
map->t2c->tilewidth / 2.;
@@ -218,13 +223,13 @@ void g_spawn_entities() {
}
}
}
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table != nullptr)
entity_method(e, "init_post");
}
plog("free groups");
- rfor (i, 1, MAX_GROUP_WORDS * 32 - 1) {
+ rfor(i, 1, MAX_GROUP_WORDS * 32 - 1) {
if (!g_group_count(i)) {
u32 r = 0;
while (i + r < MAX_GROUP_WORDS * 32 - 1 &&
@@ -241,7 +246,7 @@ void g_spawn_entities() {
u32 g_count(const char *type) {
u32 c = 0;
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table != nullptr && strcmp(e->table->name, type) == 0)
c += 1;
@@ -255,7 +260,7 @@ void g_shake(i32 duration) {
u32 g_group_count(u32 gid) {
u32 c = 0;
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table && entity_in_group(e, gid))
c += 1;
@@ -264,7 +269,7 @@ u32 g_group_count(u32 gid) {
}
void g_group_set_visibility(u32 gid, bool visible) {
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table && entity_in_group(e, gid))
e->visible_next = visible;
@@ -272,7 +277,7 @@ void g_group_set_visibility(u32 gid, bool visible) {
}
void g_group_set_flip(u32 gid, bool flip_x, bool flip_y) {
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table && entity_in_group(e, gid)) {
e->flip_x ^= flip_x;
@@ -283,7 +288,7 @@ void g_group_set_flip(u32 gid, bool flip_x, bool flip_y) {
VecEntityP *g_group(u32 gid) {
VecEntityP *v = VecEntityP_new(0);
- repeat (i, MAX_ENTITIES) {
+ repeat(i, MAX_ENTITIES) {
const auto e = &g->entities[i];
if (e->table && entity_in_group(e, gid))
VecEntityP_push(v, e);