diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index ec253ee..4ae11d6 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -5,6 +5,12 @@ | |||
5 | #include "game.h" | 5 | #include "game.h" |
6 | #include "renderer.h" | 6 | #include "renderer.h" |
7 | 7 | ||
8 | enum class TitleState { | ||
9 | FadeIn, | ||
10 | Sustain, | ||
11 | FadeOut | ||
12 | }; | ||
13 | |||
8 | int main(int, char**) | 14 | int main(int, char**) |
9 | { | 15 | { |
10 | std::random_device randomEngine; | 16 | std::random_device randomEngine; |
@@ -17,6 +23,14 @@ int main(int, char**) | |||
17 | 23 | ||
18 | Game game(rng, muxer); | 24 | Game game(rng, muxer); |
19 | 25 | ||
26 | constexpr int titleFadeLen = 3000; | ||
27 | bool doneTitles = false; | ||
28 | int titleNum = 0; | ||
29 | TitleState titleState = TitleState::FadeIn; | ||
30 | Interpolation titleFade; | ||
31 | Timer titleSustain(3000); | ||
32 | titleFade.start(titleFadeLen); | ||
33 | |||
20 | size_t lastTime = SDL_GetTicks(); | 34 | size_t lastTime = SDL_GetTicks(); |
21 | while (!game.quit) | 35 | while (!game.quit) |
22 | { | 36 | { |
@@ -24,9 +38,58 @@ int main(int, char**) | |||
24 | size_t frameTime = currentTime - lastTime; | 38 | size_t frameTime = currentTime - lastTime; |
25 | lastTime = currentTime; | 39 | lastTime = currentTime; |
26 | 40 | ||
27 | game.update(frameTime); | 41 | if (doneTitles) { |
28 | renderer.renderGame(game, true); | 42 | game.update(frameTime); |
29 | muxer.update(); | 43 | renderer.renderGame(game, true); |
44 | muxer.update(); | ||
45 | } else { | ||
46 | SDL_Event e; | ||
47 | |||
48 | while (SDL_PollEvent(&e)); | ||
49 | |||
50 | switch (titleState) { | ||
51 | case TitleState::FadeIn: { | ||
52 | titleFade.tick(frameTime); | ||
53 | if (titleFade.isComplete()) { | ||
54 | titleState = TitleState::Sustain; | ||
55 | titleSustain.reset(); | ||
56 | } | ||
57 | |||
58 | renderer.renderTitle(titleNum, titleFade.getProgress(0, 1)); | ||
59 | |||
60 | break; | ||
61 | } | ||
62 | case TitleState::Sustain: { | ||
63 | titleSustain.accumulate(frameTime); | ||
64 | const Uint8* state = SDL_GetKeyboardState(NULL); | ||
65 | if (state[SDL_SCANCODE_SPACE] || titleSustain.step()) { | ||
66 | titleState = TitleState::FadeOut; | ||
67 | titleFade.start(titleFadeLen); | ||
68 | } | ||
69 | |||
70 | renderer.renderTitle(titleNum, 1); | ||
71 | |||
72 | break; | ||
73 | } | ||
74 | case TitleState::FadeOut: { | ||
75 | titleFade.tick(frameTime); | ||
76 | renderer.renderTitle(titleNum, titleFade.getProgress(1, 0)); | ||
77 | |||
78 | if (titleFade.isComplete()) { | ||
79 | titleNum++; | ||
80 | |||
81 | if (titleNum < NUM_TITLES) { | ||
82 | titleState = TitleState::FadeIn; | ||
83 | titleFade.start(titleFadeLen); | ||
84 | } else { | ||
85 | doneTitles = true; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | } | ||
30 | } | 93 | } |
31 | } catch (const sdl_error& ex) | 94 | } catch (const sdl_error& ex) |
32 | { | 95 | { |