added alpha blending for scene components, global pointer for scene data, include file for the intro scene, etc
Derek Stevens nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlupL8UACgkQO3+8IhRO Y5hptBAAmRmBzoi4vZzH98S0y01rNufQSk8TTnLDRmpdQcf3FD+1XaU9aTwlA4oN NQhyr1Lcf932jG1RNqGZS/fncZUITdVj2SdZG9foMcvKJRKXQGZKnSgALpqRuUU0 872fXO2Wgd6SxSNxPNLUcFqD0nsu2Xj656jsohiNtMhkF4xkYF7iN8zCxTQlX01H jHs4fLQZlpBFhsnjQ68KV+5GAA+bvOTiCVz42mVtwtNAevMOiVRrC5VzeqZ4FpEp b1N9SmkdVTTQZMXt+CJccX6VHTsr35hdANoe6zpQFqtHdF0KieQgSdD9aVt1zLT0 hET2jP7bh709kIpBUjWbeH8QS+XtksfGYZxsh+CODHktULkAmsOnqEndhefRsgMr EFWgUtSBunwcRvbcs2KCS9OQEj6Fmk3stsxkxLvKx9KZhbfOnL056xNE5v7XIEUJ fcYmgu1XRTyn1n04HM+5qt9Nda8jGuN3xvMoGnxitgLAo3mkUPjQ1A/NX+dWPOaB yphrMEHxR2l5QjsiMvAtK8FQc0r1CcxLcOPM18CpEEhKqpXeJbJVnjYX2HdKbDzf y/38KrjhZeocUzzSHhYocGwaBpQqEjHSbQacjfyplDQQKqPA91np3Oy6xuKlfWiv oco9rWFhoMUayDZAT7uGfVolAXcKd/oLlxzCWhpuvMDKI61tLMM= =LuyQ -----END PGP SIGNATURE-----
18 files changed,
70 insertions(+),
41 deletions(-)
A
.gitignore
@@ -0,0 +1,5 @@
+# ignore compiled objects +/*.o + +# ignore the test executable +/game
M
Engine.c
→
Engine.c
@@ -15,6 +15,7 @@ #include "WorldData.h"
#include "TextBox.h" #include "Kaos.h" #include "HyperKaos.h" +#include "Scene.h" #include "extern.h" //@@ -207,12 +208,13 @@ loadingTxt = TTF_RenderText_Solid(font, "loading map data...", textColor);
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; }@@ -260,6 +262,8 @@ free(dialogueData);
free(bgmData); free(sfxData); + + free(theatre); SDL_FreeSurface(textBoxBG); SDL_FreeSurface(nextArrow);
M
HyperKaos.c
→
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"
M
Makefile
→
Makefile
@@ -4,7 +4,10 @@ .PHONY: all clean cleanobj
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:
M
Scene.c
→
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;@@ -27,6 +27,9 @@ self->v = 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 @@ int i;
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)
M
Scene.h
→
Scene.h
@@ -21,7 +21,7 @@ int time;
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);
M
TextBox.c
→
TextBox.c
@@ -7,22 +7,11 @@ #include "Timer.h"
#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() {
M
WorldData.c
→
WorldData.c
@@ -11,6 +11,7 @@ #include "Room.h"
#include "Kaos.h" #include "HyperKaos.h" #include "TextBox.h" +#include "Scene.h" typedef struct timer Timer; #include "extern.h"
A
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);
M
main.c
→
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 @@ printf("Init failed\n");
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)