diff --git a/HyperKaos.c b/HyperKaos.c index e887440..46b17e1 100644 --- a/HyperKaos.c +++ b/HyperKaos.c @@ -16,7 +16,7 @@ typedef struct textBox TextBox; HyperKaos* newHyperKaos(int id, int type, int x, int y, int w, int h) { - HyperKaos* self = (HyperKaos*)malloc(sizeof(HyperKaos)); + HyperKaos* self = malloc(sizeof(HyperKaos)); self->domain.x = x; self->domain.y = y; diff --git a/Kaos.c b/Kaos.c index ff1b0e7..8c641e2 100644 --- a/Kaos.c +++ b/Kaos.c @@ -16,7 +16,7 @@ Kaos* rawKaos() { - Kaos* self = (Kaos*)malloc(sizeof(Kaos)); + Kaos* self = malloc(sizeof(Kaos)); self->next = NULL; return self; } @@ -24,7 +24,7 @@ Kaos* rawKaos() Kaos* newConversation(int i) { Kaos* core = rawKaos(); - Conversation* self = (Conversation*)malloc(sizeof(Conversation)); + Conversation* self = malloc(sizeof(Conversation)); self->index = i; @@ -37,7 +37,7 @@ Kaos* newConversation(int i) void runConversation(Kaos* self) { - Conversation* kSelf = (Conversation*)self->kType; + Conversation* kSelf = self->kType; displayTextBox(dialogueData[kSelf->index]); } @@ -50,7 +50,7 @@ void deleteConversation(Kaos* target) Kaos* newChoice(char* q, char* a1, char* a2, HyperKaos* p1, HyperKaos* p2) { Kaos* core = rawKaos(); - Choice* self = (Choice*)malloc(sizeof(Choice)); + Choice* self = malloc(sizeof(Choice)); self->question = TTF_RenderText_Solid(font, q, textColor); self->answ1 = TTF_RenderText_Solid(font, a1, textColor); @@ -67,7 +67,7 @@ Kaos* newChoice(char* q, char* a1, char* a2, HyperKaos* p1, HyperKaos* p2) void runChoice(Kaos* self) { - Choice* kSelf = (Choice*)self->kType; + Choice* kSelf = self->kType; int choice = 0; int textIsRelevent = 1; actionbutton = 0; @@ -122,9 +122,10 @@ void runChoice(Kaos* self) void deleteChoice(Kaos* self) { - SDL_FreeSurface(((Choice*)(self->kType))->question); - SDL_FreeSurface(((Choice*)(self->kType))->answ1); - SDL_FreeSurface(((Choice*)(self->kType))->answ2); + Choice* kSelf = self->kType; + SDL_FreeSurface(kSelf->question); + SDL_FreeSurface(kSelf->answ1); + SDL_FreeSurface(kSelf->answ2); free(self->kType); free(self); } @@ -132,7 +133,7 @@ void deleteChoice(Kaos* self) Kaos* newManip(Player* t, int x, int y) { Kaos* core = rawKaos(); - Manip* self = (Manip*)malloc(sizeof(Manip)); + Manip* self = malloc(sizeof(Manip)); self->target= t; self->xSpd = x; @@ -147,7 +148,7 @@ Kaos* newManip(Player* t, int x, int y) void runManip(Kaos* self) { - Manip* kSelf = (Manip*)self->kType; + Manip* kSelf = self->kType; kSelf->target->bearing.x = kSelf->xSpd; kSelf->target->bearing.y = kSelf->ySpd; } @@ -161,7 +162,7 @@ void deleteManip(Kaos* target) Kaos* newLook(Player* t, char d) { Kaos* core = rawKaos(); - Look* self = (Look*)malloc(sizeof(Look)); + Look* self = malloc(sizeof(Look)); self->target = t; self->dir = d; @@ -175,7 +176,7 @@ Kaos* newLook(Player* t, char d) void runLook(Kaos* self) { - Look* kSelf = (Look*)self->kType; + Look* kSelf = self->kType; SDL_Rect playerClip = { 0,0,16,16}; switch(kSelf->dir) { @@ -204,7 +205,7 @@ void deleteLook(Kaos* target) Kaos* newTeleport(Player* p, int x, int y, int o) { Kaos* core = rawKaos(); - Teleport* self = (Teleport*)malloc(sizeof(Teleport)); + Teleport* self = malloc(sizeof(Teleport)); self->target = p; self->x = x; @@ -251,7 +252,7 @@ void runTeleport(Kaos* self) void deleteTeleport(Kaos* target) { - Teleport* kSelf = (Teleport*)target->kType; + Teleport* kSelf = target->kType; SDL_FreeSurface(kSelf->aura); free(target->kType); free(target); @@ -260,7 +261,7 @@ void deleteTeleport(Kaos* target) Kaos* newFaceEachother(Player* p1, Player* p2) { Kaos* core = rawKaos(); - FaceEachother* self = (FaceEachother*)malloc(sizeof(FaceEachother)); + FaceEachother* self = malloc(sizeof(FaceEachother)); self->p1 = p1; self->p2 = p2; @@ -274,7 +275,7 @@ Kaos* newFaceEachother(Player* p1, Player* p2) void runFaceEachother(Kaos* self) { - FaceEachother* kSelf = (FaceEachother*)self->kType; + 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) @@ -304,7 +305,7 @@ void deleteFaceEachother(Kaos* target) Kaos* newPlaySound(int i) { Kaos* core = rawKaos(); - PlaySound* self = (PlaySound*)malloc(sizeof(PlaySound)); + PlaySound* self = malloc(sizeof(PlaySound)); self->i = i; @@ -317,7 +318,7 @@ Kaos* newPlaySound(int i) void runPlaySound(Kaos* self) { - PlaySound* kSelf = (PlaySound*)self->kType; + PlaySound* kSelf = self->kType; Mix_PlayChannel(-1, sfxData[kSelf->i], 0); } @@ -330,7 +331,7 @@ void deletePlaySound(Kaos* target) Kaos* newErase(char t, int i) { Kaos* core = rawKaos(); - Erase* self = (Erase*)malloc(sizeof(Erase)); + Erase* self = malloc(sizeof(Erase)); self->type = t; self->index = i; @@ -344,7 +345,7 @@ Kaos* newErase(char t, int i) void runErase(Kaos* self) { - Erase* kSelf = (Erase*)self->kType; + Erase* kSelf = self->kType; switch (kSelf->type) { case 'w': @@ -372,7 +373,7 @@ void deleteErase(Kaos* target) Kaos* newWait(char t, int i) { Kaos* core = rawKaos(); - Wait* self = (Wait*)malloc(sizeof(Wait)); + Wait* self = malloc(sizeof(Wait)); self->type = t; self->frames = i; @@ -386,7 +387,7 @@ Kaos* newWait(char t, int i) void runWait(Kaos* self) { - Wait* kSelf = (Wait*)self->kType; + Wait* kSelf = self->kType; int i; if (kSelf->type == 'f') captive = 1; diff --git a/Player.c b/Player.c index 34385d4..6d776a2 100644 --- a/Player.c +++ b/Player.c @@ -37,7 +37,7 @@ Player* newPlayer(char* filename, int a, int b) amask = 0xff000000; #endif - Player* self = (Player*)malloc(sizeof(Player)); + Player* self = malloc(sizeof(Player)); self->counter = 0; self->spriteSheet = NULL; diff --git a/Room.c b/Room.c index 5618d52..a236682 100644 --- a/Room.c +++ b/Room.c @@ -19,30 +19,25 @@ Room* newRoom(char* filename, int a) { Room* self = (Room*)malloc(sizeof(Room)); - self->obstacle = NULL; - self->obstacle = (SDL_Rect*)malloc(4*sizeof(SDL_Rect)); + self->obstacle = malloc(4*sizeof(SDL_Rect)); self->numberOfObstacles = 0; self->maxNumberOfObstacles = 4; - self->fgObject = NULL; - self->fgObject = (FGImage*)malloc(4*sizeof(FGImage)); + self->fgObject = malloc(4*sizeof(FGImage)); self->numberOfObj = 0; self->maxNumberOfObj = 4; self->objSpeed = a; self->objIterator = 0; - self->warps = NULL; - self->warps = (WarpZone*)malloc(4*sizeof(WarpZone)); + self->warps = malloc(4*sizeof(WarpZone)); self->numberOfWarps = 0; self->maxNumberOfWarps = 4; - self->eventTriggers = NULL; - self->eventTriggers = (HyperKaos**)malloc(4*sizeof(HyperKaos*)); + self->eventTriggers = malloc(4*sizeof(HyperKaos*)); self->numberOfTriggers = 0; self->maxNumberOfTriggers =4; - self->people = NULL; - self->people = (Player**)malloc(4*sizeof(Player*)); + self->people = malloc(4*sizeof(Player*)); self->numberOfPeople = 0; self->maxNumberOfPeople = 4; @@ -232,7 +227,7 @@ void addObstacle(Room* self, int x, int y, int w, int h) if (self->numberOfObstacles+1 > self->maxNumberOfObstacles) { self->maxNumberOfObstacles *= 2; - SDL_Rect* temp = (SDL_Rect*)malloc(self->maxNumberOfObstacles*sizeof(SDL_Rect)); + SDL_Rect* temp = malloc(self->maxNumberOfObstacles*sizeof(SDL_Rect)); for (i = 0; i < self->numberOfObstacles; i++) temp[i] = self->obstacle[i]; free(self->obstacle); @@ -251,7 +246,7 @@ void addObstacle(Room* self, int x, int y, int w, int h) void deleteObstacle(Room* self, int i) { int j; - SDL_Rect* temp = (SDL_Rect*)malloc(self->maxNumberOfObstacles*sizeof(SDL_Rect)); + 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++) @@ -266,13 +261,13 @@ void deleteObstacle(Room* self, int i) // fg objects // -void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int dual) +void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int dual, int alpha) { int i; if (self->numberOfObj+1 > self->maxNumberOfObj) { self->maxNumberOfObj *= 2; - FGImage* temp = (FGImage*)malloc(self->maxNumberOfObj*sizeof(FGImage));; + FGImage* temp = malloc(self->maxNumberOfObj*sizeof(FGImage));; for (i = 0; i < self->numberOfObj; i++) temp[i] = self->fgObject[i]; free(self->fgObject); @@ -290,6 +285,8 @@ void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int 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++; } @@ -297,7 +294,7 @@ void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int void deleteFgObj(Room* self, int i) { int j; - FGImage* temp = (FGImage*)malloc(self->maxNumberOfObj*sizeof(FGImage)); + 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++) @@ -375,7 +372,7 @@ void addWarp(Room* self, int x, int y, int w, int h, enum dataChunks toChunk, in if (self->numberOfWarps+1 > self->maxNumberOfWarps) { self->maxNumberOfWarps *= 2; - WarpZone* temp = (WarpZone*)malloc(self->maxNumberOfWarps*sizeof(WarpZone)); + WarpZone* temp = malloc(self->maxNumberOfWarps*sizeof(WarpZone)); for (i = 0; i < self->numberOfWarps; i++) temp[i] = self->warps[i]; free(self->warps); @@ -399,7 +396,7 @@ void addWarp(Room* self, int x, int y, int w, int h, enum dataChunks toChunk, in void deleteWarp(Room* self, int i) { int j; - WarpZone* temp = (WarpZone*)malloc(self->maxNumberOfWarps*sizeof(WarpZone)); + 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++) @@ -420,7 +417,7 @@ void addTrigger(Room* self, HyperKaos* newTrigger) if (self->numberOfTriggers+1 > self->maxNumberOfTriggers) { self->maxNumberOfTriggers *= 2; - HyperKaos** temp = (HyperKaos**)malloc(self->maxNumberOfTriggers*sizeof(HyperKaos*)); + HyperKaos** temp = malloc(self->maxNumberOfTriggers*sizeof(HyperKaos*)); for (i = 0; i < self->numberOfTriggers; i++) temp[i] = self->eventTriggers[i]; free(self->eventTriggers); @@ -434,7 +431,7 @@ void addTrigger(Room* self, HyperKaos* newTrigger) void deleteTrigger(Room* self, int i) { int j; - HyperKaos** temp = (HyperKaos**)malloc(self->maxNumberOfTriggers*sizeof(HyperKaos*)); + 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++) @@ -452,7 +449,7 @@ void addPerson(Room* self, Player* newPlayer) if (self->numberOfPeople+1 > self->maxNumberOfPeople) { self->maxNumberOfPeople *= 2; - Player** temp = (Player**)malloc(self->maxNumberOfPeople*sizeof(Player*)); + Player** temp = malloc(self->maxNumberOfPeople*sizeof(Player*)); for (i = 0; i < self->numberOfPeople; i++) temp[i] = self->people[i]; free(self->people); @@ -466,11 +463,11 @@ void addPerson(Room* self, Player* newPlayer) void deletePerson(Room* self, int i) { int j; - Player** temp = (Player**)malloc(self->maxNumberOfPeople*sizeof(Player*)); + 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] = self->people[j]; + temp[j-1] = self->people[j]; killPlayer(self->people[i]); free(self->people); self->people = temp; diff --git a/Room.h b/Room.h index 806c3d2..da9eab8 100644 --- a/Room.h +++ b/Room.h @@ -64,7 +64,7 @@ int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whi void addObstacle(Room* self, int x, int y, int w, int h); void deleteObstacle(Room* self, int i); -void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int dual); +void addFgObj(Room* self, int x, int y, int w, int h, char* filename, int f, int dual, int alpha); void deleteFgObj(Room* self, int i); void drawFgObjects1(Room* self); void drawFgObjects2(Room* self); diff --git a/TextBox.c b/TextBox.c index 221d098..bce20bb 100644 --- a/TextBox.c +++ b/TextBox.c @@ -26,9 +26,9 @@ extern Player* hero; TextBox* newTextBox() { - TextBox* self = (TextBox*)malloc(sizeof(TextBox)); + TextBox* self = malloc(sizeof(TextBox)); self->portrait = NULL; - self->message = (SDL_Surface**)malloc(4*sizeof(SDL_Surface*)); + self->message = malloc(4*sizeof(SDL_Surface*)); self->lines = 0; self->cursor = 0; self->scroll = 0; @@ -38,9 +38,9 @@ TextBox* newTextBox() TextBox* newGTextBox(SDL_Surface* image) { - TextBox* self = (TextBox*)malloc(sizeof(TextBox)); + TextBox* self = malloc(sizeof(TextBox)); self->portrait = image; - self->message = (SDL_Surface**)malloc(4*sizeof(SDL_Surface*)); + self->message = malloc(4*sizeof(SDL_Surface*)); self->lines = 0; self->cursor = 0; self->scroll = 0; diff --git a/WorldData.c b/WorldData.c index 3f2e098..258b179 100644 --- a/WorldData.c +++ b/WorldData.c @@ -30,9 +30,9 @@ void bufferData(enum dataChunks chunk) mapBuffer[3] = newRoom("assets/img/backgrounds/darkroom.gif", 4); addObstacle(mapBuffer[0], 64,92,22,16); - addFgObj(mapBuffer[0], 64,64,22,55,"assets/img/objects/floatingChips.png", 4, 1); + addFgObj(mapBuffer[0], 64,64,22,55,"assets/img/objects/floatingChips.png", 4, 1, 255); addObstacle(mapBuffer[0], 320 - 64 - 22, 92,22,16); - addFgObj(mapBuffer[0], 320 - 64 - 22, 64, 22, 55, "assets/img/objects/floatingChips.png", 4, 1); + addFgObj(mapBuffer[0], 320 - 64 - 22, 64, 22, 55, "assets/img/objects/floatingChips.png", 4, 1, 255); addWarp(mapBuffer[0], 0,0,8,180, LEVEL1, 1, 304,90); addWarp(mapBuffer[0], 312,0,8,180, LEVEL1, 2, 16,90);