diff --git a/common.mk b/common.mk index 58357b0..a14c785 100644 --- a/common.mk +++ b/common.mk @@ -10,7 +10,7 @@ DEPS += defs.h structs.h OBJS += ai.o OBJS += battle.o bullets.o -OBJS += capitalShips.o challengeHome.o challenges.o cJSON.o controls.o +OBJS += capitalShips.o challengeHome.o challenges.o cJSON.o controls.o credits.o OBJS += debris.o dev.o draw.o OBJS += effects.o entities.o OBJS += fighters.o diff --git a/data/credits/credits.json b/data/credits/credits.json new file mode 100644 index 0000000..1e75138 --- /dev/null +++ b/data/credits/credits.json @@ -0,0 +1,134 @@ +[ + "0 30 MAIN PROGRAMMING", + "0 24 Stephen J Sweeney", + "0 24 Richard Sweeney", + + "75 30 ADDITIONAL CODE", + + "75 30 GRAPHICS", + + "30 24 Main Graphics", + "0 24 Stephen J Sweeney (CC BY-NC-SA 3.0)", + + "30 24 gfx/planets/earth.png", + "0 24 Derived from the the Blue Marble NASA photograph", + "0 24 http://visibleearth.nasa.gov/view.php?id=57723", + + "30 24 gfx/trophies/bronze.png", + "0 24 Dervied from Trophy icon, by Lorc (CC BY 3.0)", + "0 24 http://game-icons.net/lorc/originals/trophy.html", + + "30 24 gfx/trophies/gold.png", + "0 24 Dervied from Trophy icon, by Lorc (CC BY 3.0)", + "0 24 http://game-icons.net/lorc/originals/trophy.html", + + "30 24 gfx/trophies/platinum.png", + "0 24 Dervied from Trophy icon, by Lorc (CC BY 3.0)", + "0 24 http://game-icons.net/lorc/originals/trophy.html", + + "30 24 gfx/trophies/silver.png", + "0 24 Dervied from Trophy icon, by Lorc (CC BY 3.0)", + "0 24 http://game-icons.net/lorc/originals/trophy.html", + + "30 24 gfx/trophies/unearned.png", + "0 24 Dervied from Trophy icon, by Lorc (CC BY 3.0)", + "0 24 http://game-icons.net/lorc/originals/trophy.html", + + "75 30 TRANSLATIONS", + + "75 30 DEVELOPMENT SOFTWARE", + + "75 28 Simple DirectMedia Layer", + "0 24 Created by Sam Lantinga", + "0 24 Developed by the SDL Community", + + "75 28 GCC", + "0 24 GNU Compiler Collection", + "0 24 Developed by the GNU Project", + + "75 28 The GIMP", + "0 24 GNU Image Manipulation Program", + "0 24 Created by Spencer Kimball and Peter Mattis", + "0 24 Developed by The GIMP Development Team", + + "75 28 Kate", + "0 24 KDE Advanced Text Editor", + "0 24 Developed by the KDE Team", + + "75 28 Audacity", + "0 24 Created by Dominic Mazzoni and Roger Dannenberg", + "0 24 Developed by The Audacity Team", + + "75 30 FONTS", + + "30 24 data/fonts/Roboto-Medium.ttf", + "0 24 by Christian Robertson", + "0 24 Licensed under the Apache License, version 2.0", + + "30 24 data/fonts/Khosrau.ttf", + "0 24 by Fereydoun Rostam.", + "0 24 http://www.dafont.com/khosrau.font", + + "75 30 SOUND EFFECTS", + + "75 30 MUSIC", + + "30 24 Battle in the winter.mp3", + "0 24 Johan Brodd (CC-BY)", + "0 24 http://opengameart.org/content/battle-in-the-winter", + + "30 24 battleThemeA.mp3", + "0 24 cynicmusic.com | pixelsphere.org (CC-0)", + "0 24 http://opengameart.org/content/battle-theme-a", + + "30 24 determination.mp3", + "0 24 artisticdude (CC-0)", + "0 24 http://opengameart.org/content/determination", + + "30 24 heroism.ogg", + "0 24 Edward J. Blakeley (GPL 3.0)", + "0 24 http://opengameart.org/content/heroism", + + "30 24 InnerCore_Low.ogg", + "0 24 Gundatsch (CC-BY)", + "0 24 https://soundcloud.com/gundatsch", + + "30 24 Pressure.ogg", + "0 24 yd (CC-0)", + "0 24 http://opengameart.org/content/pressure", + + "30 24 Rise of Spirit", + "0 24 Alexandr Zhelanov (CC-0)", + "0 24 https://soundcloud.com/alexandr-zhelanov", + + "30 24 Showdown.mp3", + "0 24 el-corleo (CC-BY)", + "0 24 http://opengameart.org/content/showdown", + + "30 24 track-3.mp3", + "0 24 Alexandr Zhelanov (CC-BY)", + "0 24 https://soundcloud.com/alexandr-zhelanov", + + "30 24 track-4.mp3", + "0 24 Alexandr Zhelanov (CC-BY)", + "0 24 https://soundcloud.com/alexandr-zhelanov", + + "30 24 DST-RailJet-LongSeamlessLoop.ogg", + "0 24 Deceased Superior Technician (CC-BY)", + "0 24 http://opengameart.org/content/railjet-long-seamless-loop", + + "30 24 covert_operations.mp3", + "0 24 artisticdude (CC-0)", + "0 24 http://opengameart.org/content/covert-operations", + + "30 24 Tactical Pursuit.mp3", + "0 24 Matthew Pablo (CC-BY)", + "0 24 http://opengameart.org/content/tactical-pursuit", + + "75 30 SPECIAL THANKS", + "0 24 Szunti, Bertram25, bentley, akien-mga", + + "150 24 This is a work of fiction. Names, characters, businesses, places, events and incidents are either the products of the author's imagination or used in a fictitious manner. Any resemblance to actual persons, living or dead, or actual events is purely coincidental. The Battle for the Solar System : The Pandoran War is (C) 2015-2016, Stephen J Sweeney, Some Rights Reserved. The Battle for the Solar System and all related materials (including, but not limited to, characters, setting, and story elements) are (C) 2009-2016, Stephen J Sweeney, All Rights Reserved.", + + "500 30 www.battleforthesolarsystem.com" +] diff --git a/music/main/Her Violet Eyes.mp3 b/music/main/Her Violet Eyes.mp3 new file mode 100644 index 0000000..2ed5008 Binary files /dev/null and b/music/main/Her Violet Eyes.mp3 differ diff --git a/src/game/credits.c b/src/game/credits.c new file mode 100644 index 0000000..cda05dd --- /dev/null +++ b/src/game/credits.c @@ -0,0 +1,172 @@ +/* +Copyright (C) 2015-2016 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 SDL_Texture *background; +static SDL_Texture *earthTexture; +static Credit head; +static Credit *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); + + background = getTexture("gfx/backgrounds/background02.jpg"); + + earthTexture = getTexture("gfx/planets/earth.png"); + + loadCredits(); + + endSectionTransition(); + + playMusic("music/main/Her Violet Eyes.mp3"); +} + +static void logic(void) +{ + Credit *c; + + handleKeyboard(); + + for (c = head.next ; c != NULL ; c = c->next) + { + c->y -= creditSpeed; + + if (!c->next) + { + c->y = MAX(c->y, (SCREEN_HEIGHT - c->h) / 2); + } + } + + if (--timeout <= 0) + { + exit(0); + } +} + +static void draw(void) +{ + Credit *c; + + drawBackground(background); + + blit(earthTexture, SCREEN_WIDTH - 200, (SCREEN_HEIGHT / 2) + 100, 1); + + 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); + + drawText(10, 10, 18, TA_LEFT, colors.white, "%d", timeout / FPS); +} + +static void loadCredits(void) +{ + cJSON *root, *node; + int y, dist; + char *text; + Credit *c; + + y = SCREEN_HEIGHT + 100; + + text = readFile("data/credits/credits.json"); + root = cJSON_Parse(text); + + limitTextWidth(CREDIT_LINE_LIMIT); + + for (node = root->child ; node != NULL ; node = node->next) + { + c = malloc(sizeof(Credit)); + memset(c, 0, sizeof(Credit)); + tail->next = c; + tail = c; + + c->y = y; + + c->text = malloc(sizeof(char) * strlen(node->valuestring)); + memset(c->text, '\0', sizeof(char) * strlen(node->valuestring)); + + sscanf(node->valuestring, "%d %d %[^\n]", &dist, &c->size, c->text); + + c->y += dist; + c->h = getWrappedTextHeight(c->text, c->size); + + y += c->h + dist; + } + + limitTextWidth(0); + + /* the music that plays over the credits is 2m 44s, so scroll credits roughly inline with that */ + timeout = ((2 * 60) + 55) * FPS; + + creditSpeed = y; + creditSpeed /= timeout; + + cJSON_Delete(root); + free(text); +} + +static void handleKeyboard(void) +{ + if (app.keyboard[SDL_SCANCODE_ESCAPE]) + { + + } +} + +void destroyCredits(void) +{ + Credit *c; + + while (head.next) + { + c = head.next; + head.next = c->next; + if (c->text) + { + free(c->text); + } + free(c); + } +} diff --git a/src/game/credits.h b/src/game/credits.h new file mode 100644 index 0000000..f3f292c --- /dev/null +++ b/src/game/credits.h @@ -0,0 +1,39 @@ +/* +Copyright (C) 2015-2016 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" +#include "../json/cJSON.h" + +#define CREDIT_LINE_LIMIT (SCREEN_WIDTH - 300) + +extern SDL_Texture *getTexture(const char *filename); +extern void playMusic(char *filename); +extern void drawBackground(SDL_Texture *texture); +extern void startSectionTransition(void); +extern void endSectionTransition(void); +extern void stopMusic(void); +extern void blit(SDL_Texture *t, int x, int y, int centered); +extern char *readFile(char *filename); +extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); +extern void limitTextWidth(int width); +extern int getWrappedTextHeight(char *text, int size); + +extern App app; +extern Colors colors; diff --git a/src/main.c b/src/main.c index 368b3f9..7c18481 100644 --- a/src/main.c +++ b/src/main.c @@ -208,8 +208,9 @@ static void handleLoggingArgs(int argc, char *argv[]) static void handleMissionArgs(int argc, char *argv[]) { - int i; - int testingMission = 0; + int i, testingMission, showCredits; + + showCredits = testingMission = 0; for (i = 1 ; i < argc ; i++) { @@ -220,9 +221,18 @@ static void handleMissionArgs(int argc, char *argv[]) testingMission = 1; } + + if (strcmp(argv[i], "-credits") == 0) + { + showCredits = 1; + } } - if (!testingMission) + if (showCredits) + { + initCredits(); + } + else if (!testingMission) { initTitle(); } diff --git a/src/main.h b/src/main.h index 727f219..0794787 100644 --- a/src/main.h +++ b/src/main.h @@ -51,6 +51,7 @@ extern void createScreenshotFolder(void); extern int isControl(int type); extern void clearControl(int type); extern void saveGame(void); +extern void initCredits(void); App app; Colors colors; diff --git a/src/structs.h b/src/structs.h index e6b42d4..7e4b533 100644 --- a/src/structs.h +++ b/src/structs.h @@ -40,6 +40,7 @@ typedef struct Location Location; typedef struct Bucket Bucket; typedef struct Trophy Trophy; typedef struct Tuple Tuple; +typedef struct Credit Credit; typedef struct { int debug; @@ -512,6 +513,14 @@ typedef struct { SDL_Color darkGrey; } Colors; +struct Credit { + char *text; + float y; + int size; + int h; + Credit *next; +}; + struct Bucket { char *key, *value; Bucket *next; diff --git a/src/system/init.c b/src/system/init.c index 347ce4e..ed3bd2f 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -363,6 +363,8 @@ void cleanup(void) destroyResources(); + destroyCredits(); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Done"); TTF_Quit(); diff --git a/src/system/init.h b/src/system/init.h index baf6729..b73d321 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -71,6 +71,7 @@ extern char *getLookupName(char *prefix, long num); extern long lookup(char *name); extern void initStars(void); extern void initTrophies(void); +extern void destroyCredits(void); extern App app; extern Colors colors;