tbftss/src/game/title.c

285 lines
5.7 KiB
C
Raw Normal View History

2015-10-20 13:51:49 +02:00
/*
2016-02-21 16:50:27 +01:00
Copyright (C) 2015-2016 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);
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 quit(void);
static void returnFromOptions(void);
static SDL_Texture *background;
static SDL_Texture *logo;
static SDL_Texture *pandoranWar;
static SDL_Texture *earthTexture;
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();
logo = getTexture("gfx/title/logo.png");
pandoranWar = getTexture("gfx/title/pandoran.png");
background = getTexture("gfx/backgrounds/background02.jpg");
earthTexture = getTexture("gfx/planets/earth.png");
earth.x = rand() % SCREEN_WIDTH;
earth.y = -(128 + (rand() % 128));
initBackground();
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;
2015-10-20 13:51:49 +02:00
getWidget("options", "title")->action = options;
getWidget("quit", "title")->action = quit;
2016-05-15 09:19:26 +02:00
getWidget("ok", "stats")->action = ok;
getWidget("ok", "trophies")->action = ok;
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++)
{
2016-04-02 17:38:26 +02:00
fighters[i].x = rand() % (SCREEN_WIDTH - 32);
2015-10-20 13:51:49 +02:00
fighters[i].y = SCREEN_HEIGHT + (rand() % SCREEN_HEIGHT);
fighters[i].texture = getTexture(fighterTextures[rand() % numTextures]);
fighters[i].dy = -(1 + rand() % 3);
}
}
static void logic(void)
{
handleKeyboard();
scrollBackground(0, 0.25);
doStars(0, -0.5);
earth.y += 0.1;
if (earth.y > SCREEN_HEIGHT + 128)
{
earth.x = rand() % SCREEN_WIDTH;
earth.y = -(128 + (rand() % 128));
}
doFighters();
doEffects();
2016-05-15 09:19:26 +02:00
doTrophies();
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
{
2016-04-13 12:04:47 +02:00
self->x = rand() % (SCREEN_WIDTH - 32);
self->y = SCREEN_HEIGHT + (rand() % SCREEN_HEIGHT);
self->texture = getTexture(fighterTextures[rand() % numTextures]);
self->dy = -(1 + rand() % 3);
2015-10-20 13:51:49 +02:00
}
}
}
static void draw(void)
{
drawBackground(background);
drawStars();
blit(earthTexture, earth.x, earth.y, 1);
drawFighters();
drawEffects();
blit(logo, SCREEN_WIDTH / 2, 50, 1);
blit(pandoranWar, SCREEN_WIDTH / 2, 110, 1);
2016-02-21 16:50:27 +01:00
drawText(10, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2016");
2015-11-14 15:45:19 +01:00
drawText(SCREEN_WIDTH - 10, SCREEN_HEIGHT - 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:
drawWidgets("title");
break;
case SHOW_STATS:
drawStats();
break;
case SHOW_OPTIONS:
drawOptions();
break;
2016-05-15 09:19:26 +02:00
case SHOW_TROPHIES:
drawTrophies();
break;
2015-10-20 13:51:49 +02:00
}
}
static void drawFighters(void)
{
int i;
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();
}
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 quit(void)
{
2016-04-02 17:38:26 +02:00
exit(0);
2015-10-20 13:51:49 +02:00
}