diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..decbe3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# ignore compiled objects +/*.o + +# ignore the test executable +/game \ No newline at end of file diff --git a/Engine.c b/Engine.c index 2bc7686..00dab7c 100644 --- a/Engine.c +++ b/Engine.c @@ -15,6 +15,7 @@ #include "TextBox.h" #include "Kaos.h" #include "HyperKaos.h" +#include "Scene.h" #include "extern.h" // @@ -207,12 +208,13 @@ int init(int argc, char* args[]) hero = newPlayer("assets/img/characters/kmage.png", 160, 90); - mapData = (Room**)malloc(64*sizeof(Room*)); - mapBuffer= (Room**)malloc(64*sizeof(Room*)); - dialogueData = (TextBox**)malloc(124*sizeof(Room*)); - bgmData = (Mix_Music**)malloc(4*sizeof(Mix_Music*)); - sfxData = (Mix_Chunk**)malloc(24*sizeof(Mix_Chunk*)); - kaosData = (Kaos**)malloc(124*sizeof(Kaos*)); + mapData = malloc(64*sizeof(Room*)); + mapBuffer= malloc(64*sizeof(Room*)); + dialogueData = malloc(124*sizeof(Room*)); + bgmData = malloc(8*sizeof(Mix_Music*)); + sfxData = malloc(24*sizeof(Mix_Chunk*)); + kaosData = malloc(124*sizeof(Kaos*)); + theatre = malloc(8*sizeof(Scene*)); printf("Init complete\n"); return 1; } @@ -261,6 +263,8 @@ void cleanup() free(bgmData); free(sfxData); + free(theatre); + SDL_FreeSurface(textBoxBG); SDL_FreeSurface(nextArrow); SDL_FreeSurface(saveMenu); diff --git a/HyperKaos.c b/HyperKaos.c index 46b17e1..4312e4e 100644 --- a/HyperKaos.c +++ b/HyperKaos.c @@ -11,6 +11,7 @@ typedef struct room Room; typedef struct player Player; typedef struct timer Timer; typedef struct textBox TextBox; +typedef struct scene Scene; #include "extern.h" diff --git a/Kaos.c b/Kaos.c index 8c641e2..8e091da 100644 --- a/Kaos.c +++ b/Kaos.c @@ -11,6 +11,7 @@ #include "Player.h" #include "Room.h" #include "HyperKaos.h" +#include "Scene.h" #include "extern.h" diff --git a/Makefile b/Makefile index 49c1e12..f521608 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,10 @@ CFLAGS= -Wall -I/usr/include/SDL -L/usr/lib/ -lSDL -lSDL_image -lSDL_ttf -lSDL_m all: game -game: main.c Player.o Engine.o Timer.o Room.o WorldData.o TextBox.o Kaos.o HyperKaos.o +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 $(CC) -o $@ $^ $(CFLAGS) cleanobj: diff --git a/Player.c b/Player.c index 6d776a2..d75906b 100644 --- a/Player.c +++ b/Player.c @@ -14,6 +14,7 @@ typedef struct TTF_Font TTF_Font; typedef struct timer Timer; typedef struct textBox TextBox; typedef struct kaos Kaos; +typedef struct scene Scene; #include "extern.h" Player* newPlayer(char* filename, int a, int b) diff --git a/Room.c b/Room.c index a236682..7c7c11e 100644 --- a/Room.c +++ b/Room.c @@ -13,6 +13,7 @@ typedef struct timer Timer; typedef struct textBox TextBox; +typedef struct scene Scene; #include "extern.h" Room* newRoom(char* filename, int a) diff --git a/Scene.c b/Scene.c index 0265521..95ed5ed 100644 --- a/Scene.c +++ b/Scene.c @@ -15,11 +15,11 @@ typedef struct room Room; typedef struct player Player; #include "extern.h" -SLayer* newSLayer(char* filename, int x, int y, int h, int v) +SLayer* newSLayer(SDL_Surface* img, int x, int y, int h, int v, int alpha) { SLayer* self = malloc(sizeof(SLayer)); - self->sprite = loadImage(filename); + self->sprite = img; self->x = x; self->y = y; self->h = h; @@ -28,6 +28,9 @@ SLayer* newSLayer(char* filename, int x, int y, int h, int v) self->oX = x; self->oY = y; + if (alpha != 255) + SDL_SetAlpha(self->sprite, SDL_SRCALPHA|SDL_RLEACCEL, alpha); + return self; } @@ -55,13 +58,14 @@ void buildScene(Scene* self, SLayer* sprite) SLayer** temp; if (self->nSprites) temp = self->sprites; - self->sprites = malloc((self->nSprites+1)*sizeof(SLayer)); + self->sprites = malloc((self->nSprites+1)*sizeof(SLayer*)); if (self->nSprites) { for (i = 0; i < self->nSprites; i++) self->sprites[i] = temp[i]; } - self->sprites[self->nSprites++] = sprite; + self->sprites[self->nSprites] = sprite; + self->nSprites++; } void playScene(Scene* self) diff --git a/Scene.h b/Scene.h index d1ce9a9..865ce4b 100644 --- a/Scene.h +++ b/Scene.h @@ -21,7 +21,7 @@ typedef struct scene Transition fade; } Scene; -SLayer* newSLayer(char* filename, int x, int y, int h, int v); +SLayer* newSLayer(SDL_Surface* img, int x, int y, int h, int v, int alpha); void deleteSLayer(SLayer* target); Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor); diff --git a/TextBox.c b/TextBox.c index bce20bb..284cfef 100644 --- a/TextBox.c +++ b/TextBox.c @@ -7,22 +7,11 @@ #include "Player.h" #include "TextBox.h" -extern int quit; -extern int playing; -extern int actionbutton; +typedef struct room Room; +typedef struct kaos Kaos; +typedef struct scene Scene; -extern SDL_Event event; -extern SDL_Surface* screen; -extern Timer fps; - -extern SDL_Rect* textScroller; -extern SDL_Surface* textBoxBG; -extern SDL_Surface* nextArrow; - -extern TTF_Font* font; -extern SDL_Color textColor; - -extern Player* hero; +#include "extern.h" TextBox* newTextBox() { diff --git a/WorldData.c b/WorldData.c index 258b179..2e4813e 100644 --- a/WorldData.c +++ b/WorldData.c @@ -11,6 +11,7 @@ #include "Kaos.h" #include "HyperKaos.h" #include "TextBox.h" +#include "Scene.h" typedef struct timer Timer; #include "extern.h" diff --git a/assets/img/backgrounds/presents.png b/assets/img/backgrounds/presents.png deleted file mode 100644 index 390763c..0000000 Binary files a/assets/img/backgrounds/presents.png and /dev/null differ diff --git a/assets/img/fx/fog.png b/assets/img/fx/fog.png new file mode 100644 index 0000000..e0524df Binary files /dev/null and b/assets/img/fx/fog.png differ diff --git a/assets/img/fx/plasma.png b/assets/img/fx/plasma.png new file mode 100644 index 0000000..3e9543c Binary files /dev/null and b/assets/img/fx/plasma.png differ diff --git a/enum.h b/enum.h index 2eaf471..d6927d2 100644 --- a/enum.h +++ b/enum.h @@ -1,5 +1,3 @@ -#define CHUNKS_H - enum dataChunks { LEVEL1 = 1, diff --git a/extern.h b/extern.h index aeb71a5..3c41c40 100644 --- a/extern.h +++ b/extern.h @@ -38,4 +38,4 @@ extern TextBox** dialogueData; extern Mix_Music** bgmData; extern Mix_Chunk** sfxData; extern Kaos** kaosData; - +extern Scene** theatre; diff --git a/intro.c b/intro.c new file mode 100644 index 0000000..db82623 --- /dev/null +++ b/intro.c @@ -0,0 +1,25 @@ + + SDL_Color black = {0,0,0}; + + SLayer* nebula = newSLayer(loadImage("assets/img/backgrounds/presents.png"), 0,0,0,0,255); + SLayer* fogF = newSLayer(loadImage("assets/img/fx/fog.png"), 0,0,-1,0,128); + SLayer* fogB = newSLayer(loadImage("assets/img/fx/plasma.png"), -320,0,1,0,56); + SLayer* presents = newSLayer(TTF_RenderText_Solid(font, "nilFM presents", textColor), 120,84,0,0,128); + + SLayer* menuTransition = newSLayer(loadImage("assets/img/backgrounds/mainmenu.png"),0,0,0,0,255); + + Scene* intro = newScene(30,30, 200, black, black); + Scene* transition = newScene(30,0,30, black, black); + + buildScene(intro, nebula); + buildScene(intro, fogB); + buildScene(intro, fogF); + buildScene(intro, presents); + + buildScene(transition, menuTransition); + + playScene(intro); + playScene(transition); + + deleteScene(intro); + deleteScene(transition); \ No newline at end of file diff --git a/main.c b/main.c index 593bf86..7aafe26 100644 --- a/main.c +++ b/main.c @@ -55,6 +55,7 @@ TextBox** dialogueData = NULL; Mix_Music** bgmData = NULL; Mix_Chunk** sfxData = NULL; Kaos** kaosData = NULL; +Scene** theatre = NULL; int kaosFlag = -1; @@ -69,17 +70,12 @@ int main (int argc, char* args[]) return 1; } - SDL_Color black = {0,0,0}; - SLayer* presents = newSLayer("assets/img/backgrounds/presents.png", 0,0,0,0); - SLayer* menuTransition = newSLayer("assets/img/backgrounds/mainmenu.png",0,0,0,0); - Scene* intro = newScene(30,30, 90, black, black); - Scene* transition = newScene(30,0,30, black, black); - buildScene(intro, presents); - buildScene(transition, menuTransition); - playScene(intro); - playScene(transition); - deleteScene(intro); - deleteScene(transition); + /* + * intro discarded immediately after playing, so instead of increasing the + * complexity and offloading it somewhere, we just keep it in this include + * file for cleanliness and modularity + */ + #include "intro.c" // main game loop while (!quit)