added alpha blending for scene components, global pointer for scene data, include file for the intro scene, etc

This commit is contained in:
Iris Lightshard 2018-09-24 11:41:09 -07:00
parent eb1d90d5e0
commit 8b1e4cafdf
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
18 changed files with 70 additions and 41 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# ignore compiled objects
/*.o
# ignore the test executable
/game

View file

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

View file

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

1
Kaos.c
View file

@ -11,6 +11,7 @@
#include "Player.h"
#include "Room.h"
#include "HyperKaos.h"
#include "Scene.h"
#include "extern.h"

View file

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

View file

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

1
Room.c
View file

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

12
Scene.c
View file

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

View file

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

View file

@ -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()
{

View file

@ -11,6 +11,7 @@
#include "Kaos.h"
#include "HyperKaos.h"
#include "TextBox.h"
#include "Scene.h"
typedef struct timer Timer;
#include "extern.h"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

BIN
assets/img/fx/fog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
assets/img/fx/plasma.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

2
enum.h
View file

@ -1,5 +1,3 @@
#define CHUNKS_H
enum dataChunks
{
LEVEL1 = 1,

View file

@ -38,4 +38,4 @@ extern TextBox** dialogueData;
extern Mix_Music** bgmData;
extern Mix_Chunk** sfxData;
extern Kaos** kaosData;
extern Scene** theatre;

25
intro.c Normal file
View file

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

18
main.c
View file

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