From 0c631edd0994dc4c842d59a6466e77e833be3378 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 13 May 2018 08:59:30 +0100 Subject: [PATCH] Start of map mirroring. --- src/defs.h | 4 +++ src/entities/blobs/bob.c | 5 ++++ src/entities/structures/door.c | 5 ++++ src/entities/structures/lift.c | 5 ++++ src/entities/structures/lift.h | 1 + src/entities/structures/teleporter.h | 1 + src/main.c | 10 ++----- src/main.h | 2 +- src/test/worldTest.c | 4 +-- src/world/entities.c | 39 ++++++++++++++++++++++++++++ src/world/map.c | 25 ++++++++++++++++++ src/world/map.h | 1 + src/world/worldLoader.c | 13 ++++++++++ 13 files changed, 104 insertions(+), 11 deletions(-) diff --git a/src/defs.h b/src/defs.h index 80207c3..12cca9c 100644 --- a/src/defs.h +++ b/src/defs.h @@ -79,6 +79,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAP_TILE_OUTSIDE 255 #define MAP_TILE_MAX 256 +/* for mirroring */ +#define MAP_PIXEL_WIDTH (MAP_WIDTH * MAP_TILE_SIZE) + #define JUMP_POWER -12 #define MAX_OXYGEN (FPS * 10) #define MAX_KEY_TYPES 8 @@ -144,6 +147,7 @@ enum #define EF_NO_OBSERVE (2 << 18) #define EF_BULLET_HIT (2 << 19) #define EF_CRUSHABLE (2 << 20) +#define EF_MIRROR (2 << 21) #define GRAVITY_POWER 0.5f #define FRICTION 0.75f diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index e8a798e..18199b7 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -705,6 +705,11 @@ static void load(cJSON *root) world.bob->x = cJSON_GetObjectItem(root, "x")->valueint; world.bob->y = cJSON_GetObjectItem(root, "y")->valueint; world.bob->facing = lookup(cJSON_GetObjectItem(root, "facing")->valuestring); + + if (game.plus & PLUS_MIRROR) + { + world.bob->x = MAP_PIXEL_WIDTH - world.bob->x; + } } static void save(cJSON *root) diff --git a/src/entities/structures/door.c b/src/entities/structures/door.c index b00b9bb..d077967 100644 --- a/src/entities/structures/door.c +++ b/src/entities/structures/door.c @@ -316,6 +316,11 @@ static void load(cJSON *root) s->closedX = cJSON_GetObjectItem(root, "closedX")->valueint; s->closedY = cJSON_GetObjectItem(root, "closedY")->valueint; } + + if (game.plus & PLUS_MIRROR) + { + s->tx = MAP_PIXEL_WIDTH - s->tx; + } } static void save(cJSON *root) diff --git a/src/entities/structures/lift.c b/src/entities/structures/lift.c index 409f9b2..416ecda 100644 --- a/src/entities/structures/lift.c +++ b/src/entities/structures/lift.c @@ -144,6 +144,11 @@ static void load(cJSON *root) s->startX = cJSON_GetObjectItem(root, "startX")->valueint; s->startY = cJSON_GetObjectItem(root, "startY")->valueint; s->waitTime = cJSON_GetObjectItem(root, "waitTime")->valueint; + + if (game.plus & PLUS_MIRROR) + { + s->tx = MAP_PIXEL_WIDTH - s->tx; + } } static void save(cJSON *root) diff --git a/src/entities/structures/lift.h b/src/entities/structures/lift.h index 343625e..382834c 100644 --- a/src/entities/structures/lift.h +++ b/src/entities/structures/lift.h @@ -32,3 +32,4 @@ extern void setGameplayMessage(int type, char *format, ...); extern App app; extern Entity *self; +extern Game game; diff --git a/src/entities/structures/teleporter.h b/src/entities/structures/teleporter.h index daa1597..acdd242 100644 --- a/src/entities/structures/teleporter.h +++ b/src/entities/structures/teleporter.h @@ -32,3 +32,4 @@ extern void teleportEntity(Entity *e, float tx, float ty); extern App app; extern Entity *self; +extern Game game; diff --git a/src/main.c b/src/main.c index be3355a..f1efeb3 100644 --- a/src/main.c +++ b/src/main.c @@ -111,11 +111,10 @@ static long capFrameRate(const long then) static void handleCommandLine(int argc, char *argv[]) { - int i, plus; + int i; char *worldId; worldId = NULL; - plus = PLUS_NONE; for (i = 1 ; i < argc ; i++) { @@ -183,16 +182,11 @@ static void handleCommandLine(int argc, char *argv[]) initCredits(); return; } - - if (strcmp(argv[i], "-plus") == 0) - { - plus = atoi(argv[++i]); - } } if (worldId != NULL) { - initWorldTest(worldId, plus); + initWorldTest(worldId); } else { diff --git a/src/main.h b/src/main.h index 986e780..62cfeda 100644 --- a/src/main.h +++ b/src/main.h @@ -31,7 +31,7 @@ extern void init18N(int argc, char *argv[]); extern void initGameSystem(void); extern void initLookups(void); extern void initSDL(void); -extern void initWorldTest(char *worldId, int plus); +extern void initWorldTest(char *worldId); extern void initEnding(void); extern void initCredits(void); extern void prepareScene(void); diff --git a/src/test/worldTest.c b/src/test/worldTest.c index c80eb7a..b129267 100644 --- a/src/test/worldTest.c +++ b/src/test/worldTest.c @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "worldTest.h" -void initWorldTest(char *worldId, int plus) +void initWorldTest(char *worldId) { loadGame(0); @@ -30,7 +30,7 @@ void initWorldTest(char *worldId, int plus) { STRNCPY(game.worldId, worldId, MAX_NAME_LENGTH); - game.plus = plus; + game.plus = PLUS_MIRROR; initWorld(); } diff --git a/src/world/entities.c b/src/world/entities.c index 014c0bb..888dc1e 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -37,6 +37,7 @@ static void compareEnvironments(void); static int getMarkerType(void); static int drawComparator(const void *a, const void *b); static void checkStuckInWall(void); +static void mirror(void); static Entity *riders[MAX_RIDERS]; static Entity *touched[MAX_TOUCHED]; @@ -68,6 +69,8 @@ void initEntities(void) self->w = r->w; self->h = r->h; + + mirror(); } addToQuadtree(self, &world.quadtree); @@ -103,6 +106,8 @@ void doEntities(void) self->w = r->w; self->h = r->h; + + mirror(); } removeFromQuadtree(self, &world.quadtree); @@ -1138,6 +1143,40 @@ static int drawComparator(const void *a, const void *b) return e2->type - e1->type; } +static void mirror(void) +{ + Structure *s; + + if (self->flags & EF_MIRROR) + { + switch (self->type) + { + case ET_DOOR: + break; + + case ET_LIFT: + s = (Structure*)self; + if (s->tx == s->x) + { + s->tx -= self->w; + } + break; + + case ET_TELEPORTER: + s = (Structure*)self; + s->tx -= self->w; + break; + + default: + break; + } + + self->x -= self->w; + + self->flags &= ~EF_MIRROR; + } +} + void destroyEntities(void) { Entity *e; diff --git a/src/world/map.c b/src/world/map.c index f65da31..dee61ae 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -24,6 +24,7 @@ static void loadMapData(void); static void loadCommonTiles(void); static void loadTileset(void); static void loadDecals(void); +static void mirrorMap(void); static SDL_Rect *loadTile(char *filename); static int MAX_Y; @@ -287,9 +288,33 @@ static void loadMapData(void) free(data); + if (game.plus & PLUS_MIRROR) + { + mirrorMap(); + } + calculateMapBounds(); } +static void mirrorMap(void) +{ + int x, y, w, t1, t2; + + w = MAP_WIDTH - 1; + + for (y = 0 ; y < MAP_HEIGHT ; y++) + { + for (x = 0 ; x < MAP_WIDTH / 2 ; x++) + { + t1 = world.map.data[x][y]; + t2 = world.map.data[w - x][y]; + + world.map.data[x][y] = t2; + world.map.data[w - x][y] = t1; + } + } +} + static void loadCommonTiles(void) { int i; diff --git a/src/world/map.h b/src/world/map.h index ddc855b..c9c011e 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -29,4 +29,5 @@ extern int rrnd(int low, int high); extern App app; extern Camera camera; +extern Game game; extern World world; diff --git a/src/world/worldLoader.c b/src/world/worldLoader.c index 09fc467..a7f3258 100644 --- a/src/world/worldLoader.c +++ b/src/world/worldLoader.c @@ -142,6 +142,12 @@ static void loadTriggers(cJSON *root) t->y = cJSON_GetObjectItem(node, "y")->valueint; t->w = cJSON_GetObjectItem(node, "w")->valueint; t->h = cJSON_GetObjectItem(node, "h")->valueint; + + if (game.plus & PLUS_MIRROR) + { + t->x = MAP_PIXEL_WIDTH - t->x; + t->x -= t->w; + } } } @@ -190,6 +196,13 @@ static void loadEntities(cJSON *root) { self->alive = ALIVE_DEAD; } + + if (game.plus & PLUS_MIRROR) + { + self->x = MAP_PIXEL_WIDTH - self->x; + + self->flags |= EF_MIRROR; + } } }