summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input_system.cpp29
-rw-r--r--src/menu_system.cpp26
-rw-r--r--src/menu_system.h23
-rw-r--r--src/renderer.cpp20
4 files changed, 86 insertions, 12 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index c399e91..fd7889d 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -5,6 +5,7 @@
5#include "script_system.h" 5#include "script_system.h"
6#include "transform_system.h" 6#include "transform_system.h"
7#include "animation_system.h" 7#include "animation_system.h"
8#include "menu_system.h"
8 9
9struct Input { 10struct Input {
10 bool left = false; 11 bool left = false;
@@ -16,25 +17,29 @@ struct Input {
16void InputSystem::tick(double dt) { 17void InputSystem::tick(double dt) {
17 SDL_Event e; 18 SDL_Event e;
18 while (SDL_PollEvent(&e)) { 19 while (SDL_PollEvent(&e)) {
19 if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) { 20 if (e.type == SDL_QUIT) {
20 if (debugConsole_) {
21 debugConsole_ = false;
22 game_.unpauseGameplay();
23 SDL_StopTextInput();
24 debugText_.clear();
25 } else {
26 game_.quit();
27 }
28 } else if (e.type == SDL_QUIT) {
29 game_.quit(); 21 game_.quit();
30 22
31 return; 23 return;
32 } else if (e.type == SDL_TEXTINPUT) { 24 } else if (e.type == SDL_TEXTINPUT) {
33 debugText_.append(e.text.text); 25 debugText_.append(e.text.text);
34 } else if (e.type == SDL_KEYDOWN) { 26 } else if (e.type == SDL_KEYDOWN) {
35 if (e.key.keysym.sym == SDLK_BACKQUOTE) { 27 if (e.key.keysym.sym == SDLK_ESCAPE) {
28 if (debugConsole_) {
29 debugConsole_ = false;
30 game_.unpauseGameplay();
31 SDL_StopTextInput();
32 debugText_.clear();
33 } else {
34 if (game_.getSystem<MenuSystem>().isMenuOpen()) {
35 game_.getSystem<MenuSystem>().closePauseMenu();
36 } else if (!game_.isGameplayPaused()) {
37 game_.getSystem<MenuSystem>().openPauseMenu();
38 }
39 }
40 } else if (e.key.keysym.sym == SDLK_BACKQUOTE) {
36#ifdef TANETANE_DEBUG 41#ifdef TANETANE_DEBUG
37 if (!debugConsole_) { 42 if (!debugConsole_ && !game_.isGameplayPaused()) {
38 debugConsole_ = true; 43 debugConsole_ = true;
39 game_.pauseGameplay(); 44 game_.pauseGameplay();
40 SDL_StartTextInput(); 45 SDL_StartTextInput();
diff --git a/src/menu_system.cpp b/src/menu_system.cpp index a5f3539..7c7d162 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp
@@ -1,2 +1,28 @@
1#include "menu_system.h" 1#include "menu_system.h"
2#include "game.h" 2#include "game.h"
3
4void MenuSystem::tick(double dt) {
5 pauseAnimation_.tick(dt);
6
7 if (openState_ == OpenState::Animating && pauseAnimation_.isComplete()) {
8 if (pauseAnimation_.getProgress() == 0.0) {
9 openState_ = OpenState::Closed;
10
11 game_.unpauseGameplay();
12 } else if (pauseAnimation_.getProgress() == 1.0) {
13 openState_ = OpenState::Open;
14 }
15 }
16}
17
18void MenuSystem::openPauseMenu() {
19 pauseAnimation_.start(125, 1.0);
20 openState_ = OpenState::Animating;
21
22 game_.pauseGameplay();
23}
24
25void MenuSystem::closePauseMenu() {
26 pauseAnimation_.start(125, 0.0);
27 openState_ = OpenState::Animating;
28}
diff --git a/src/menu_system.h b/src/menu_system.h index 46963b2..ded57b5 100644 --- a/src/menu_system.h +++ b/src/menu_system.h
@@ -2,6 +2,7 @@
2#define MENU_SYSTEM_H_205861EC 2#define MENU_SYSTEM_H_205861EC
3 3
4#include "system.h" 4#include "system.h"
5#include "interpolation.h"
5 6
6class Game; 7class Game;
7 8
@@ -12,9 +13,31 @@ public:
12 13
13 explicit MenuSystem(Game& game) : game_(game) {} 14 explicit MenuSystem(Game& game) : game_(game) {}
14 15
16 void tick(double dt) override;
17
18 // Commands
19
20 void openPauseMenu();
21
22 void closePauseMenu();
23
24 // Info
25
26 double getPauseAnimationProgress() const { return pauseAnimation_.getProgress(); }
27
28 bool isMenuOpen() const { return openState_ == OpenState::Open; }
29
15private: 30private:
16 31
32 enum class OpenState {
33 Closed,
34 Animating,
35 Open
36 };
37
17 Game& game_; 38 Game& game_;
39 Interpolation pauseAnimation_;
40 OpenState openState_ = OpenState::Closed;
18}; 41};
19 42
20#endif /* end of include guard: MENU_SYSTEM_H_205861EC */ 43#endif /* end of include guard: MENU_SYSTEM_H_205861EC */
diff --git a/src/renderer.cpp b/src/renderer.cpp index ea8a2ac..314dd4f 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -8,6 +8,7 @@
8#include "message_system.h" 8#include "message_system.h"
9#include "effect_system.h" 9#include "effect_system.h"
10#include "input_system.h" 10#include "input_system.h"
11#include "menu_system.h"
11 12
12Renderer::Renderer() { 13Renderer::Renderer() {
13 win_ = window_ptr( 14 win_ = window_ptr(
@@ -124,6 +125,7 @@ void Renderer::renderSprite(const Sprite& sprite) {
124 125
125void Renderer::render(Game& game) { 126void Renderer::render(Game& game) {
126 auto& effects = game.getSystem<EffectSystem>(); 127 auto& effects = game.getSystem<EffectSystem>();
128 auto& menus = game.getSystem<MenuSystem>();
127 129
128 if (cachedMapName_ != game.getMap().getName()) { 130 if (cachedMapName_ != game.getMap().getName()) {
129 cachedMapName_ = game.getMap().getName(); 131 cachedMapName_ = game.getMap().getName();
@@ -493,6 +495,24 @@ void Renderer::render(Game& game) {
493 } 495 }
494 } 496 }
495 497
498 if (menus.isMenuOpen()) {
499 SDL_SetRenderTarget(ren_.get(), cameraTex.get());
500 SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE);
501 SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255);
502 SDL_RenderFillRect(ren_.get(), nullptr);
503 } else if (menus.getPauseAnimationProgress() > 0.0) {
504 SDL_SetRenderTarget(ren_.get(), cameraTex.get());
505 SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE);
506 SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255);
507
508 int barHeight = CANVAS_HEIGHT / 2 * menus.getPauseAnimationProgress();
509 SDL_Rect topHalf { 0, 0, CANVAS_WIDTH, barHeight };
510 SDL_Rect bottomHalf { 0, CANVAS_HEIGHT - barHeight, CANVAS_WIDTH, barHeight };
511
512 SDL_RenderFillRect(ren_.get(), &topHalf);
513 SDL_RenderFillRect(ren_.get(), &bottomHalf);
514 }
515
496 SDL_SetRenderTarget(ren_.get(), nullptr); 516 SDL_SetRenderTarget(ren_.get(), nullptr);
497 SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); 517 SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr);
498 SDL_RenderPresent(ren_.get()); 518 SDL_RenderPresent(ren_.get());