Skip to content

Commit

Permalink
battle transition
Browse files Browse the repository at this point in the history
  • Loading branch information
kjblanchard committed Nov 9, 2024
1 parent 8fee773 commit e73afdf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct GameState {
int WindowWidth;
bool Loading;
bool CameraFollowTarget;
bool EnteringBattle;
// Level* CurrentLevel;
};
} // namespace Supergoon
1 change: 1 addition & 0 deletions src/engine/include/Supergoon/World/Level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Level {
void LoadAllGameObjects();
void RestartLevel();
void CreateBackgroundImage();
static void SetBackGroundColor(Color color = Color{255, 255, 255, 255});
template <typename T>
static T *GetCurrentLevelProperty(std::string key);

Expand Down
3 changes: 3 additions & 0 deletions src/engine/src/World/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,6 @@ void Level::Draw() {
}
}

void Level::SetBackGroundColor(Color color) {
_currentLevel->_background->SetImageColor(color);
}
12 changes: 12 additions & 0 deletions src/game/Systems/CameraSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void getFollowTarget(CameraComponent& cc) {
cc.FollowTarget = &lc;
});
}
float colorFade = 255;
static Tween* tweener = new Tween(255, 0, 1.0, &colorFade, Supergoon::Easings::Linear);

void UpdateCamera() {
auto c = GameObject::GetGameObjectWithComponents<CameraComponent>();
Expand All @@ -20,6 +22,16 @@ void UpdateCamera() {
}
auto& cc = c->GetComponent<CameraComponent>();
auto& gc = g->GetComponent<GameState>();
if (gc.EnteringBattle) {
// We should instead slowly decrement camera x
tweener->Update();
cc.Box.X -= 5;

auto color = Color{255, (uint8_t)colorFade, (uint8_t)colorFade, (uint8_t)colorFade};
Level::SetBackGroundColor(color);
Events::PushEvent(Events::BuiltinEvents.CameraUpdate, true, (void*)&cc.Box);
return;
}
if (!gc.CameraFollowTarget) {
return;
}
Expand Down
11 changes: 10 additions & 1 deletion src/game/Systems/PlayerSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void playerInput(GameObject go, PlayerComponent& player) {
auto state = GameObject::GetGameObjectWithComponents<GameState>();
auto& stateComponent = state->GetComponent<GameState>();
assert(state.has_value());
if (stateComponent.Loading) {
if (stateComponent.Loading || stateComponent.EnteringBattle) {
return;
}
auto vel = Vector2();
Expand Down Expand Up @@ -63,6 +63,15 @@ static void playerInput(GameObject go, PlayerComponent& player) {
moved = true;
newDirection = Directions::West;
}
if (KeyDown(KeyboardKeys::Key_B)) {
// Start battle transition.
stateComponent.CameraFollowTarget = false;
stateComponent.EnteringBattle = true;
Events::PushEvent(Events::BuiltinEvents.PlayBgmEvent, 0, (void*)strdup("battle1"));
anim.Playing = false;
return;
// Camera component handles the sliding.
}
auto deltatime = (float)Game::DeltaTime();
vel *= Vector2{deltatime, deltatime};
// Handle Collisions
Expand Down

0 comments on commit e73afdf

Please sign in to comment.