all repos — hyperkaos @ ed6e55207cbb590f8e3cb231699f09089951fe17

lightweight modular puzzle/adventure game engine in C with SDL 1.2

remove unnecessary casts from void, fix removePlayer() in Room.c, add alpha setting for FgObjects
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlulTcwACgkQO3+8IhRO
Y5hE8w//eXjF43sG9GHBXuO5Fq+5251rFtdNRlkngxV2R6+lc5cH+dLS7IwYGFEy
9OX7DVniCyW6Vk8e5hnuBXGqYO/rhlwsXUv2Hpv9+mqiYKgzRinvuHY8uG2cz9Of
oy309aGVNd+0yh9hMAv6kLFQTO72fCekLvNwdZ4t9+sEc5od7Qe+AlFWL6uBhegA
2LcjLl2B2q1bFQR7JzdlddbYKRQaevgzzWiMy9uxhlUvcpWipVk1Ac2vsbBt4k+5
aNXcqOATUp6UrZmEUEcdkJwSq0Rm4TQWTc+tOSzeYujSMCVAGySsQz4yfFKwbAdu
wUIeP8C82eMLcE1MxHoWqLFSIXg3H3RazBHrKv83bLgyas37X3b5eEdWnEflfc27
Bc53s+6vE7xASYqgxPxFHw/eAsyHMDBE6aYk9TTmOug2jfxxZuDpuJf+c8loxOIZ
WWugEsU2X7eYgg1N8XjRuPWttZkSjPlpz+RY9LCWwu+BEMY54Drg/b7pgfoyQPW2
uK511igIE/bG0Jn3Nb/JAFBoW6Ma62hrMUoynr981EvlQDRsaz1Ou1QB9UClrjKs
VrGvVm3CB2XZcon/iyoNo4rmLb7lmVNJmWsWYuotYSd3N8L0ibhgU75+M/N/YFlM
ZvLaG0luhX4zMUpZPM9Br74K3sUX81PEK/NRd3OG0iDjajXnLUU=
=6z4y
-----END PGP SIGNATURE-----
commit

ed6e55207cbb590f8e3cb231699f09089951fe17

parent

21865a49b14bbaffaebdbc9fc43b6011ad9527e2

7 files changed, 51 insertions(+), 53 deletions(-)

jump to
M HyperKaos.cHyperKaos.c

@@ -16,7 +16,7 @@ #include "extern.h"

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;
M Kaos.cKaos.c

@@ -16,7 +16,7 @@ #include "extern.h"

Kaos* rawKaos() { - Kaos* self = (Kaos*)malloc(sizeof(Kaos)); + Kaos* self = malloc(sizeof(Kaos)); self->next = NULL; return self; }

@@ -24,7 +24,7 @@

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

void runConversation(Kaos* self) { - Conversation* kSelf = (Conversation*)self->kType; + Conversation* kSelf = self->kType; displayTextBox(dialogueData[kSelf->index]); }

@@ -50,7 +50,7 @@

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

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

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

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

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

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

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

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

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

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

void runPlaySound(Kaos* self) { - PlaySound* kSelf = (PlaySound*)self->kType; + PlaySound* kSelf = self->kType; Mix_PlayChannel(-1, sfxData[kSelf->i], 0); }

@@ -330,7 +331,7 @@

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

void runErase(Kaos* self) { - Erase* kSelf = (Erase*)self->kType; + Erase* kSelf = self->kType; switch (kSelf->type) { case 'w':

@@ -372,7 +373,7 @@

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

void runWait(Kaos* self) { - Wait* kSelf = (Wait*)self->kType; + Wait* kSelf = self->kType; int i; if (kSelf->type == 'f') captive = 1;
M Player.cPlayer.c

@@ -37,7 +37,7 @@ bmask = 0x00ff0000;

amask = 0xff000000; #endif - Player* self = (Player*)malloc(sizeof(Player)); + Player* self = malloc(sizeof(Player)); self->counter = 0; self->spriteSheet = NULL;
M Room.cRoom.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 @@ int i;

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

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

@@ -297,7 +294,7 @@

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

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

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

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 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;
M Room.hRoom.h

@@ -64,7 +64,7 @@

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);
M TextBox.cTextBox.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* 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;
M WorldData.cWorldData.c

@@ -30,9 +30,9 @@ mapBuffer[2] = newRoom("assets/img/backgrounds/greenroom.gif", 4);

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