From 99ab9bd22be2506c23d1e379f35583ddab4eadf6 Mon Sep 17 00:00:00 2001 From: zlago Date: Fri, 4 Oct 2024 21:38:14 +0200 Subject: map transitions --- src/warp.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/warp.c (limited to 'src/warp.c') diff --git a/src/warp.c b/src/warp.c new file mode 100644 index 0000000..f36b716 --- /dev/null +++ b/src/warp.c @@ -0,0 +1,62 @@ +#include "main.h" +#include "entity.h" +#include "loader.h" +#include "tilemap.h" + +static int warp_update(struct warp *self) { + if ( + self->hitbox.left < entities.player[0].hitbox.right && + self->hitbox.right > entities.player[0].hitbox.left && + self->hitbox.top < entities.player[0].hitbox.bottom && + self->hitbox.bottom > entities.player[0].hitbox.top + ) { + if (self->ext == NULL) { + return 0; + } + game_next_level = self->ext; + memcpy(next_entities.player, entities.player, sizeof (entities.player)); + next_entities.player[0].x = self->tox * 16; + next_entities.player[0].y = self->toy * 16; + game_state = STATE_FADE_IN; + self->ext = NULL; + return 0; + } + return 0; +} + +struct warp *warp_new(struct entities *entities) { + entities->warp[entities->warps] = (struct warp) { + .update = warp_update, + .x = 0, .y = 0, + .w = 0, .h = 0, + .tox = 0, .toy = 0, + .hitbox = { + 0, 0, 0, 0, + }, + .timer = 0, + .ext = NULL, + }; + return entities->warp + entities->warps++; +} + +int warp_property(struct warp *const restrict self, char const *const restrict property, char const *const restrict value) { + if (strcmp(property, "x") == 0) { + self->x = atoi(value); + } else if (strcmp(property, "y") == 0) { + self->y = atoi(value); + } else if (strcmp(property, "width") == 0) { + self->w = atoi(value); + } else if (strcmp(property, "height") == 0) { + self->h = atoi(value); + } else if (strcmp(property, "tox") == 0) { + self->tox = atoi(value); + } else if (strcmp(property, "toy") == 0) { + self->toy = atoi(value); + } else if (strcmp(property, "map") == 0) { + self->ext = value; + } else { + return 1; + } + self->hitbox = (struct hitbox) {.left = self->x, .top = self->y, .right = self->x + self->w, .bottom = self->y + self->h}; + return 0; +} -- cgit 1.4.1-2-gfad0