diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-10 12:11:27 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-10 12:11:27 -0500 |
commit | 31dc0e443efc0aae48e11a0d98e699dbed5c7dcf (patch) | |
tree | 17e044698531fc1af82dddcbd144ae93d3ae0252 /src | |
parent | fb58cb31804da7e5e40fc861927060a183962441 (diff) | |
download | tanetane-31dc0e443efc0aae48e11a0d98e699dbed5c7dcf.tar.gz tanetane-31dc0e443efc0aae48e11a0d98e699dbed5c7dcf.tar.bz2 tanetane-31dc0e443efc0aae48e11a0d98e699dbed5c7dcf.zip |
Added fade out around map change
Also moved script system first in the loop so that the camera can catch up before rendering. Also added a map change from map 2 back to map 1.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.h | 5 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/renderer.cpp | 6 | ||||
-rw-r--r-- | src/script_system.cpp | 10 |
4 files changed, 20 insertions, 3 deletions
diff --git a/src/game.h b/src/game.h index 8ea7576..bb88dec 100644 --- a/src/game.h +++ b/src/game.h | |||
@@ -79,6 +79,10 @@ public: | |||
79 | 79 | ||
80 | const Font& getFont() const { return font_; } | 80 | const Font& getFont() const { return font_; } |
81 | 81 | ||
82 | double getFadeoutProgress() const { return fadeout_; } | ||
83 | |||
84 | void setFadeoutProgress(double val) { fadeout_ = val; } | ||
85 | |||
82 | private: | 86 | private: |
83 | 87 | ||
84 | void clearSprites(); | 88 | void clearSprites(); |
@@ -94,6 +98,7 @@ private: | |||
94 | std::map<std::string, int> spritesByAlias_; | 98 | std::map<std::string, int> spritesByAlias_; |
95 | std::unique_ptr<Map> map_; | 99 | std::unique_ptr<Map> map_; |
96 | Font font_; | 100 | Font font_; |
101 | double fadeout_ = 0.0; | ||
97 | }; | 102 | }; |
98 | 103 | ||
99 | #endif /* end of include guard: GAME_H_E6F1396E */ | 104 | #endif /* end of include guard: GAME_H_E6F1396E */ |
diff --git a/src/main.cpp b/src/main.cpp index 5f28408..8487077 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -14,13 +14,13 @@ | |||
14 | 14 | ||
15 | void loop(Renderer& renderer) { | 15 | void loop(Renderer& renderer) { |
16 | Game game(renderer); | 16 | Game game(renderer); |
17 | game.emplaceSystem<ScriptSystem>(); | ||
17 | game.emplaceSystem<TransformSystem>(); | 18 | game.emplaceSystem<TransformSystem>(); |
18 | game.emplaceSystem<InputSystem>(); | 19 | game.emplaceSystem<InputSystem>(); |
19 | game.emplaceSystem<CharacterSystem>(); | 20 | game.emplaceSystem<CharacterSystem>(); |
20 | game.emplaceSystem<AnimationSystem>(); | 21 | game.emplaceSystem<AnimationSystem>(); |
21 | game.emplaceSystem<CameraSystem>(); | 22 | game.emplaceSystem<CameraSystem>(); |
22 | game.emplaceSystem<MessageSystem>(); | 23 | game.emplaceSystem<MessageSystem>(); |
23 | game.emplaceSystem<ScriptSystem>(); | ||
24 | 24 | ||
25 | game.loadMap("../res/maps/map1.tmx", "spawn"); | 25 | game.loadMap("../res/maps/map1.tmx", "spawn"); |
26 | 26 | ||
diff --git a/src/renderer.cpp b/src/renderer.cpp index e9db413..db5daed 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -234,6 +234,12 @@ void Renderer::render(Game& game) { | |||
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | if (game.getFadeoutProgress() > 0.0) { | ||
238 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); | ||
239 | SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, game.getFadeoutProgress() * 255); | ||
240 | SDL_RenderFillRect(ren_.get(), nullptr); | ||
241 | } | ||
242 | |||
237 | SDL_SetRenderTarget(ren_.get(), nullptr); | 243 | SDL_SetRenderTarget(ren_.get(), nullptr); |
238 | SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); | 244 | SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); |
239 | SDL_RenderPresent(ren_.get()); | 245 | SDL_RenderPresent(ren_.get()); |
diff --git a/src/script_system.cpp b/src/script_system.cpp index 6e38905..a5e9403 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
@@ -56,6 +56,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
56 | game_.loadMap(filename, warpPoint); | 56 | game_.loadMap(filename, warpPoint); |
57 | }); | 57 | }); |
58 | 58 | ||
59 | engine_.set_function( | ||
60 | "setFadeoutProgress", | ||
61 | [&] (double val) { | ||
62 | game_.setFadeoutProgress(val); | ||
63 | }); | ||
64 | |||
59 | engine_.script_file("../res/scripts/common.lua"); | 65 | engine_.script_file("../res/scripts/common.lua"); |
60 | } | 66 | } |
61 | 67 | ||
@@ -64,7 +70,7 @@ void ScriptSystem::tick(double dt) { | |||
64 | auto result = (*callable_)(dt); | 70 | auto result = (*callable_)(dt); |
65 | if (!result.valid()) { | 71 | if (!result.valid()) { |
66 | sol::error e = result; | 72 | sol::error e = result; |
67 | throw std::runtime_error(e.what()); | 73 | throw e; |
68 | } | 74 | } |
69 | 75 | ||
70 | if (!*callable_) { | 76 | if (!*callable_) { |
@@ -90,7 +96,7 @@ void ScriptSystem::runScript(std::string name) { | |||
90 | auto result = (*callable_)(); | 96 | auto result = (*callable_)(); |
91 | if (!result.valid()) { | 97 | if (!result.valid()) { |
92 | sol::error e = result; | 98 | sol::error e = result; |
93 | throw std::runtime_error(e.what()); | 99 | throw e; |
94 | } | 100 | } |
95 | 101 | ||
96 | if (!*callable_) { | 102 | if (!*callable_) { |