-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SplashScene and transition effect
- Loading branch information
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <bn_color.h> | ||
|
||
namespace sym::constants | ||
{ | ||
constexpr const bn::color TRANSPARENT_BG_COLOR(4, 4, 6); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <bn_optional.h> | ||
|
||
namespace sym | ||
{ | ||
|
||
enum class SceneType | ||
{ | ||
SPLASH, | ||
TITLE, | ||
GAME, | ||
LICENSE | ||
}; | ||
|
||
class Scene | ||
{ | ||
public: | ||
virtual ~Scene() = default; | ||
[[nodiscard]] virtual bn::optional<SceneType> Update() = 0; | ||
|
||
protected: | ||
Scene() = default; | ||
}; | ||
|
||
} // namespace sym |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include "Scene.h" | ||
|
||
#include <bn_array.h> | ||
#include <bn_blending_actions.h> | ||
#include <bn_regular_bg_ptr.h> | ||
|
||
namespace sym | ||
{ | ||
|
||
class SplashScene : public Scene | ||
{ | ||
public: | ||
SplashScene(); | ||
~SplashScene() = default; | ||
[[nodiscard]] bn::optional<SceneType> Update() final; | ||
|
||
private: | ||
void SwapBgWhenNeeded(); | ||
void SwapBg(); | ||
/** | ||
* @brief Update the alpha transition action | ||
* | ||
* @return bn::optional<SceneType> Next scene type when transition is done, otherwise bn::nullopt | ||
*/ | ||
[[nodiscard]] bn::optional<SceneType> Transition(); | ||
|
||
static constexpr int BG_SWAP_UPDATE_COUNT = 30; | ||
static constexpr int BG_SWAP_COUNT = 8; | ||
static constexpr int FADE_UPDATE_COUNT = 60; | ||
|
||
bn::array<bn::regular_bg_ptr, 2> bgs_; | ||
int bgSwapCounter_ = BG_SWAP_COUNT; | ||
int bgSwapUpdateCounter_ = BG_SWAP_UPDATE_COUNT; | ||
bool isShowingFirstBg_ = false; | ||
bool isFadeDone_ = false; | ||
bn::optional<bn::blending_transparency_alpha_to_action> transparentAction_; | ||
}; | ||
|
||
} // namespace sym |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "SplashScene.h" | ||
|
||
#include <bn_blending_actions.h> | ||
#include <bn_fixed.h> | ||
#include <bn_keypad.h> | ||
#include <bn_optional.h> | ||
|
||
#include "bn_regular_bg_items_bg_splash1.h" | ||
#include "bn_regular_bg_items_bg_splash2.h" | ||
|
||
namespace sym | ||
{ | ||
|
||
SplashScene::SplashScene() | ||
: bgs_{bn::regular_bg_items::bg_splash1.create_bg(0, 0), bn::regular_bg_items::bg_splash2.create_bg(0, 0)} | ||
{ | ||
bgs_[0].set_visible(isShowingFirstBg_); | ||
for (auto& bg : bgs_) | ||
bg.set_blending_enabled(true); | ||
} | ||
|
||
bn::optional<SceneType> SplashScene::Update() | ||
{ | ||
SwapBgWhenNeeded(); | ||
|
||
if (bn::keypad::a_pressed()) | ||
{ | ||
bgSwapCounter_ = 0; | ||
} | ||
|
||
if (0 >= bgSwapCounter_) | ||
{ | ||
return Transition(); | ||
} | ||
|
||
return bn::nullopt; | ||
} | ||
|
||
void SplashScene::SwapBgWhenNeeded() | ||
{ | ||
if (0 >= bgSwapUpdateCounter_--) | ||
{ | ||
bgSwapUpdateCounter_ = BG_SWAP_UPDATE_COUNT; | ||
--bgSwapCounter_; | ||
SwapBg(); | ||
} | ||
} | ||
|
||
void SplashScene::SwapBg() | ||
{ | ||
isShowingFirstBg_ = !isShowingFirstBg_; | ||
bgs_[0].set_visible(isShowingFirstBg_); | ||
bgs_[1].set_visible(!isShowingFirstBg_); | ||
} | ||
|
||
bn::optional<SceneType> SplashScene::Transition() | ||
{ | ||
if (!transparentAction_) | ||
{ | ||
transparentAction_ = bn::blending_transparency_alpha_to_action(FADE_UPDATE_COUNT, 0); | ||
} | ||
|
||
if (transparentAction_->done()) | ||
{ | ||
return SceneType::TITLE; | ||
} | ||
|
||
transparentAction_->update(); | ||
return bn::nullopt; | ||
} | ||
|
||
} // namespace sym |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
#include <bn_bg_palettes.h> | ||
#include <bn_color.h> | ||
#include <bn_core.h> | ||
#include <bn_memory.h> | ||
|
||
#include "Constants.h" | ||
#include "SplashScene.h" | ||
#include "bn_assert.h" | ||
|
||
int main() | ||
{ | ||
bn::core::init(); | ||
|
||
bn::bg_palettes::set_transparent_color(sym::constants::TRANSPARENT_BG_COLOR); | ||
bn::unique_ptr<sym::Scene> scene(new sym::SplashScene); | ||
bn::optional<sym::SceneType> nextScene; | ||
|
||
while (true) | ||
{ | ||
if (scene) | ||
{ | ||
nextScene = scene->Update(); | ||
} | ||
|
||
bn::core::update(); | ||
|
||
if (nextScene) | ||
{ | ||
switch (*nextScene) | ||
{ | ||
case sym::SceneType::SPLASH: | ||
scene.reset(new sym::SplashScene); | ||
break; | ||
case sym::SceneType::TITLE: | ||
// TODO: scene.reset(new sym::TitleScene); | ||
break; | ||
// case sym::SceneType::GAME: | ||
// break; | ||
// case sym::SceneType::LICENSE: | ||
// break; | ||
default: | ||
BN_ERROR("Unknown SceneType: ", (int)*nextScene); | ||
} | ||
} | ||
} | ||
} |