added tombstones to everything -- lazy deletion of objects allows more robust behavior
This commit is contained in:
parent
b8eb524afb
commit
ff46718f04
8 changed files with 162 additions and 143 deletions
|
@ -25,6 +25,7 @@ HyperKaos* newHyperKaos(int id, int type, int x, int y, int w, int h)
|
||||||
self->domain.h = h;
|
self->domain.h = h;
|
||||||
self->kaosID = id;
|
self->kaosID = id;
|
||||||
self->eventType = type;
|
self->eventType = type;
|
||||||
|
self->tombStone = 0;
|
||||||
self->head = NULL;
|
self->head = NULL;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -4,6 +4,8 @@ typedef struct hyperKaos
|
||||||
{
|
{
|
||||||
int kaosID;
|
int kaosID;
|
||||||
int eventType;
|
int eventType;
|
||||||
|
int tombStone;
|
||||||
|
|
||||||
SDL_Rect domain;
|
SDL_Rect domain;
|
||||||
Kaos* head;
|
Kaos* head;
|
||||||
} HyperKaos;
|
} HyperKaos;
|
||||||
|
|
13
Player.c
13
Player.c
|
@ -60,6 +60,7 @@ Player* newPlayer(char* filename, int a, int b)
|
||||||
self->frontFaceBox.y = self->boundBox.y + 16;
|
self->frontFaceBox.y = self->boundBox.y + 16;
|
||||||
self->frontFaceBox.w = 16;
|
self->frontFaceBox.w = 16;
|
||||||
self->frontFaceBox.h = 16;
|
self->frontFaceBox.h = 16;
|
||||||
|
self->tombStone = 0;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -149,16 +150,16 @@ void movePlayer(Player* self, Room* hereNow)
|
||||||
{
|
{
|
||||||
if (checkWCollision(rightHere, &(self->boundBox), rightHere->warps, &outgoing))
|
if (checkWCollision(rightHere, &(self->boundBox), rightHere->warps, &outgoing))
|
||||||
{
|
{
|
||||||
nextChunk = ((rightHere->warps) + outgoing)->chunk;
|
nextChunk = rightHere->warps[outgoing]->chunk;
|
||||||
|
|
||||||
if (nextChunk != thisChunk)
|
if (nextChunk != thisChunk)
|
||||||
{
|
{
|
||||||
bufferData(((hereNow->warps) + outgoing)->chunk);
|
bufferData(hereNow->warps[outgoing]->chunk);
|
||||||
warpto(mapBuffer[((rightHere->warps) + outgoing)->destination]);
|
warpto(mapBuffer[rightHere->warps[outgoing]->destination]);
|
||||||
}
|
}
|
||||||
else warpto(mapData[((rightHere->warps) + outgoing)->destination]);
|
else warpto(mapData[rightHere->warps[outgoing]->destination]);
|
||||||
self->point.x = ((hereNow->warps) + outgoing)->x;
|
self->point.x = hereNow->warps[outgoing]->x;
|
||||||
self->point.y = ((hereNow->warps) + outgoing)->y;
|
self->point.y = hereNow->warps[outgoing]->y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//stay onscreen
|
//stay onscreen
|
||||||
|
|
1
Player.h
1
Player.h
|
@ -14,6 +14,7 @@ typedef struct player
|
||||||
SDL_Rect frontFaceBox;
|
SDL_Rect frontFaceBox;
|
||||||
SDL_Surface* spriteSheet;
|
SDL_Surface* spriteSheet;
|
||||||
SDL_Surface* sprite;
|
SDL_Surface* sprite;
|
||||||
|
int tombStone;
|
||||||
|
|
||||||
} Player;
|
} Player;
|
||||||
|
|
||||||
|
|
251
Room.c
251
Room.c
|
@ -19,21 +19,88 @@ typedef struct textBox TextBox;
|
||||||
typedef struct scene Scene;
|
typedef struct scene Scene;
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
|
Obstruction* newObstruction(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
Obstruction* self = malloc(sizeof(Obstruction));
|
||||||
|
self->domain.x = x;
|
||||||
|
self->domain.y = y;
|
||||||
|
self->domain.w = w;
|
||||||
|
self->domain.h = h;
|
||||||
|
self->tombStone = 0;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteObstruction(Obstruction* target)
|
||||||
|
{
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
FGImage* newFGImage(int x, int y, int w, int h, int f, int dual, char* filename, int alpha)
|
||||||
|
{
|
||||||
|
FGImage* self = malloc(sizeof(FGImage));
|
||||||
|
|
||||||
|
self->location.x = x;
|
||||||
|
self->location.y = y;
|
||||||
|
self->location.w = w;
|
||||||
|
self->location.h = h;
|
||||||
|
|
||||||
|
self->frames = f;
|
||||||
|
self->frameNow = 0;
|
||||||
|
self->dualLayer = dual;
|
||||||
|
self->tombStone = 0;
|
||||||
|
|
||||||
|
self->spriteSheet = loadImage(filename);
|
||||||
|
if (alpha != 255)
|
||||||
|
SDL_SetAlpha(self->spriteSheet, SDL_SRCALPHA|SDL_RLEACCEL, alpha);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFGImage(FGImage* target)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(target->spriteSheet);
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
WarpZone* newWarpZone(int x, int y, int w, int h, enum dataChunks chunk, int dest, int dX, int dY)
|
||||||
|
{
|
||||||
|
WarpZone* self = malloc(sizeof(WarpZone));
|
||||||
|
|
||||||
|
self->location.x = x;
|
||||||
|
self->location.y = y;
|
||||||
|
self->location.w = w;
|
||||||
|
self->location.h = h;
|
||||||
|
|
||||||
|
self->chunk = chunk;
|
||||||
|
self->destination = dest;
|
||||||
|
self->x = dX;
|
||||||
|
self->y = dY;
|
||||||
|
self->tombStone = 0;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteWarpZone(WarpZone* target)
|
||||||
|
{
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
Room* newRoom(char* filename, int a)
|
Room* newRoom(char* filename, int a)
|
||||||
{
|
{
|
||||||
Room* self = (Room*)malloc(sizeof(Room));
|
Room* self = (Room*)malloc(sizeof(Room));
|
||||||
|
|
||||||
self->obstacle = malloc(4*sizeof(SDL_Rect));
|
self->obstacle = malloc(4*sizeof(Obstruction*));
|
||||||
self->numberOfObstacles = 0;
|
self->numberOfObstacles = 0;
|
||||||
self->maxNumberOfObstacles = 4;
|
self->maxNumberOfObstacles = 4;
|
||||||
|
|
||||||
self->fgObject = malloc(4*sizeof(FGImage));
|
self->fgObject = malloc(4*sizeof(FGImage*));
|
||||||
self->numberOfObj = 0;
|
self->numberOfObj = 0;
|
||||||
self->maxNumberOfObj = 4;
|
self->maxNumberOfObj = 4;
|
||||||
self->objSpeed = a;
|
self->objSpeed = a;
|
||||||
self->objIterator = 0;
|
self->objIterator = 0;
|
||||||
|
|
||||||
self->warps = malloc(4*sizeof(WarpZone));
|
self->warps = malloc(4*sizeof(WarpZone*));
|
||||||
self->numberOfWarps = 0;
|
self->numberOfWarps = 0;
|
||||||
self->maxNumberOfWarps = 4;
|
self->maxNumberOfWarps = 4;
|
||||||
|
|
||||||
|
@ -65,33 +132,35 @@ Room* newRoom(char* filename, int a)
|
||||||
void deleteRoom(Room* target)
|
void deleteRoom(Room* target)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
for (i = 0; i < target->numberOfObstacles; i++)
|
||||||
|
deleteObstruction(target->obstacle[i]);
|
||||||
free(target->obstacle);
|
free(target->obstacle);
|
||||||
target->obstacle = NULL;
|
target->obstacle = NULL;
|
||||||
|
|
||||||
for (i = 0; i < target->numberOfObj; i++)
|
for (i = 0; i < target->numberOfObj; i++)
|
||||||
{
|
deleteFGImage(target->fgObject[i]);
|
||||||
SDL_FreeSurface(target->fgObject[i].spriteSheet);
|
|
||||||
target->fgObject[i].spriteSheet = NULL;
|
|
||||||
}
|
|
||||||
free(target->fgObject);
|
free(target->fgObject);
|
||||||
target->fgObject = NULL;
|
target->fgObject=NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < target->numberOfWarps; i++)
|
||||||
|
deleteWarpZone(target->warps[i]);
|
||||||
free(target->warps);
|
free(target->warps);
|
||||||
target->warps = NULL;
|
target->warps = NULL;
|
||||||
|
|
||||||
for (i = 0; i < target->numberOfTriggers; i++)
|
for (i = 0; i < target->numberOfTriggers; i++)
|
||||||
{
|
|
||||||
deleteHyperKaos(target->eventTriggers[i]);
|
deleteHyperKaos(target->eventTriggers[i]);
|
||||||
}
|
|
||||||
free(target->eventTriggers);
|
free(target->eventTriggers);
|
||||||
target->eventTriggers = NULL;
|
target->eventTriggers = NULL;
|
||||||
|
|
||||||
for (i = 0; i < target->numberOfPeople; i++)
|
for (i = 0; i < target->numberOfPeople; i++)
|
||||||
{
|
|
||||||
killPlayer(target->people[i]);
|
killPlayer(target->people[i]);
|
||||||
}
|
|
||||||
free(target->people);
|
free(target->people);
|
||||||
|
target->people=NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < target->numberOfSigils; i++)
|
||||||
|
deleteSynergy(target->sigils[i]);
|
||||||
|
free(target->sigils);
|
||||||
|
target->sigils = NULL;
|
||||||
|
|
||||||
SDL_FreeSurface(target->spriteSheet);
|
SDL_FreeSurface(target->spriteSheet);
|
||||||
SDL_FreeSurface(target->bgImage);
|
SDL_FreeSurface(target->bgImage);
|
||||||
|
@ -158,13 +227,13 @@ void animate(Room* self)
|
||||||
// collision detection
|
// collision detection
|
||||||
//
|
//
|
||||||
|
|
||||||
int checkCollision(Room* self, Player* player, SDL_Rect* box)
|
int checkCollision(Room* self, Player* player, Obstruction** box)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i <= self->numberOfObstacles; i++)
|
for (i = 1; i <= self->numberOfObstacles; i++)
|
||||||
{
|
{
|
||||||
if (playerIsInRect(player, box))
|
if (!((*box)->tombStone) && playerIsInRect(player, &(*box)->domain))
|
||||||
// if ( (playerX >= box->x && playerX <= box->x + box->w)
|
// if ( (playerX >= box->x && playerX <= box->x + box->w)
|
||||||
// && (playerY >= box->y && playerY <= box->y + box->h) )
|
// && (playerY >= box->y && playerY <= box->y + box->h) )
|
||||||
{
|
{
|
||||||
|
@ -175,7 +244,7 @@ int checkCollision(Room* self, Player* player, SDL_Rect* box)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkWCollision(Room* self, SDL_Rect* player, WarpZone* warpBoxes, int* whichWarp)
|
int checkWCollision(Room* self, SDL_Rect* player, WarpZone** warpBoxes, int* whichWarp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int playerX = player->x + (player->w)/2;
|
int playerX = player->x + (player->w)/2;
|
||||||
|
@ -183,8 +252,10 @@ int checkWCollision(Room* self, SDL_Rect* player, WarpZone* warpBoxes, int* whic
|
||||||
|
|
||||||
for (i = 1; i <= self->numberOfWarps; i++)
|
for (i = 1; i <= self->numberOfWarps; i++)
|
||||||
{
|
{
|
||||||
if ( (playerX >= (warpBoxes->location).x && playerX <= (warpBoxes->location).x + (warpBoxes->location).w)
|
if (
|
||||||
&& (playerY >= (warpBoxes->location).y && playerY <= (warpBoxes->location).y + (warpBoxes->location).h))
|
!((*warpBoxes)->tombStone) &&
|
||||||
|
(playerX >= (*warpBoxes)->location.x && playerX <= ((*warpBoxes)->location.x + (*warpBoxes)->location.w)
|
||||||
|
&& playerY >= (*warpBoxes)->location.y && playerY <= ((*warpBoxes)->location.y + (*warpBoxes)->location.h)) )
|
||||||
{
|
{
|
||||||
*whichWarp = i-1;
|
*whichWarp = i-1;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -203,7 +274,8 @@ int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whi
|
||||||
for (i = 1; i <= self->numberOfTriggers; i++)
|
for (i = 1; i <= self->numberOfTriggers; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( (playerX > ((*triggers)->domain).x && playerX < ((*triggers)->domain).x + ((*triggers)->domain).w)
|
if (!((*triggers)->tombStone) &&
|
||||||
|
(playerX > ((*triggers)->domain).x && playerX < ((*triggers)->domain).x + ((*triggers)->domain).w)
|
||||||
&& (playerY > ((*triggers)->domain).y && playerY < ((*triggers)->domain).y + ((*triggers)->domain).h) )
|
&& (playerY > ((*triggers)->domain).y && playerY < ((*triggers)->domain).y + ((*triggers)->domain).h) )
|
||||||
{
|
{
|
||||||
if ((*triggers)->eventType == 0)
|
if ((*triggers)->eventType == 0)
|
||||||
|
@ -234,7 +306,7 @@ void addObstacle(Room* self, int x, int y, int w, int h)
|
||||||
if (self->numberOfObstacles+1 > self->maxNumberOfObstacles)
|
if (self->numberOfObstacles+1 > self->maxNumberOfObstacles)
|
||||||
{
|
{
|
||||||
self->maxNumberOfObstacles *= 2;
|
self->maxNumberOfObstacles *= 2;
|
||||||
SDL_Rect* temp = malloc(self->maxNumberOfObstacles*sizeof(SDL_Rect));
|
Obstruction** temp = malloc(self->maxNumberOfObstacles*sizeof(Obstruction*));
|
||||||
for (i = 0; i < self->numberOfObstacles; i++)
|
for (i = 0; i < self->numberOfObstacles; i++)
|
||||||
temp[i] = self->obstacle[i];
|
temp[i] = self->obstacle[i];
|
||||||
free(self->obstacle);
|
free(self->obstacle);
|
||||||
|
@ -242,26 +314,15 @@ void addObstacle(Room* self, int x, int y, int w, int h)
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->obstacle[self->numberOfObstacles].x = x;
|
|
||||||
self->obstacle[self->numberOfObstacles].y = y;
|
self->obstacle[self->numberOfObstacles] = newObstruction(x, y, w, h);
|
||||||
self->obstacle[self->numberOfObstacles].w = w;
|
|
||||||
self->obstacle[self->numberOfObstacles].h = h;
|
|
||||||
|
|
||||||
self->numberOfObstacles++;
|
self->numberOfObstacles++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteObstacle(Room* self, int i)
|
void deleteObstacle(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->obstacle[i]->tombStone = 1;
|
||||||
SDL_Rect* temp = malloc(self->maxNumberOfObstacles*sizeof(SDL_Rect));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->obstacle[j];
|
|
||||||
for (j = i + 1; j < self->numberOfObstacles; j++)
|
|
||||||
temp[j-1] = self->obstacle[j];
|
|
||||||
free(self->obstacle);
|
|
||||||
self->obstacle = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfObstacles--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -274,7 +335,7 @@ void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int
|
||||||
if (self->numberOfObj+1 > self->maxNumberOfObj)
|
if (self->numberOfObj+1 > self->maxNumberOfObj)
|
||||||
{
|
{
|
||||||
self->maxNumberOfObj *= 2;
|
self->maxNumberOfObj *= 2;
|
||||||
FGImage* temp = malloc(self->maxNumberOfObj*sizeof(FGImage));;
|
FGImage** temp = malloc(self->maxNumberOfObj*sizeof(FGImage*));;
|
||||||
for (i = 0; i < self->numberOfObj; i++)
|
for (i = 0; i < self->numberOfObj; i++)
|
||||||
temp[i] = self->fgObject[i];
|
temp[i] = self->fgObject[i];
|
||||||
free(self->fgObject);
|
free(self->fgObject);
|
||||||
|
@ -282,35 +343,15 @@ void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->fgObject[self->numberOfObj].location.x = x;
|
self->fgObject[self->numberOfObj] = newFGImage(x, y, w, h, f, dual, filename, alpha);
|
||||||
self->fgObject[self->numberOfObj].location.y = y;
|
|
||||||
self->fgObject[self->numberOfObj].location.w = w;
|
|
||||||
self->fgObject[self->numberOfObj].location.h = h;
|
|
||||||
|
|
||||||
self->fgObject[self->numberOfObj].frames = f;
|
|
||||||
self->fgObject[self->numberOfObj].frameNow = 0;
|
|
||||||
self->fgObject[self->numberOfObj].dualLayer = dual;
|
|
||||||
|
|
||||||
self->fgObject[self->numberOfObj].spriteSheet = loadImage(filename);
|
|
||||||
if (alpha != 255)
|
|
||||||
SDL_SetAlpha(self->fgObject[self->numberOfObj].spriteSheet, SDL_SRCALPHA|SDL_RLEACCEL, alpha);
|
|
||||||
self->numberOfObj++;
|
self->numberOfObj++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteFgObj(Room* self, int i)
|
void deleteFgObj(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->fgObject[i]->tombStone = 1;
|
||||||
FGImage* temp = malloc(self->maxNumberOfObj*sizeof(FGImage));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->fgObject[j];
|
|
||||||
for (j = i + 1; j < self->numberOfObj; j++)
|
|
||||||
temp[j-1] = self->fgObject[j];
|
|
||||||
SDL_FreeSurface(self->fgObject[i].spriteSheet);
|
|
||||||
free(self->fgObject);
|
|
||||||
self->fgObject = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfObj--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFgObjects1(Room* self)
|
void drawFgObjects1(Room* self)
|
||||||
|
@ -325,14 +366,17 @@ void drawFgObjects1(Room* self)
|
||||||
|
|
||||||
for (i = 0; i < self->numberOfObj; i++)
|
for (i = 0; i < self->numberOfObj; i++)
|
||||||
{
|
{
|
||||||
clip.w = self->fgObject[i].location.w;
|
if (!(self->fgObject[i]->tombStone))
|
||||||
clip.x = self->fgObject[i].frameNow*clip.w;
|
{
|
||||||
clip.h = self->fgObject[i].location.h;
|
clip.w = self->fgObject[i]->location.w;
|
||||||
applySurface(self->fgObject[i].location.x, self->fgObject[i].location.y, self->fgObject[i].spriteSheet, screen, &clip );
|
clip.x = self->fgObject[i]->frameNow*clip.w;
|
||||||
if (self->objIterator == self->objSpeed)
|
clip.h = self->fgObject[i]->location.h;
|
||||||
self->fgObject[i].frameNow++;
|
applySurface(self->fgObject[i]->location.x, self->fgObject[i]->location.y, self->fgObject[i]->spriteSheet, screen, &clip );
|
||||||
if (self->fgObject[i].frameNow == self->fgObject[i].frames)
|
if (self->objIterator == self->objSpeed)
|
||||||
self->fgObject[i].frameNow = 0;
|
self->fgObject[i]->frameNow++;
|
||||||
|
if (self->fgObject[i]->frameNow == self->fgObject[i]->frames)
|
||||||
|
self->fgObject[i]->frameNow = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (self->objIterator == self->objSpeed)
|
if (self->objIterator == self->objSpeed)
|
||||||
self->objIterator = 0;
|
self->objIterator = 0;
|
||||||
|
@ -351,17 +395,17 @@ void drawFgObjects2(Room* self)
|
||||||
|
|
||||||
for (i = 0; i < self->numberOfObj; i++)
|
for (i = 0; i < self->numberOfObj; i++)
|
||||||
{
|
{
|
||||||
if (self->fgObject[i].dualLayer)
|
if (!(self->fgObject[i]->tombStone) && self->fgObject[i]->dualLayer)
|
||||||
{
|
{
|
||||||
clip.w = self->fgObject[i].location.w;
|
clip.w = self->fgObject[i]->location.w;
|
||||||
clip.x = self->fgObject[i].frameNow*clip.w;
|
clip.x = self->fgObject[i]->frameNow*clip.w;
|
||||||
clip.h = self->fgObject[i].location.h;
|
clip.h = self->fgObject[i]->location.h;
|
||||||
clip.y = clip.h;
|
clip.y = clip.h;
|
||||||
applySurface(self->fgObject[i].location.x, self->fgObject[i].location.y, self->fgObject[i].spriteSheet, screen, &clip );
|
applySurface(self->fgObject[i]->location.x, self->fgObject[i]->location.y, self->fgObject[i]->spriteSheet, screen, &clip );
|
||||||
if (self->objIterator == self->objSpeed)
|
if (self->objIterator == self->objSpeed)
|
||||||
self->fgObject[i].frameNow++;
|
self->fgObject[i]->frameNow++;
|
||||||
if (self->fgObject[i].frameNow == self->fgObject[i].frames)
|
if (self->fgObject[i]->frameNow == self->fgObject[i]->frames)
|
||||||
self->fgObject[i].frameNow = 0;
|
self->fgObject[i]->frameNow = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (self->objIterator == self->objSpeed)
|
if (self->objIterator == self->objSpeed)
|
||||||
|
@ -379,7 +423,7 @@ void addWarp(Room* self, int x, int y, int w, int h, enum dataChunks toChunk, in
|
||||||
if (self->numberOfWarps+1 > self->maxNumberOfWarps)
|
if (self->numberOfWarps+1 > self->maxNumberOfWarps)
|
||||||
{
|
{
|
||||||
self->maxNumberOfWarps *= 2;
|
self->maxNumberOfWarps *= 2;
|
||||||
WarpZone* temp = malloc(self->maxNumberOfWarps*sizeof(WarpZone));
|
WarpZone** temp = malloc(self->maxNumberOfWarps*sizeof(WarpZone*));
|
||||||
for (i = 0; i < self->numberOfWarps; i++)
|
for (i = 0; i < self->numberOfWarps; i++)
|
||||||
temp[i] = self->warps[i];
|
temp[i] = self->warps[i];
|
||||||
free(self->warps);
|
free(self->warps);
|
||||||
|
@ -387,31 +431,13 @@ void addWarp(Room* self, int x, int y, int w, int h, enum dataChunks toChunk, in
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->warps[self->numberOfWarps].x = goesX;
|
self->warps[self->numberOfWarps] = newWarpZone(x, y, w, h, toChunk, goesTo, goesX, goesY);
|
||||||
self->warps[self->numberOfWarps].y = goesY;
|
self->numberOfWarps++;
|
||||||
|
|
||||||
self->warps[self->numberOfWarps].location.x = x;
|
|
||||||
self->warps[self->numberOfWarps].location.y = y;
|
|
||||||
self->warps[self->numberOfWarps].location.w = w;
|
|
||||||
self->warps[self->numberOfWarps].location.h = h;
|
|
||||||
|
|
||||||
self->warps[self->numberOfWarps].chunk = toChunk;
|
|
||||||
self->warps[self->numberOfWarps++].destination = goesTo;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteWarp(Room* self, int i)
|
void deleteWarp(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->warps[i]->tombStone = 1;
|
||||||
WarpZone* temp = malloc(self->maxNumberOfWarps*sizeof(WarpZone));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->warps[j];
|
|
||||||
for (j = i + 1; j < self->numberOfWarps; j++)
|
|
||||||
temp[j-1] = self->warps[j];
|
|
||||||
free(self->warps);
|
|
||||||
self->warps = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfWarps--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -437,17 +463,7 @@ void addTrigger(Room* self, HyperKaos* newTrigger)
|
||||||
|
|
||||||
void deleteTrigger(Room* self, int i)
|
void deleteTrigger(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->eventTriggers[i]->tombStone = 1;
|
||||||
HyperKaos** temp = malloc(self->maxNumberOfTriggers*sizeof(HyperKaos*));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->eventTriggers[j];
|
|
||||||
for (j = i + 1; j < self->numberOfTriggers; j++)
|
|
||||||
temp[j-1] = self->eventTriggers[j];
|
|
||||||
deleteHyperKaos(self->eventTriggers[i]);
|
|
||||||
free(self->eventTriggers);
|
|
||||||
self->eventTriggers = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfTriggers--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSigil(Room* self, Synergy* newSigil)
|
void addSigil(Room* self, Synergy* newSigil)
|
||||||
|
@ -469,17 +485,7 @@ void addSigil(Room* self, Synergy* newSigil)
|
||||||
|
|
||||||
void deleteSigil(Room* self, int i)
|
void deleteSigil(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->sigils[i]->tombStone = 1;
|
||||||
Synergy** temp = malloc(self->maxNumberOfSigils*sizeof(Synergy*));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->sigils[j];
|
|
||||||
for (j = i + 1; j < self->numberOfSigils; j++)
|
|
||||||
temp[j-1] = self->sigils[j];
|
|
||||||
deleteSynergy(self->sigils[i]);
|
|
||||||
free(self->sigils);
|
|
||||||
self->sigils = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfSigils--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPerson(Room* self, Player* newPlayer)
|
void addPerson(Room* self, Player* newPlayer)
|
||||||
|
@ -501,17 +507,7 @@ void addPerson(Room* self, Player* newPlayer)
|
||||||
|
|
||||||
void deletePerson(Room* self, int i)
|
void deletePerson(Room* self, int i)
|
||||||
{
|
{
|
||||||
int j;
|
self->people[i]->tombStone = 1;
|
||||||
Player** temp = malloc(self->maxNumberOfPeople*sizeof(Player*));
|
|
||||||
for (j = 0; j < i; j++)
|
|
||||||
temp[j] = self->people[j];
|
|
||||||
for (j = i + 1; j < self->numberOfPeople; j++)
|
|
||||||
temp[j-1] = self->people[j];
|
|
||||||
killPlayer(self->people[i]);
|
|
||||||
free(self->people);
|
|
||||||
self->people = temp;
|
|
||||||
temp = NULL;
|
|
||||||
self->numberOfPeople--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPeople(Room* self)
|
void drawPeople(Room* self)
|
||||||
|
@ -519,6 +515,7 @@ void drawPeople(Room* self)
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < self->numberOfPeople; i++)
|
for (i = 0; i < self->numberOfPeople; i++)
|
||||||
{
|
{
|
||||||
|
if(!(self->people[i]->tombStone))
|
||||||
drawPlayer(self->people[i]);
|
drawPlayer(self->people[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
Room.h
26
Room.h
|
@ -1,16 +1,28 @@
|
||||||
typedef struct hyperKaos HyperKaos;
|
typedef struct hyperKaos HyperKaos;
|
||||||
typedef struct synergy Synergy;
|
typedef struct synergy Synergy;
|
||||||
|
|
||||||
|
typedef struct obstruction
|
||||||
|
{
|
||||||
|
SDL_Rect domain;
|
||||||
|
int tombStone;
|
||||||
|
} Obstruction;
|
||||||
|
|
||||||
|
Obstruction* newObstruction(int x, int y, int w, int h);
|
||||||
|
void deleteObstruction(Obstruction* target);
|
||||||
|
|
||||||
typedef struct fgImage
|
typedef struct fgImage
|
||||||
{
|
{
|
||||||
int frames;
|
int frames;
|
||||||
int frameNow;
|
int frameNow;
|
||||||
int dualLayer;
|
int dualLayer;
|
||||||
|
int tombStone;
|
||||||
|
|
||||||
SDL_Rect location;
|
SDL_Rect location;
|
||||||
SDL_Surface* spriteSheet;
|
SDL_Surface* spriteSheet;
|
||||||
} FGImage;
|
} FGImage;
|
||||||
|
|
||||||
|
FGImage* newFGImage(int x, int y, int w, int h, int f, int dual, char* filename, int alpha);
|
||||||
|
void deleteFGImage(FGImage* target);
|
||||||
|
|
||||||
typedef struct warpZone
|
typedef struct warpZone
|
||||||
{
|
{
|
||||||
|
@ -18,25 +30,29 @@ typedef struct warpZone
|
||||||
enum dataChunks chunk;
|
enum dataChunks chunk;
|
||||||
int destination;
|
int destination;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
int tombStone;
|
||||||
} WarpZone;
|
} WarpZone;
|
||||||
|
|
||||||
|
WarpZone* newWarpZone(int x, int y, int w, int h, enum dataChunks chunk, int dest, int dX, int dY);
|
||||||
|
void deleteWarpZone(WarpZone* target);
|
||||||
|
|
||||||
typedef struct room
|
typedef struct room
|
||||||
{
|
{
|
||||||
SDL_Surface* spriteSheet;
|
SDL_Surface* spriteSheet;
|
||||||
SDL_Surface* bgImage;
|
SDL_Surface* bgImage;
|
||||||
int frameNo;
|
int frameNo;
|
||||||
|
|
||||||
SDL_Rect* obstacle;
|
Obstruction** obstacle;
|
||||||
int numberOfObstacles;
|
int numberOfObstacles;
|
||||||
int maxNumberOfObstacles;
|
int maxNumberOfObstacles;
|
||||||
|
|
||||||
struct fgImage* fgObject;
|
FGImage** fgObject;
|
||||||
int numberOfObj;
|
int numberOfObj;
|
||||||
int maxNumberOfObj;
|
int maxNumberOfObj;
|
||||||
int objSpeed;
|
int objSpeed;
|
||||||
int objIterator;
|
int objIterator;
|
||||||
|
|
||||||
WarpZone* warps;
|
WarpZone** warps;
|
||||||
int numberOfWarps;
|
int numberOfWarps;
|
||||||
int maxNumberOfWarps;
|
int maxNumberOfWarps;
|
||||||
|
|
||||||
|
@ -62,8 +78,8 @@ void deleteRoom(Room* target);
|
||||||
void changeRSprite(Room* self, SDL_Rect* clip);
|
void changeRSprite(Room* self, SDL_Rect* clip);
|
||||||
void animate(Room* self);
|
void animate(Room* self);
|
||||||
|
|
||||||
int checkCollision(Room* self, Player* player, SDL_Rect* box);
|
int checkCollision(Room* self, Player* player, Obstruction** box);
|
||||||
int checkWCollision(Room* self, SDL_Rect* player, WarpZone* warpBoxes, int* whichWarp);
|
int checkWCollision(Room* self, SDL_Rect* player, WarpZone** warpBoxes, int* whichWarp);
|
||||||
int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whichTrigger, int* triggerType);
|
int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whichTrigger, int* triggerType);
|
||||||
|
|
||||||
void addObstacle(Room* self, int x, int y, int w, int h);
|
void addObstacle(Room* self, int x, int y, int w, int h);
|
||||||
|
|
|
@ -4,6 +4,7 @@ typedef struct synergy
|
||||||
char dir;
|
char dir;
|
||||||
SDL_Rect zone;
|
SDL_Rect zone;
|
||||||
HyperKaos* trigger;
|
HyperKaos* trigger;
|
||||||
|
int tombStone;
|
||||||
} Synergy;
|
} Synergy;
|
||||||
|
|
||||||
Synergy* newSynergy(int s, char d, int x, int y, int w, int h, HyperKaos* t);
|
Synergy* newSynergy(int s, char d, int x, int y, int w, int h, HyperKaos* t);
|
||||||
|
|
10
TODO
10
TODO
|
@ -1,8 +1,8 @@
|
||||||
-add tombstones to everything
|
xadd tombstones to everything
|
||||||
-encase obstacles in their own struct
|
xencase obstacles in their own struct
|
||||||
-adjust collision detection
|
xadjust collision detection
|
||||||
-adjust kListen
|
xadjust kListen
|
||||||
-adjust deleteThing
|
xadjust deleteThing
|
||||||
-anything else that might be affected by tombstones
|
-anything else that might be affected by tombstones
|
||||||
-spell stuff
|
-spell stuff
|
||||||
-HUD
|
-HUD
|
||||||
|
|
Loading…
Reference in a new issue