1 /*
2 Copyright (C) 2009-2021 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19
20 #include "headers.h"
21
22 #include "audio/music.h"
23 #include "game.h"
24 #include "graphics/animation.h"
25 #include "graphics/font.h"
26 #include "graphics/graphics.h"
27 #include "player.h"
28 #include "system/load_save.h"
29 #include "system/random.h"
30
31 extern Input menuInput, input;
32 extern Game game;
33 extern Entity player;
34
35 static Title title;
36
37 static void initTitle(void);
38
doTitle()39 void doTitle()
40 {
41 if (title.edgarLogo == NULL)
42 {
43 initTitle();
44 }
45
46 title.thinkTime--;
47
48 if (title.thinkTime <= -30)
49 {
50 title.thinkTime = 30;
51 }
52 }
53
drawTitle()54 void drawTitle()
55 {
56 if (title.edgarLogo != NULL)
57 {
58 drawImage(title.edgarLogo, (SCREEN_WIDTH - title.edgarLogo->w) / 2, SCREEN_HEIGHT / 8, FALSE, 255);
59
60 drawImage(title.copyright, (SCREEN_WIDTH - title.copyright->w) / 2, SCREEN_HEIGHT - title.copyright->h - 5, FALSE, 255);
61
62 drawLoopingAnimation(&player, (SCREEN_WIDTH - player.w) / 2, SCREEN_HEIGHT / 2 + player.h / 2, 0, 0, 0);
63
64 if (title.thinkTime <= 0)
65 {
66 drawImage(title.startButton, (SCREEN_WIDTH - title.startButton->w) / 2, SCREEN_HEIGHT * 6 / 8, FALSE, 255);
67 }
68 }
69
70 drawGame();
71 }
72
initTitle()73 static void initTitle()
74 {
75 char copyright[MAX_VALUE_LENGTH];
76 SDL_Surface *surface;
77
78 SNPRINTF(copyright, MAX_VALUE_LENGTH, _("Copyright Parallel Realities 2009 - %d"), YEAR);
79
80 surface = generateTransparentTextSurface(copyright, game.font, 220, 220, 220, TRUE);
81
82 title.copyright = convertSurfaceToTexture(surface, TRUE);
83
84 title.edgarLogo = loadImage("gfx/title_screen/logo.png");
85
86 surface = generateTransparentTextSurface(_("Press any key"), game.largeFont, 220, 220, 220, TRUE);
87
88 title.startButton = convertSurfaceToTexture(surface, TRUE);
89
90 title.thinkTime = 30;
91
92 loadPlayer(0, 0, "edgar/edgar_title");
93
94 setEntityAnimationByID(&player, prand() % 3);
95
96 title.continueSlot = getMostRecentSave();
97
98 if (title.continueSlot != -1)
99 {
100 game.canContinue = TRUE;
101 }
102
103 setTransition(TRANSITION_IN, NULL);
104
105 loadMusic("TITLE_MUSIC");
106
107 playLoadedMusic();
108 }
109
freeTitle()110 void freeTitle()
111 {
112 if (title.edgarLogo != NULL)
113 {
114 destroyTexture(title.edgarLogo);
115
116 title.edgarLogo = NULL;
117 }
118
119 if (title.copyright != NULL)
120 {
121 destroyTexture(title.copyright);
122
123 title.copyright = NULL;
124 }
125
126 if (title.startButton != NULL)
127 {
128 destroyTexture(title.startButton);
129
130 title.startButton = NULL;
131 }
132 }
133