Start of map mirroring.

This commit is contained in:
Steve 2018-05-13 08:59:30 +01:00
parent 05e7fc7cad
commit 0c631edd09
13 changed files with 104 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -32,3 +32,4 @@ extern void setGameplayMessage(int type, char *format, ...);
extern App app;
extern Entity *self;
extern Game game;

View File

@ -32,3 +32,4 @@ extern void teleportEntity(Entity *e, float tx, float ty);
extern App app;
extern Entity *self;
extern Game game;

View File

@ -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
{

View File

@ -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);

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -29,4 +29,5 @@ extern int rrnd(int low, int high);
extern App app;
extern Camera camera;
extern Game game;
extern World world;

View File

@ -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;
}
}
}