summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 09:29:47 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 15:34:50 -0500
commitf839e07d4d2e94070129129c669072145235cf4f (patch)
tree3b1cd73c00d1ea968646dd649199d54a25964d8e /src
parent42495836c9ebe1c3914540043d2338eebd85dbab (diff)
downloadtanetane-f839e07d4d2e94070129129c669072145235cf4f.tar.gz
tanetane-f839e07d4d2e94070129129c669072145235cf4f.tar.bz2
tanetane-f839e07d4d2e94070129129c669072145235cf4f.zip
Added cursor to pause menu
#7
Diffstat (limited to 'src')
-rw-r--r--src/menu_system.cpp17
-rw-r--r--src/menu_system.h9
-rw-r--r--src/renderer.cpp12
3 files changed, 38 insertions, 0 deletions
diff --git a/src/menu_system.cpp b/src/menu_system.cpp index 00c4849..acbfd76 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp
@@ -12,6 +12,23 @@ void MenuSystem::tick(double dt) {
12 } else if (pauseAnimation_.getProgress() == 1.0) { 12 } else if (pauseAnimation_.getProgress() == 1.0) {
13 openState_ = OpenState::Open; 13 openState_ = OpenState::Open;
14 } 14 }
15 } else if (openState_ == OpenState::Open) {
16 cursorBobTimer_.accumulate(dt);
17 while (cursorBobTimer_.step()) {
18 if (cursorBobDown_) {
19 cursorBob_++;
20
21 if (cursorBob_ >= 4) {
22 cursorBobDown_ = false;
23 }
24 } else {
25 cursorBob_--;
26
27 if (cursorBob_ <= 0) {
28 cursorBobDown_ = true;
29 }
30 }
31 }
15 } 32 }
16} 33}
17 34
diff --git a/src/menu_system.h b/src/menu_system.h index 56f84d5..9cbd1f0 100644 --- a/src/menu_system.h +++ b/src/menu_system.h
@@ -5,6 +5,7 @@
5#include "interpolation.h" 5#include "interpolation.h"
6#include "menu.h" 6#include "menu.h"
7#include "system.h" 7#include "system.h"
8#include "timer.h"
8 9
9class Game; 10class Game;
10 11
@@ -31,6 +32,10 @@ public:
31 32
32 const std::vector<MenuItem>& getMenu() const { return menu_; } 33 const std::vector<MenuItem>& getMenu() const { return menu_; }
33 34
35 int getCursorPosition() const { return cursor_; }
36
37 int getCursorBob() const { return cursorBob_; }
38
34private: 39private:
35 40
36 enum class OpenState { 41 enum class OpenState {
@@ -43,6 +48,10 @@ private:
43 Interpolation pauseAnimation_; 48 Interpolation pauseAnimation_;
44 OpenState openState_ = OpenState::Closed; 49 OpenState openState_ = OpenState::Closed;
45 std::vector<MenuItem> menu_; 50 std::vector<MenuItem> menu_;
51 int cursor_ = 0;
52 int cursorBob_ = 0;
53 bool cursorBobDown_ = true;
54 Timer cursorBobTimer_ { 125 };
46}; 55};
47 56
48#endif /* end of include guard: MENU_SYSTEM_H_205861EC */ 57#endif /* end of include guard: MENU_SYSTEM_H_205861EC */
diff --git a/src/renderer.cpp b/src/renderer.cpp index 14eefea..fc16e20 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -559,6 +559,7 @@ void Renderer::renderMenu(Game& game) {
559 559
560 const int lineHeight = 16; 560 const int lineHeight = 16;
561 int totalHeight = menus.getMenu().size() * lineHeight; 561 int totalHeight = menus.getMenu().size() * lineHeight;
562 std::vector<vec2i> positions;
562 563
563 int index = 0; 564 int index = 0;
564 for (const MenuItem& menuItem : menus.getMenu()) { 565 for (const MenuItem& menuItem : menus.getMenu()) {
@@ -577,11 +578,22 @@ void Renderer::renderMenu(Game& game) {
577 SDL_SetRenderTarget(ren_.get(), menuTex_.get()); 578 SDL_SetRenderTarget(ren_.get(), menuTex_.get());
578 SDL_RenderCopy(ren_.get(), output.renderedTex.get(), nullptr, &dest); 579 SDL_RenderCopy(ren_.get(), output.renderedTex.get(), nullptr, &dest);
579 580
581 positions.emplace_back(dest.x, dest.y);
582
580 break; 583 break;
581 } 584 }
582 } 585 }
586
583 index++; 587 index++;
584 } 588 }
589
590 int cursorTexId = loadImageFromFile("../res/feather_pen.png");
591 const SDL_Rect cursorDest {
592 positions[menus.getCursorPosition()].x() - 2 - 16 - menus.getCursorBob(),
593 positions[menus.getCursorPosition()].y() - 8 - menus.getCursorBob(),
594 16,
595 16 };
596 SDL_RenderCopy(ren_.get(), textures_.at(cursorTexId).get(), nullptr, &cursorDest);
585} 597}
586 598
587int Renderer::loadImageFromFile(std::string filename) { 599int Renderer::loadImageFromFile(std::string filename) {