tbftss/src/game/title.c

321 lines
6.5 KiB
C
Raw Normal View History

2015-10-20 13:51:49 +02:00
/*
2019-01-01 17:14:11 +01:00
Copyright (C) 2015-2019 Parallel Realities
2015-10-20 13:51:49 +02: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 "title.h"
static void logic(void);
static void draw(void);
static void handleKeyboard(void);
static void initFighters(void);
static void doFighters(void);
static void drawFighters(void);
2016-02-27 13:14:29 +01:00
static void campaign(void);
static void challenges(void);
2016-05-15 09:19:26 +02:00
static void trophies(void);
2016-02-29 10:35:39 +01:00
static void stats(void);
2017-08-07 20:14:43 +02:00
static void fighterDatabase(void);
2016-05-15 09:19:26 +02:00
static void ok(void);
2015-10-20 13:51:49 +02:00
static void options(void);
static void credits(void);
2015-10-20 13:51:49 +02:00
static void quit(void);
static void returnFromOptions(void);
static SDL_Texture *background;
2018-12-06 09:37:19 +01:00
static AtlasImage *logo[2];
static AtlasImage *pandoranWar;
static AtlasImage *earthTexture;
2015-10-20 13:51:49 +02:00
static PointF earth;
static Entity fighters[NUM_FIGHTERS];
static const char *fighterTextures[] = {"gfx/fighters/firefly.png", "gfx/fighters/hammerhead.png", "gfx/fighters/hyena.png", "gfx/fighters/lynx.png", "gfx/fighters/kingfisher.png", "gfx/fighters/leopard.png", "gfx/fighters/nymph.png", "gfx/fighters/ray.png", "gfx/fighters/rook.png", "gfx/fighters/taf.png"};
2016-02-29 10:35:39 +01:00
static int show;
2015-10-20 13:51:49 +02:00
void initTitle(void)
{
startSectionTransition();
stopMusic();
app.delegate.logic = &logic;
app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
battle.camera.x = battle.camera.y = 0;
2015-10-20 13:51:49 +02:00
destroyBattle();
2018-12-06 09:37:19 +01:00
logo[0] = getAtlasImage("gfx/title/logo01.png");
logo[1] = getAtlasImage("gfx/title/logo02.png");
2015-10-20 13:51:49 +02:00
2018-12-06 09:37:19 +01:00
pandoranWar = getAtlasImage("gfx/title/pandoran.png");
2015-10-20 13:51:49 +02:00
background = getTexture("gfx/backgrounds/background02.jpg");
2018-12-06 09:37:19 +01:00
earthTexture = getAtlasImage("gfx/planets/earth.png");
2015-10-20 13:51:49 +02:00
2018-12-12 09:32:32 +01:00
earth.x = rand() % app.winWidth;
2015-10-20 13:51:49 +02:00
earth.y = -(128 + (rand() % 128));
initEffects();
2015-10-20 13:51:49 +02:00
initFighters();
2016-02-29 11:47:10 +01:00
updateAllMissions();
2016-02-27 13:14:29 +01:00
getWidget("campaign", "title")->action = campaign;
getWidget("challenges", "title")->action = challenges;
2016-05-15 09:19:26 +02:00
getWidget("trophies", "title")->action = trophies;
2016-02-29 10:35:39 +01:00
getWidget("stats", "title")->action = stats;
2017-08-07 20:14:43 +02:00
getWidget("fighterDB", "title")->action = fighterDatabase;
2015-10-20 13:51:49 +02:00
getWidget("options", "title")->action = options;
getWidget("credits", "title")->action = credits;
2015-10-20 13:51:49 +02:00
getWidget("quit", "title")->action = quit;
2016-05-15 09:19:26 +02:00
getWidget("ok", "stats")->action = ok;
getWidget("ok", "trophies")->action = ok;
2017-08-10 09:44:19 +02:00
getWidget("ok", "fighterDB")->action = ok;
2016-02-29 10:35:39 +01:00
2018-05-06 19:50:11 +02:00
autoSizeWidgetButtons("title", 1);
2016-02-29 10:35:39 +01:00
show = SHOW_TITLE;
2015-10-20 13:51:49 +02:00
endSectionTransition();
2016-05-29 12:48:11 +02:00
playMusic("music/main/Rise of spirit.ogg", 0);
2015-10-20 13:51:49 +02:00
}
static void initFighters(void)
{
int i, numTextures;
numTextures = sizeof(fighterTextures) / sizeof(char*);
memset(&fighters, 0, sizeof(Entity) * NUM_FIGHTERS);
2015-10-20 13:51:49 +02:00
for (i = 0 ; i < NUM_FIGHTERS ; i++)
{
2018-12-12 09:32:32 +01:00
fighters[i].x = rand() % (app.winWidth - 32);
fighters[i].y = app.winHeight + (rand() % app.winHeight);
2018-12-06 09:37:19 +01:00
fighters[i].texture = getAtlasImage(fighterTextures[rand() % numTextures]);
2015-10-20 13:51:49 +02:00
fighters[i].dy = -(1 + rand() % 3);
}
}
static void logic(void)
{
handleKeyboard();
scrollBackground(0, 0.25);
doStars(0, -0.5);
earth.y += 0.1;
2018-12-12 09:32:32 +01:00
if (earth.y > app.winHeight + 128)
2015-10-20 13:51:49 +02:00
{
2018-12-12 09:32:32 +01:00
earth.x = rand() % app.winWidth;
2015-10-20 13:51:49 +02:00
earth.y = -(128 + (rand() % 128));
}
doFighters();
doEffects();
app.doTrophyAlerts = 1;
2016-05-15 09:19:26 +02:00
2017-08-10 09:44:19 +02:00
if (show == SHOW_FIGHTER_DB)
{
doFighterDatabase();
}
2015-10-20 13:51:49 +02:00
doWidgets();
}
static void doFighters(void)
{
2016-04-02 17:38:26 +02:00
int i, numTextures;
numTextures = sizeof(fighterTextures) / sizeof(char*);
2015-10-20 13:51:49 +02:00
for (i = 0 ; i < NUM_FIGHTERS ; i++)
{
self = &fighters[i];
2016-04-13 12:04:47 +02:00
/* engine position hack, due to camera being fixed */
self->y += 16;
2015-10-20 13:51:49 +02:00
addEngineEffect();
2016-04-13 12:04:47 +02:00
self->y -= 16;
self->y += self->dy;
2015-10-20 13:51:49 +02:00
2016-04-13 12:04:47 +02:00
if (self->y <= -64)
2015-10-20 13:51:49 +02:00
{
2018-12-12 09:32:32 +01:00
self->x = rand() % (app.winWidth - 32);
self->y = app.winHeight + (rand() % app.winHeight);
2018-12-06 09:37:19 +01:00
self->texture = getAtlasImage(fighterTextures[rand() % numTextures]);
2016-04-13 12:04:47 +02:00
self->dy = -(1 + rand() % 3);
2015-10-20 13:51:49 +02:00
}
}
}
static void draw(void)
{
drawBackground(background);
drawStars();
2018-12-06 17:52:13 +01:00
setAtlasColor(255, 255, 255, 255);
2018-12-06 09:37:19 +01:00
2015-10-20 13:51:49 +02:00
blit(earthTexture, earth.x, earth.y, 1);
drawFighters();
drawEffects();
2018-12-06 17:52:13 +01:00
setAtlasColor(255, 255, 255, 255);
2018-12-06 09:37:19 +01:00
2018-12-12 09:32:32 +01:00
blit(logo[0], (app.winWidth / 2) - logo[0]->rect.w, 30, 0);
blit(logo[1], (app.winWidth / 2), 30, 0);
2015-10-20 13:51:49 +02:00
2018-12-12 09:32:32 +01:00
blit(pandoranWar, app.winWidth / 2, 110, 1);
2015-10-20 13:51:49 +02:00
2019-01-01 17:14:11 +01:00
drawText(10, app.winHeight - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2019");
2018-12-12 09:32:32 +01:00
drawText(app.winWidth - 10, app.winHeight - 25, 14, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION);
2015-10-20 13:51:49 +02:00
2016-02-29 10:35:39 +01:00
switch (show)
2015-10-20 13:51:49 +02:00
{
2016-02-29 10:35:39 +01:00
case SHOW_TITLE:
2018-12-12 09:32:32 +01:00
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
2016-02-29 10:35:39 +01:00
drawWidgets("title");
2018-12-12 09:32:32 +01:00
SDL_SetRenderTarget(app.renderer, app.backBuffer);
2016-02-29 10:35:39 +01:00
break;
case SHOW_STATS:
drawStats();
break;
case SHOW_OPTIONS:
drawOptions();
break;
2016-05-15 09:19:26 +02:00
case SHOW_TROPHIES:
drawTrophies();
break;
2017-08-07 20:14:43 +02:00
case SHOW_FIGHTER_DB:
drawFighterDatabase();
break;
2015-10-20 13:51:49 +02:00
}
}
static void drawFighters(void)
{
int i;
2018-12-06 17:52:13 +01:00
setAtlasColor(255, 255, 255, 255);
2015-10-20 13:51:49 +02:00
for (i = 0 ; i < NUM_FIGHTERS ; i++)
{
blit(fighters[i].texture, fighters[i].x, fighters[i].y, 1);
}
}
static void handleKeyboard(void)
{
if (app.keyboard[SDL_SCANCODE_ESCAPE] && !app.awaitingWidgetInput)
2015-10-20 13:51:49 +02:00
{
returnFromOptions();
playSound(SND_GUI_CLOSE);
2016-03-05 16:35:09 +01:00
clearInput();
2015-10-20 13:51:49 +02:00
}
}
2016-02-27 13:14:29 +01:00
static void campaign(void)
2015-10-20 13:51:49 +02:00
{
2016-05-15 09:19:26 +02:00
destroyBattle();
2015-10-20 13:51:49 +02:00
initGalacticMap();
}
2016-02-27 13:14:29 +01:00
static void challenges(void)
2015-10-20 13:51:49 +02:00
{
2016-05-15 09:19:26 +02:00
destroyBattle();
game.currentMission = NULL;
2016-02-27 17:16:21 +01:00
initChallengeHome();
2015-10-20 13:51:49 +02:00
}
2016-05-15 09:19:26 +02:00
static void trophies(void)
{
selectWidget("ok", "trophies");
show = SHOW_TROPHIES;
initTrophiesDisplay();
}
2017-08-07 20:14:43 +02:00
static void fighterDatabase(void)
{
show = SHOW_FIGHTER_DB;
initFighterDatabaseDisplay();
}
2015-10-20 13:51:49 +02:00
static void options(void)
{
2016-02-29 10:35:39 +01:00
selectWidget("ok", "options");
show = SHOW_OPTIONS;
2015-10-20 13:51:49 +02:00
initOptions(returnFromOptions);
}
2016-02-29 10:35:39 +01:00
static void stats(void)
{
selectWidget("ok", "stats");
show = SHOW_STATS;
initStatsDisplay();
}
2016-05-15 09:19:26 +02:00
static void ok(void)
2016-02-29 10:35:39 +01:00
{
selectWidget("stats", "title");
show = SHOW_TITLE;
}
2015-10-20 13:51:49 +02:00
static void returnFromOptions(void)
{
2016-02-29 10:35:39 +01:00
show = SHOW_TITLE;
2015-10-20 13:51:49 +02:00
}
static void credits(void)
{
initCredits();
}
2015-10-20 13:51:49 +02:00
static void quit(void)
{
2016-04-02 17:38:26 +02:00
exit(0);
2015-10-20 13:51:49 +02:00
}