From 31dc0e443efc0aae48e11a0d98e699dbed5c7dcf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 12:11:27 -0500 Subject: 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. --- src/game.h | 5 +++++ src/main.cpp | 2 +- src/renderer.cpp | 6 ++++++ src/script_system.cpp | 10 ++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src') 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: const Font& getFont() const { return font_; } + double getFadeoutProgress() const { return fadeout_; } + + void setFadeoutProgress(double val) { fadeout_ = val; } + private: void clearSprites(); @@ -94,6 +98,7 @@ private: std::map spritesByAlias_; std::unique_ptr map_; Font font_; + double fadeout_ = 0.0; }; #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 @@ void loop(Renderer& renderer) { Game game(renderer); + game.emplaceSystem(); game.emplaceSystem(); game.emplaceSystem(); game.emplaceSystem(); game.emplaceSystem(); game.emplaceSystem(); game.emplaceSystem(); - game.emplaceSystem(); game.loadMap("../res/maps/map1.tmx", "spawn"); 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) { } } + if (game.getFadeoutProgress() > 0.0) { + SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, game.getFadeoutProgress() * 255); + SDL_RenderFillRect(ren_.get(), nullptr); + } + SDL_SetRenderTarget(ren_.get(), nullptr); SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); 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) { game_.loadMap(filename, warpPoint); }); + engine_.set_function( + "setFadeoutProgress", + [&] (double val) { + game_.setFadeoutProgress(val); + }); + engine_.script_file("../res/scripts/common.lua"); } @@ -64,7 +70,7 @@ void ScriptSystem::tick(double dt) { auto result = (*callable_)(dt); if (!result.valid()) { sol::error e = result; - throw std::runtime_error(e.what()); + throw e; } if (!*callable_) { @@ -90,7 +96,7 @@ void ScriptSystem::runScript(std::string name) { auto result = (*callable_)(); if (!result.valid()) { sol::error e = result; - throw std::runtime_error(e.what()); + throw e; } if (!*callable_) { -- cgit 1.4.1