summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2024-07-13 14:59:20 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2024-07-13 14:59:20 +0200
commit1d2515ef96ca701dfbd6a906f371c91335533b93 (patch)
treeaa4b3511742d13a7f397c3666a4194761a5ed21e /src/server.c
parent60e11c18b8ac11645c86eb80ae6a7e8555815f53 (diff)
player can collect flowersHEADmain
Signed-off-by: Lizzy Fleckenstein <lizzy@vlhl.dev>
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/server.c b/src/server.c
index db599c7..fac95b1 100644
--- a/src/server.c
+++ b/src/server.c
@@ -49,6 +49,9 @@ typedef struct {
MAYBE(pos)
+#define FPOS "(%"PRIi32" ,%"PRIi32", %"PRIi8")"
+#define PPOS(pos) (pos).xy.x, (pos).xy.y, (pos).z
+
typedef struct {
const char *filename;
str name;
@@ -92,6 +95,11 @@ srv_entity *entity_from_id(game *g, entity_id id)
return NULL;
}
+bool pos_eq(pos a, pos b)
+{
+ return vec2_eq(a.xy, b.xy) && a.z == b.z;
+}
+
pos entity_pos(srv_entity *e)
{
return (pos) { e->base.pos, e->z };
@@ -433,6 +441,19 @@ bool handle_hi(str pkt, player *p, game *g)
return true;
}
+static str flower_name(flower_type t)
+{
+ switch (t) {
+ case FLOWER_ROSE: return S("rose");
+ case FLOWER_HIBISCUS: return S("hibiscus");
+ case FLOWER_SUNFLOWER: return S("sunflower");
+ case FLOWER_TULIP: return S("tulip");
+ case FLOWER_DANDELION: return S("dandelion");
+ case FLOWER_COUNT: break;
+ }
+ return S("???");
+}
+
bool handle_move(str pkt, player *p, game *g)
{
dir d;
@@ -444,18 +465,30 @@ bool handle_move(str pkt, player *p, game *g)
srv_entity *e = entity_from_id(g, p->id);
- pos old_pos = entity_pos(e);
-
// yolo
+ pos old_pos = entity_pos(e);
e->base.pos = vec2_add(v, e->base.pos);
-
pos new_pos = entity_pos(e);
moved_entity(g, e, some_pos(old_pos), some_pos(new_pos));
-
// TODO: only send newly visible nodes
send_nodes(p, g, player_sight(new_pos.xy), new_pos.z);
+ e = NULL; // will be invalidated!
+
+ // epic flower collision
+ ARR_ITER(g->entities, iter) {
+ if (pos_eq(new_pos, entity_pos(iter)) && iter->base.type == ENTITY_FLOWER) {
+ printf("player %.*s collected flower of type %.*s at "FPOS"\n",
+ PSTR(p->name), PSTR(flower_name(iter->base.flower)), PPOS(new_pos));
+
+ // TODO: add item to inventory
+
+ remove_entity(g, iter);
+ iter--;
+ }
+ }
+
return true;
}