basics of the cutscene engine are fleshed out, working intro sequence
This commit is contained in:
parent
ed6e55207c
commit
eb1d90d5e0
4 changed files with 167 additions and 0 deletions
125
Scene.c
Normal file
125
Scene.c
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <SDL/SDL_image.h>
|
||||||
|
#include <SDL/SDL_ttf.h>
|
||||||
|
#include <SDL/SDL_mixer.h>
|
||||||
|
|
||||||
|
#include "Scene.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
#include "Engine.h"
|
||||||
|
|
||||||
|
typedef struct kaos Kaos;
|
||||||
|
typedef struct textBox TextBox;
|
||||||
|
typedef struct room Room;
|
||||||
|
typedef struct player Player;
|
||||||
|
#include "extern.h"
|
||||||
|
|
||||||
|
SLayer* newSLayer(char* filename, int x, int y, int h, int v)
|
||||||
|
{
|
||||||
|
SLayer* self = malloc(sizeof(SLayer));
|
||||||
|
|
||||||
|
self->sprite = loadImage(filename);
|
||||||
|
self->x = x;
|
||||||
|
self->y = y;
|
||||||
|
self->h = h;
|
||||||
|
self->v = v;
|
||||||
|
|
||||||
|
self->oX = x;
|
||||||
|
self->oY = y;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteSLayer(SLayer* target)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(target->sprite);
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor)
|
||||||
|
{
|
||||||
|
Scene* self = malloc(sizeof(Scene));
|
||||||
|
|
||||||
|
self->sprites = NULL;
|
||||||
|
self->time = time;
|
||||||
|
self->nSprites = 0;
|
||||||
|
self->fade = (Transition){in, incolor, out, outcolor};
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildScene(Scene* self, SLayer* sprite)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
SLayer** temp;
|
||||||
|
if (self->nSprites)
|
||||||
|
temp = self->sprites;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void playScene(Scene* self)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
int alphamod;
|
||||||
|
Uint32 icolor, ocolor;
|
||||||
|
SDL_Surface* fadeIn, *fadeOut;
|
||||||
|
|
||||||
|
fadeIn = loadImage("assets/img/backgrounds/blueroom.png");
|
||||||
|
fadeOut = fadeIn;
|
||||||
|
|
||||||
|
icolor = SDL_MapRGB(fadeIn->format, self->fade.incolor.r, self->fade.incolor.g, self->fade.incolor.b);
|
||||||
|
ocolor = SDL_MapRGB(fadeIn->format, self->fade.outcolor.r, self->fade.outcolor.g, self->fade.outcolor.b);
|
||||||
|
|
||||||
|
SDL_FillRect(fadeIn, NULL, icolor);
|
||||||
|
SDL_FillRect(fadeOut, NULL, ocolor);
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < self->time; i++)
|
||||||
|
{
|
||||||
|
timeStart(fps);
|
||||||
|
for (j = 0; j < self->nSprites; j++)
|
||||||
|
{
|
||||||
|
applySurface(self->sprites[j]->x, self->sprites[j]->y, self->sprites[j]->sprite, screen, NULL);
|
||||||
|
self->sprites[j]->x += self->sprites[j]->h;
|
||||||
|
self->sprites[j]->y += self->sprites[j]->v;
|
||||||
|
}
|
||||||
|
if (i < self->fade.in)
|
||||||
|
{
|
||||||
|
alphamod = 255 - (int)(255*((float)i/self->fade.in));
|
||||||
|
SDL_SetAlpha(fadeIn, SDL_SRCALPHA|SDL_RLEACCEL, alphamod);
|
||||||
|
applySurface(0,0, fadeIn, screen, NULL);
|
||||||
|
}
|
||||||
|
if (self->time - i < self->fade.out)
|
||||||
|
{
|
||||||
|
alphamod = 255 - (int)(255*((float)(self->time - i)/self->fade.out));
|
||||||
|
SDL_SetAlpha(fadeOut, SDL_SRCALPHA|SDL_RLEACCEL, alphamod);
|
||||||
|
applySurface(0,0, fadeOut, screen, NULL);
|
||||||
|
}
|
||||||
|
SDL_Flip(screen);
|
||||||
|
timeDilation();
|
||||||
|
}
|
||||||
|
for (j = 0; j < self->nSprites; j++)
|
||||||
|
{
|
||||||
|
self->sprites[j]->x = self->sprites[j]->oX;
|
||||||
|
self->sprites[j]->y = self->sprites[j]->oY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteScene(Scene* target)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < target->nSprites; i++)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(target->sprites[i]->sprite);
|
||||||
|
free(target->sprites[i]);
|
||||||
|
}
|
||||||
|
free(target->sprites);
|
||||||
|
free(target);
|
||||||
|
}
|
30
Scene.h
Normal file
30
Scene.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
typedef struct sLayer
|
||||||
|
{
|
||||||
|
SDL_Surface* sprite;
|
||||||
|
int x,y,h,v;
|
||||||
|
int oX, oY;
|
||||||
|
} SLayer;
|
||||||
|
|
||||||
|
typedef struct transition
|
||||||
|
{
|
||||||
|
int in;
|
||||||
|
SDL_Color incolor;
|
||||||
|
int out;
|
||||||
|
SDL_Color outcolor;
|
||||||
|
} Transition;
|
||||||
|
|
||||||
|
typedef struct scene
|
||||||
|
{
|
||||||
|
SLayer** sprites;
|
||||||
|
int nSprites;
|
||||||
|
int time;
|
||||||
|
Transition fade;
|
||||||
|
} Scene;
|
||||||
|
|
||||||
|
SLayer* newSLayer(char* filename, int x, int y, int h, int v);
|
||||||
|
void deleteSLayer(SLayer* target);
|
||||||
|
|
||||||
|
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor);
|
||||||
|
void buildScene(Scene* self, SLayer* sprite);
|
||||||
|
void playScene(Scene* self);
|
||||||
|
void deleteScene(Scene* target);
|
BIN
assets/img/backgrounds/presents.png
Normal file
BIN
assets/img/backgrounds/presents.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
12
main.c
12
main.c
|
@ -12,6 +12,7 @@
|
||||||
#include "Kaos.h"
|
#include "Kaos.h"
|
||||||
#include "HyperKaos.h"
|
#include "HyperKaos.h"
|
||||||
#include "WorldData.h"
|
#include "WorldData.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
|
||||||
/*const int SCREEN_WIDTH = 320;
|
/*const int SCREEN_WIDTH = 320;
|
||||||
const int SCREEN_HEIGHT = 180;
|
const int SCREEN_HEIGHT = 180;
|
||||||
|
@ -68,6 +69,17 @@ 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);
|
||||||
|
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);
|
||||||
|
|
||||||
// main game loop
|
// main game loop
|
||||||
while (!quit)
|
while (!quit)
|
||||||
|
|
Loading…
Reference in a new issue