summaryrefslogtreecommitdiff
path: root/src/warp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/warp.c')
-rw-r--r--src/warp.c62
1 files changed, 62 insertions, 0 deletions
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;
+}