added alpha blending for scene components, global pointer for scene data, include file for the intro scene, etc
This commit is contained in:
parent
eb1d90d5e0
commit
8b1e4cafdf
18 changed files with 70 additions and 41 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# ignore compiled objects
|
||||||
|
/*.o
|
||||||
|
|
||||||
|
# ignore the test executable
|
||||||
|
/game
|
16
Engine.c
16
Engine.c
|
@ -15,6 +15,7 @@
|
||||||
#include "TextBox.h"
|
#include "TextBox.h"
|
||||||
#include "Kaos.h"
|
#include "Kaos.h"
|
||||||
#include "HyperKaos.h"
|
#include "HyperKaos.h"
|
||||||
|
#include "Scene.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -207,12 +208,13 @@ int init(int argc, char* args[])
|
||||||
hero = newPlayer("assets/img/characters/kmage.png", 160, 90);
|
hero = newPlayer("assets/img/characters/kmage.png", 160, 90);
|
||||||
|
|
||||||
|
|
||||||
mapData = (Room**)malloc(64*sizeof(Room*));
|
mapData = malloc(64*sizeof(Room*));
|
||||||
mapBuffer= (Room**)malloc(64*sizeof(Room*));
|
mapBuffer= malloc(64*sizeof(Room*));
|
||||||
dialogueData = (TextBox**)malloc(124*sizeof(Room*));
|
dialogueData = malloc(124*sizeof(Room*));
|
||||||
bgmData = (Mix_Music**)malloc(4*sizeof(Mix_Music*));
|
bgmData = malloc(8*sizeof(Mix_Music*));
|
||||||
sfxData = (Mix_Chunk**)malloc(24*sizeof(Mix_Chunk*));
|
sfxData = malloc(24*sizeof(Mix_Chunk*));
|
||||||
kaosData = (Kaos**)malloc(124*sizeof(Kaos*));
|
kaosData = malloc(124*sizeof(Kaos*));
|
||||||
|
theatre = malloc(8*sizeof(Scene*));
|
||||||
printf("Init complete\n");
|
printf("Init complete\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -261,6 +263,8 @@ void cleanup()
|
||||||
free(bgmData);
|
free(bgmData);
|
||||||
free(sfxData);
|
free(sfxData);
|
||||||
|
|
||||||
|
free(theatre);
|
||||||
|
|
||||||
SDL_FreeSurface(textBoxBG);
|
SDL_FreeSurface(textBoxBG);
|
||||||
SDL_FreeSurface(nextArrow);
|
SDL_FreeSurface(nextArrow);
|
||||||
SDL_FreeSurface(saveMenu);
|
SDL_FreeSurface(saveMenu);
|
||||||
|
|
|
@ -11,6 +11,7 @@ typedef struct room Room;
|
||||||
typedef struct player Player;
|
typedef struct player Player;
|
||||||
typedef struct timer Timer;
|
typedef struct timer Timer;
|
||||||
typedef struct textBox TextBox;
|
typedef struct textBox TextBox;
|
||||||
|
typedef struct scene Scene;
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
|
|
1
Kaos.c
1
Kaos.c
|
@ -11,6 +11,7 @@
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Room.h"
|
#include "Room.h"
|
||||||
#include "HyperKaos.h"
|
#include "HyperKaos.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -4,7 +4,10 @@ CFLAGS= -Wall -I/usr/include/SDL -L/usr/lib/ -lSDL -lSDL_image -lSDL_ttf -lSDL_m
|
||||||
|
|
||||||
all: game
|
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)
|
$(CC) -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
cleanobj:
|
cleanobj:
|
||||||
|
|
1
Player.c
1
Player.c
|
@ -14,6 +14,7 @@ typedef struct TTF_Font TTF_Font;
|
||||||
typedef struct timer Timer;
|
typedef struct timer Timer;
|
||||||
typedef struct textBox TextBox;
|
typedef struct textBox TextBox;
|
||||||
typedef struct kaos Kaos;
|
typedef struct kaos Kaos;
|
||||||
|
typedef struct scene Scene;
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
Player* newPlayer(char* filename, int a, int b)
|
Player* newPlayer(char* filename, int a, int b)
|
||||||
|
|
1
Room.c
1
Room.c
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
typedef struct timer Timer;
|
typedef struct timer Timer;
|
||||||
typedef struct textBox TextBox;
|
typedef struct textBox TextBox;
|
||||||
|
typedef struct scene Scene;
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
Room* newRoom(char* filename, int a)
|
Room* newRoom(char* filename, int a)
|
||||||
|
|
12
Scene.c
12
Scene.c
|
@ -15,11 +15,11 @@ typedef struct room Room;
|
||||||
typedef struct player Player;
|
typedef struct player Player;
|
||||||
#include "extern.h"
|
#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));
|
SLayer* self = malloc(sizeof(SLayer));
|
||||||
|
|
||||||
self->sprite = loadImage(filename);
|
self->sprite = img;
|
||||||
self->x = x;
|
self->x = x;
|
||||||
self->y = y;
|
self->y = y;
|
||||||
self->h = h;
|
self->h = h;
|
||||||
|
@ -28,6 +28,9 @@ SLayer* newSLayer(char* filename, int x, int y, int h, int v)
|
||||||
self->oX = x;
|
self->oX = x;
|
||||||
self->oY = y;
|
self->oY = y;
|
||||||
|
|
||||||
|
if (alpha != 255)
|
||||||
|
SDL_SetAlpha(self->sprite, SDL_SRCALPHA|SDL_RLEACCEL, alpha);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,13 +58,14 @@ void buildScene(Scene* self, SLayer* sprite)
|
||||||
SLayer** temp;
|
SLayer** temp;
|
||||||
if (self->nSprites)
|
if (self->nSprites)
|
||||||
temp = self->sprites;
|
temp = self->sprites;
|
||||||
self->sprites = malloc((self->nSprites+1)*sizeof(SLayer));
|
self->sprites = malloc((self->nSprites+1)*sizeof(SLayer*));
|
||||||
if (self->nSprites)
|
if (self->nSprites)
|
||||||
{
|
{
|
||||||
for (i = 0; i < self->nSprites; i++)
|
for (i = 0; i < self->nSprites; i++)
|
||||||
self->sprites[i] = temp[i];
|
self->sprites[i] = temp[i];
|
||||||
}
|
}
|
||||||
self->sprites[self->nSprites++] = sprite;
|
self->sprites[self->nSprites] = sprite;
|
||||||
|
self->nSprites++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playScene(Scene* self)
|
void playScene(Scene* self)
|
||||||
|
|
2
Scene.h
2
Scene.h
|
@ -21,7 +21,7 @@ typedef struct scene
|
||||||
Transition fade;
|
Transition fade;
|
||||||
} Scene;
|
} 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);
|
void deleteSLayer(SLayer* target);
|
||||||
|
|
||||||
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor);
|
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor);
|
||||||
|
|
19
TextBox.c
19
TextBox.c
|
@ -7,22 +7,11 @@
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "TextBox.h"
|
#include "TextBox.h"
|
||||||
|
|
||||||
extern int quit;
|
typedef struct room Room;
|
||||||
extern int playing;
|
typedef struct kaos Kaos;
|
||||||
extern int actionbutton;
|
typedef struct scene Scene;
|
||||||
|
|
||||||
extern SDL_Event event;
|
#include "extern.h"
|
||||||
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;
|
|
||||||
|
|
||||||
TextBox* newTextBox()
|
TextBox* newTextBox()
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "Kaos.h"
|
#include "Kaos.h"
|
||||||
#include "HyperKaos.h"
|
#include "HyperKaos.h"
|
||||||
#include "TextBox.h"
|
#include "TextBox.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
|
||||||
typedef struct timer Timer;
|
typedef struct timer Timer;
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 81 KiB |
BIN
assets/img/fx/fog.png
Normal file
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
BIN
assets/img/fx/plasma.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 151 KiB |
2
enum.h
2
enum.h
|
@ -1,5 +1,3 @@
|
||||||
#define CHUNKS_H
|
|
||||||
|
|
||||||
enum dataChunks
|
enum dataChunks
|
||||||
{
|
{
|
||||||
LEVEL1 = 1,
|
LEVEL1 = 1,
|
||||||
|
|
2
extern.h
2
extern.h
|
@ -38,4 +38,4 @@ extern TextBox** dialogueData;
|
||||||
extern Mix_Music** bgmData;
|
extern Mix_Music** bgmData;
|
||||||
extern Mix_Chunk** sfxData;
|
extern Mix_Chunk** sfxData;
|
||||||
extern Kaos** kaosData;
|
extern Kaos** kaosData;
|
||||||
|
extern Scene** theatre;
|
||||||
|
|
25
intro.c
Normal file
25
intro.c
Normal 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
18
main.c
|
@ -55,6 +55,7 @@ TextBox** dialogueData = NULL;
|
||||||
Mix_Music** bgmData = NULL;
|
Mix_Music** bgmData = NULL;
|
||||||
Mix_Chunk** sfxData = NULL;
|
Mix_Chunk** sfxData = NULL;
|
||||||
Kaos** kaosData = NULL;
|
Kaos** kaosData = NULL;
|
||||||
|
Scene** theatre = NULL;
|
||||||
|
|
||||||
int kaosFlag = -1;
|
int kaosFlag = -1;
|
||||||
|
|
||||||
|
@ -69,17 +70,12 @@ int main (int argc, char* args[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Color black = {0,0,0};
|
/*
|
||||||
SLayer* presents = newSLayer("assets/img/backgrounds/presents.png", 0,0,0,0);
|
* intro discarded immediately after playing, so instead of increasing the
|
||||||
SLayer* menuTransition = newSLayer("assets/img/backgrounds/mainmenu.png",0,0,0,0);
|
* complexity and offloading it somewhere, we just keep it in this include
|
||||||
Scene* intro = newScene(30,30, 90, black, black);
|
* file for cleanliness and modularity
|
||||||
Scene* transition = newScene(30,0,30, black, black);
|
*/
|
||||||
buildScene(intro, presents);
|
#include "intro.c"
|
||||||
buildScene(transition, menuTransition);
|
|
||||||
playScene(intro);
|
|
||||||
playScene(transition);
|
|
||||||
deleteScene(intro);
|
|
||||||
deleteScene(transition);
|
|
||||||
|
|
||||||
// main game loop
|
// main game loop
|
||||||
while (!quit)
|
while (!quit)
|
||||||
|
|
Loading…
Reference in a new issue