diff --git a/Engine.c b/Engine.c index b7bcbbb..90b6219 100644 --- a/Engine.c +++ b/Engine.c @@ -107,6 +107,8 @@ void interact() case A_BUTTON: actionbutton = 1; break; + case B_BUTTON: + spellbutton = 1; case PAUSE_BUTTON: pausemenu(); break; @@ -146,6 +148,8 @@ void interact() case A_BUTTON: actionbutton = 0; break; + case B_BUTTON: + spellbutton = 0; default: break; } break; diff --git a/Kaos.c b/Kaos.c index 63fca66..dfa6d87 100644 --- a/Kaos.c +++ b/Kaos.c @@ -281,20 +281,25 @@ void runFaceEachother(Kaos* self) FaceEachother* kSelf = self->kType; SDL_Rect p1Clip = {0,0,16,16}; SDL_Rect p2Clip = {0,0,16,16}; + if (kSelf->p1->point.x > kSelf->p2->point.x) p2Clip.x = 64; + if (kSelf->p1->point.x < kSelf->p2->point.x) p1Clip.x = 64; + if (kSelf->p1->point.y > kSelf->p2->point.y) { p1Clip.x = 96; p2Clip.x = 32; } + if (kSelf->p1->point.y < kSelf->p2->point.y) { p1Clip.x = 32; p2Clip.x = 96; } + changeSprite(kSelf->p1, &p1Clip); changeSprite(kSelf->p2, &p2Clip); } @@ -353,7 +358,7 @@ void runErase(Kaos* self) { case 'w': deleteWarp(rightHere, kSelf->index); - break; + break; case 't': deleteTrigger(rightHere, kSelf->index); break; diff --git a/Makefile b/Makefile index f521608..82e72ff 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: game scenetest: sceneTest.c Scene.o Engine.o Timer.o Player.o Room.o WorldData.o Kaos.o HyperKaos.o TextBox.o $(CC) -o $@ $^ $(CFLAGS) -game: main.c Player.o Engine.o Timer.o Room.o WorldData.o TextBox.o Kaos.o HyperKaos.o Scene.o +game: main.c Player.o Engine.o Timer.o Room.o WorldData.o TextBox.o Kaos.o HyperKaos.o Scene.o Synergy.o $(CC) -o $@ $^ $(CFLAGS) cleanobj: diff --git a/Player.c b/Player.c index d75906b..e97a2ff 100644 --- a/Player.c +++ b/Player.c @@ -15,6 +15,7 @@ typedef struct timer Timer; typedef struct textBox TextBox; typedef struct kaos Kaos; typedef struct scene Scene; +typedef struct hyperKaos HyperKaos; #include "extern.h" Player* newPlayer(char* filename, int a, int b) @@ -76,7 +77,7 @@ void movePlayer(Player* self, Room* hereNow) // obstacle collision - if (checkCollision(rightHere, &(self->boundBox), rightHere->obstacle)) + if (checkCollision(rightHere, self, rightHere->obstacle)) { self->point.x -= self->bearing.x; self->boundBox.x = self->point.x - 8; @@ -86,7 +87,7 @@ void movePlayer(Player* self, Room* hereNow) self->boundBox.y = self->point.y - 8; - if (checkCollision(rightHere, &(self->boundBox), rightHere->obstacle)) + if (checkCollision(rightHere, self, rightHere->obstacle)) { self->point.y -= self->bearing.y; self->boundBox.y = self->point.y - 8; @@ -246,3 +247,38 @@ void walkAnim(Player* self) self->counter++; if (self->counter == 8) self->counter = 0; } + +int playerFaces(Player* self, char dir) +{ + switch (dir) + { + case 'n': + if (self->frontFaceBox.y < self->boundBox.y) + return 1; + break; + case 's': + if (self->frontFaceBox.y > self->boundBox.y) + return 1; + break; + case 'e': + if (self->frontFaceBox.x > self->boundBox.x) + return 1; + break; + case 'w': + if (self->frontFaceBox.x < self->boundBox.x) + return 1; + break; + } + return 0; +} + +int playerIsInRect(Player* self, SDL_Rect* rect) +{ + SDL_Rect* pBox = &(self->boundBox); + int playerX = pBox->x + (pBox->w)/2; + int playerY = pBox->y + (pBox->h)/2; + if ((playerX >= rect->x && playerX <= rect->x + rect->w) + && (playerY >= rect->y && playerY <= rect->y + rect->h)) + return 1; + else return 0; +} \ No newline at end of file diff --git a/Player.h b/Player.h index b6ed129..93b2997 100644 --- a/Player.h +++ b/Player.h @@ -23,4 +23,7 @@ void killPlayer(Player* target); void movePlayer(Player* self, Room* rightHere); void changeSprite(Player* self, SDL_Rect* clip); void drawPlayer(Player* self); -void walkAnim(Player* self); \ No newline at end of file +void walkAnim(Player* self); + +int playerFaces(Player* self, char dir); +int playerIsInRect(Player* self, SDL_Rect* rect); \ No newline at end of file diff --git a/Room.c b/Room.c index 7c7c11e..f4df268 100644 --- a/Room.c +++ b/Room.c @@ -10,6 +10,7 @@ #include "Player.h" #include "Room.h" #include "HyperKaos.h" +#include "Synergy.h" typedef struct timer Timer; typedef struct textBox TextBox; @@ -42,6 +43,10 @@ Room* newRoom(char* filename, int a) self->numberOfPeople = 0; self->maxNumberOfPeople = 4; + self->sigils = malloc(4*sizeof(Synergy*)); + self->numberOfSigils = 0; + self->maxNumberOfSigils = 4; + SDL_Rect zeroRect; zeroRect.x=0; zeroRect.y=0; @@ -151,16 +156,15 @@ void animate(Room* self) // collision detection // -int checkCollision(Room* self, SDL_Rect* player, SDL_Rect* box) +int checkCollision(Room* self, Player* player, SDL_Rect* box) { int i; - int playerX = player->x + (player->w)/2; - int playerY = player->y + (player->h)/2; for (i = 1; i <= self->numberOfObstacles; i++) { - if ( (playerX >= box->x && playerX <= box->x + box->w) - && (playerY >= box->y && playerY <= box->y + box->h) ) + if (playerIsInRect(player, box)) +// if ( (playerX >= box->x && playerX <= box->x + box->w) +// && (playerY >= box->y && playerY <= box->y + box->h) ) { return 1; } @@ -444,6 +448,38 @@ void deleteTrigger(Room* self, int i) self->numberOfTriggers--; } +void addSigil(Room* self, Synergy* newSigil) +{ + int i; + if (self->numberOfSigils+1 > self->maxNumberOfSigils) + { + self->maxNumberOfSigils *= 2; + Synergy** temp = malloc(self->maxNumberOfSigils*sizeof(Synergy*)); + for (i = 0; i < self->numberOfSigils; i++) + temp[i] = self->sigils[i]; + free(self->sigils); + self->sigils = temp; + temp = NULL; + } + + self->sigils[self->numberOfSigils++] = newSigil; +} + +void deleteSigil(Room* self, int i) +{ + int j; + 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) { int i; diff --git a/Room.h b/Room.h index da9eab8..6c28944 100644 --- a/Room.h +++ b/Room.h @@ -1,4 +1,5 @@ typedef struct hyperKaos HyperKaos; +typedef struct synergy Synergy; typedef struct fgImage { @@ -43,6 +44,10 @@ typedef struct room int numberOfTriggers; int maxNumberOfTriggers; + Synergy** sigils; + int numberOfSigils; + int maxNumberOfSigils; + Player** people; int numberOfPeople; int maxNumberOfPeople; @@ -57,7 +62,7 @@ void deleteRoom(Room* target); void changeRSprite(Room* self, SDL_Rect* clip); void animate(Room* self); -int checkCollision(Room* self, SDL_Rect* player, SDL_Rect* box); +int checkCollision(Room* self, Player* player, SDL_Rect* box); int checkWCollision(Room* self, SDL_Rect* player, WarpZone* warpBoxes, int* whichWarp); int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whichTrigger, int* triggerType); @@ -75,6 +80,9 @@ void deleteWarp(Room* self, int i); void addTrigger(Room* self, HyperKaos* newTrigger); void deleteTrigger(Room* self, int i); +void addSigil(Room* self, Synergy* newSigil); +void deleteSigil(Room* self, int i); + void addPerson(Room* self, Player* newPlayer); void deletePerson(Room* self, int i); void drawPeople(Room* self); diff --git a/Scene.c b/Scene.c index 933f50b..f342f54 100644 --- a/Scene.c +++ b/Scene.c @@ -15,6 +15,7 @@ typedef struct kaos Kaos; typedef struct textBox TextBox; typedef struct room Room; typedef struct player Player; +typedef struct hyperKaos HyperKaos; #include "extern.h" SLayer* newSLayer(SDL_Surface* img, int x, int y, int h, int v, int alpha) diff --git a/Synergy.c b/Synergy.c new file mode 100644 index 0000000..1ae9729 --- /dev/null +++ b/Synergy.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include "enum.h" +#include "Player.h" +#include "Kaos.h" +#include "Room.h" +#include "HyperKaos.h" +#include "Synergy.h" + + +typedef struct player Player; +//typedef struct room Room; +//typedef struct kaos Kaos; +typedef struct scene Scene; +typedef struct timer Timer; +typedef struct textBox TextBox; +#include "extern.h" + +Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t) +{ + Synergy* self = malloc(sizeof(Synergy)); + + self->spell = s; + self->dir = d; + self->zone = z; + self->trigger = t; + + return self; +} + +void deleteSynergy(Synergy* target) +{ + free(target); +} + +void Synergize() +{ + int i; + Synergy* sigil = rightHere->sigils[0]; + for (i = 0; i < rightHere->numberOfSigils; i++) + { + if (sigil->spell == spellFlag + && playerFaces(hero, sigil->dir) + && playerIsInRect(hero, &(sigil->zone))) + run(sigil->trigger); + sigil++; + } +} \ No newline at end of file diff --git a/Synergy.h b/Synergy.h new file mode 100644 index 0000000..ee9d4c3 --- /dev/null +++ b/Synergy.h @@ -0,0 +1,12 @@ +typedef struct synergy +{ + int spell; + char dir; + SDL_Rect zone; + HyperKaos* trigger; +} Synergy; + +Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t); +void deleteSynergy(Synergy* target); + +void Synergize(); \ No newline at end of file diff --git a/TextBox.c b/TextBox.c index 3dc927c..a8c6555 100644 --- a/TextBox.c +++ b/TextBox.c @@ -13,6 +13,7 @@ typedef struct room Room; typedef struct kaos Kaos; typedef struct scene Scene; +typedef struct hyperKaos HyperKaos; #include "extern.h" diff --git a/WorldData.c b/WorldData.c index 2e4813e..a7f4711 100644 --- a/WorldData.c +++ b/WorldData.c @@ -21,6 +21,7 @@ void bufferData(enum dataChunks chunk) hasMusic = 0; applySurface(0,0, loadingTxt, screen, NULL); SDL_Flip(screen); + printf("Loading map chunk\n"); switch (chunk){ case LEVEL1: bgmData[0] = loadBGM("assets/snd/bgm/artificial sun stage (mamon machine mix).mp3"); @@ -160,7 +161,8 @@ void bufferData(enum dataChunks chunk) case LEVEL3: break; - } + } + printf("Loaded map chunk\n"); } void dataPurge(int a, int b, int c, int d, int e) @@ -180,6 +182,7 @@ void dataPurge(int a, int b, int c, int d, int e) void unloadData(enum dataChunks chunk) { + printf("Unloading old map chunk\n"); switch(chunk) { case LEVEL1: @@ -191,14 +194,17 @@ void unloadData(enum dataChunks chunk) case LEVEL3: break; } + printf("Unloaded old map chunk\n"); } void pushBufferData() { + printf("Pushing map buffer\n"); mapData = mapBuffer; mapBuffer = (Room**)malloc(64*sizeof(Room*)); if (hasMusic) Mix_PlayMusic(bgmData[0], -1); + printf("Mapbuffer clean\n"); } void pager() diff --git a/config.h b/config.h index e75ee24..9501030 100644 --- a/config.h +++ b/config.h @@ -5,5 +5,8 @@ #define DPAD_LEFT SDLK_a #define DPAD_RIGHT SDLK_d #define A_BUTTON SDLK_j +#define B_BUTTON SDLK_k +#define L_BUTTON SDLK_o +#define R_BUTTON SDLK_p #define FS_BUTTON SDLK_f #define PAUSE_BUTTON SDLK_q diff --git a/extern.h b/extern.h index 3c41c40..7f8b7ac 100644 --- a/extern.h +++ b/extern.h @@ -3,20 +3,24 @@ extern int fullscreen; extern int quit; extern int playing; extern int actionbutton; +extern int spellbutton; extern int captive; extern int hasMusic; - extern SDL_Event event; extern SDL_Surface* screen; extern Timer fps; - extern Room* rightHere; -extern Room* menuBG; -extern int kaosFlag; -extern long long int savestate; extern Player* hero; +extern HyperKaos** spellBook; +extern int kaosFlag; +extern int spellFlag; + +extern long long int savestate; +extern int spellKnowledge; + +extern Room* menuBG; extern SDL_Surface* saveMenu; extern SDL_Surface* textBoxBG; extern SDL_Surface* choiceBox; diff --git a/main.c b/main.c index 22bfad8..896f1a5 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,7 @@ int fullscreen = 0; int playing = 0; int quit = 0; int actionbutton = 0; +int spellbutton = 0; int captive = 0; int hasMusic = 0; @@ -32,6 +33,7 @@ SDL_Event event; SDL_Surface* screen = NULL; Room* rightHere = NULL; +HyperKaos** spellBook = NULL; SDL_Surface* saveMenu = NULL; SDL_Surface* textBoxBG = NULL; @@ -48,6 +50,7 @@ Room* menuBG = NULL; Mix_Music* menuBGM = NULL; long long int savestate = 2; +int spellKnowledge = 2; Room** mapData = NULL; Room** mapBuffer = NULL; @@ -58,6 +61,7 @@ Kaos** kaosData = NULL; Scene** theatre = NULL; int kaosFlag = -1; +int spellFlag = -1; enum dataChunks thisChunk; enum dataChunks nextChunk;