blobwarsAttrition/src/game/ending.c

127 lines
2.9 KiB
C
Raw Normal View History

2018-02-02 20:10:12 +01:00
/*
2019-06-02 17:13:34 +02:00
Copyright (C) 2018-2019 Parallel Realities
2018-02-02 20:10:12 +01:00
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 "ending.h"
2018-03-15 09:00:00 +01:00
static void logic(void);
static void draw(void);
static void loadEndingText(void);
static char endingText[NUM_ENDING_LINES][MAX_DESCRIPTION_LENGTH];
static Atlas *background[2];
static Texture *atlasTexture;
static int endingTextIndex;
static int endingImageIndex;
static int endingTimer;
2018-02-02 20:10:12 +01:00
void initEnding(void)
{
2018-03-30 14:34:36 +02:00
startSectionTransition();
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
background[0] = getImageFromAtlas("gfx/ending/ending01.jpg");
background[1] = getImageFromAtlas("gfx/ending/ending02.jpg");
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
atlasTexture = getTexture("gfx/atlas/atlas.png");
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
loadEndingText();
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
endingTextIndex = 0;
endingImageIndex = 0;
endingTimer = strlen(endingText[endingTextIndex]) * 4;
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
app.delegate.logic = &logic;
app.delegate.draw = &draw;
2019-06-02 17:13:34 +02:00
2018-03-30 14:34:36 +02:00
endSectionTransition();
2018-03-15 09:00:00 +01:00
}
static void logic(void)
{
if (--endingTimer <= -FPS / 2)
{
if (endingTextIndex < NUM_ENDING_LINES)
{
2018-03-30 14:34:36 +02:00
if (++endingTextIndex == 3)
{
endingImageIndex++;
startSectionTransition();
endSectionTransition();
}
2019-06-02 17:13:34 +02:00
2018-03-30 14:34:36 +02:00
if (endingTextIndex < NUM_ENDING_LINES)
{
endingTimer = strlen(endingText[endingTextIndex]) * 4;
}
else
{
fadeMusic(3000);
2019-06-02 17:13:34 +02:00
2018-03-30 14:34:36 +02:00
endingTimer = FPS * 4;
}
2018-03-15 09:00:00 +01:00
}
else
{
initCredits(1);
2018-03-15 09:00:00 +01:00
}
}
}
static void draw(void)
{
float h;
int th;
2019-06-02 17:13:34 +02:00
2018-12-23 16:32:33 +01:00
h = (app.config.winWidth / 800.0) * background[endingImageIndex]->rect.h;
2019-06-02 17:13:34 +02:00
2018-12-23 16:32:33 +01:00
blitRectScaled(atlasTexture->texture, 0, app.config.winHeight - h, app.config.winWidth, h, &background[endingImageIndex]->rect, 0);
2019-06-02 17:13:34 +02:00
2018-03-30 14:34:36 +02:00
if (endingTimer > 0 && endingTextIndex < NUM_ENDING_LINES)
2018-03-15 09:00:00 +01:00
{
2018-12-23 16:32:33 +01:00
app.textWidth = (app.config.winWidth / 2);
2018-03-15 09:00:00 +01:00
th = getWrappedTextHeight(endingText[endingTextIndex], 24) + 15;
2018-12-23 16:32:33 +01:00
drawRect(0, app.config.winHeight - th - 10, app.config.winWidth, th + 10, 0, 0, 0, 128);
drawText(app.config.winWidth / 2, app.config.winHeight - th, 24, TA_CENTER, colors.white, endingText[endingTextIndex]);
2018-12-22 23:46:38 +01:00
app.textWidth = 0;
2018-03-15 09:00:00 +01:00
}
}
static void loadEndingText(void)
{
int i;
char *text, *line;
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
i = 0;
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
memset(endingText, 0, sizeof(NUM_ENDING_LINES * MAX_DESCRIPTION_LENGTH));
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
text = readFile("data/misc/ending.txt");
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
line = strtok(text, "\n");
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
while (line)
{
2018-04-01 18:41:45 +02:00
strncpy(endingText[i++], _(line), MAX_DESCRIPTION_LENGTH);
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
line = strtok(NULL, "\n");
}
2019-06-02 17:13:34 +02:00
2018-03-16 09:30:37 +01:00
free(text);
2018-02-02 20:10:12 +01:00
}