Start of credits.

This commit is contained in:
Steve 2018-03-16 08:28:25 +00:00
parent 2dcbeb368d
commit 8d54233df5
6 changed files with 231 additions and 1 deletions

View File

@ -32,7 +32,7 @@ DEPS += defs.h structs.h
_OBJS += atlas.o aquaBlob.o
_OBJS += battery.o blaze.o bob.o boss.o blobBoss.o bullet.o
_OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o controls.o consumable.o
_OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o controls.o consumable.o credits.o
_OBJS += debris.o destructable.o door.o draw.o
_OBJS += effects.o ending.o entities.o entity.o entityFactory.o exit.o explosions.o eyeDroid.o eyeDroidCommander.o evilBlob.o
_OBJS += fleshChunk.o frost.o

172
src/game/credits.c Normal file
View File

@ -0,0 +1,172 @@
/*
Copyright (C) 2015-2017 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "credits.h"
static void loadCredits(void);
static void logic(void);
static void draw(void);
static void handleKeyboard(void);
static Texture *atlasTexture;
static Atlas *background;
static Credit head, *tail;
static float creditSpeed;
static int timeout;
void initCredits(void)
{
startSectionTransition();
stopMusic();
memset(&head, 0, sizeof(Credit));
tail = &head;
app.delegate.logic = &logic;
app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
atlasTexture = getTexture("gfx/atlas/atlas.png");
background = getImageFromAtlas("gfx/main/credits.png");
loadCredits();
loadMusic("music/Eternal Wishes.ogg");
playMusic(0);
endSectionTransition();
}
static void logic(void)
{
Credit *c;
handleKeyboard();
for (c = head.next ; c != NULL ; c = c->next)
{
c->y -= creditSpeed;
}
if (--timeout <= 0)
{
exit(1);
}
}
static void draw(void)
{
float scale;
int w, h;
Credit *c;
scale = (SCREEN_WIDTH * 1.0) / background->rect.w;
w = background->rect.w * scale;
h = background->rect.h * scale;
blitRectScaled(atlasTexture->texture, 0, SCREEN_HEIGHT - h, w, h, &background->rect, 0);
limitTextWidth(CREDIT_LINE_LIMIT);
for (c = head.next ; c != NULL ; c = c->next)
{
if (c->y > -c->h && c->y < SCREEN_HEIGHT)
{
drawText(SCREEN_WIDTH / 2, (int)c->y, c->size, TA_CENTER, colors.white, c->text);
}
}
limitTextWidth(0);
}
static void loadCredits(void)
{
int y, dist;
char *text, *line, *saveptr;
Credit *c;
y = SCREEN_HEIGHT + 50;
text = readFile("data/misc/credits.txt");
limitTextWidth(CREDIT_LINE_LIMIT);
line = strtok_r(text, "\n", &saveptr);
while (line)
{
c = malloc(sizeof(Credit));
memset(c, 0, sizeof(Credit));
tail->next = c;
tail = c;
c->y = y;
c->text = malloc(sizeof(char) * strlen(line));
memset(c->text, '\0', sizeof(char) * strlen(line));
sscanf(line, "%d %d %[^\n]", &dist, &c->size, c->text);
c->y += dist;
c->h = getWrappedTextHeight(c->text, c->size);
y += c->h + dist;
line = strtok_r(NULL, "\n", &saveptr);
}
limitTextWidth(0);
/* the music that plays over the credits is 1m 55s, so scroll credits roughly inline with that (plus 2 seconds) */
timeout = (60 + 57) * FPS;
creditSpeed = y;
creditSpeed /= timeout;
free(text);
}
static void handleKeyboard(void)
{
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
timeout = 0;
}
}
void destroyCredits(void)
{
Credit *c;
while (head.next)
{
c = head.next;
head.next = c->next;
if (c->text)
{
free(c->text);
}
free(c);
}
}

42
src/game/credits.h Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2018 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#define CREDIT_LINE_LIMIT 500
extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center);
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern void endSectionTransition(void);
extern Atlas *getImageFromAtlas(char *filename);
extern Texture *getTexture(const char *filename);
extern int getWrappedTextHeight(const char *text, int size);
extern void limitTextWidth(int width);
extern char *readFile(const char *filename);
extern void startSectionTransition(void);
extern void stopMusic(void);
extern void loadMusic(char *filename);
extern void playMusic(int loop);
extern App app;
extern Colors colors;

View File

@ -176,6 +176,12 @@ static void handleCommandLine(int argc, char *argv[])
initEnding();
return;
}
if (strcmp(argv[i], "-credits") == 0)
{
initCredits();
return;
}
}
initWorldTest(worldId);

View File

@ -33,6 +33,7 @@ extern void initLookups(void);
extern void initSDL(void);
extern void initWorldTest(char *worldId);
extern void initEnding(void);
extern void initCredits(void);
extern void prepareScene(void);
extern void presentScene(void);
extern void saveScreenshot(char *name);

View File

@ -34,6 +34,7 @@ typedef struct Bucket Bucket;
typedef struct EntityDef EntityDef;
typedef struct Trophy Trophy;
typedef struct cJSON cJSON;
typedef struct Credit Credit;
typedef struct Entity Entity;
typedef struct EntityExt EntityExt;
@ -503,6 +504,14 @@ struct Atlas {
Atlas *next;
};
struct Credit {
char *text;
float y;
int size;
int h;
Credit *next;
};
/* ===== i18n stuff ==== */
struct Bucket {