Wire engine feature services into game skeleton
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#include "whitebox_scene.h"
|
||||
|
||||
#include "../core/game_audio.h"
|
||||
#include "../core/game_config.h"
|
||||
#include "../core/game_save.h"
|
||||
#include "../core/game_services.h"
|
||||
|
||||
#include <frostbite2D/core/application.h>
|
||||
#include <frostbite2D/event/key_event.h>
|
||||
#include <frostbite2D/graphics/camera.h>
|
||||
#include <frostbite2D/graphics/renderer.h>
|
||||
#include <frostbite2D/scene/scene_manager.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ns_game {
|
||||
@@ -13,6 +17,9 @@ namespace ns_game {
|
||||
void WhiteboxScene::onEnter() {
|
||||
frostbite2D::Scene::onEnter();
|
||||
level_ = CreateWhiteboxLevel();
|
||||
if (auto savedDebugFlags = GameSave::Get().LoadDebugFlags()) {
|
||||
debugFlags_ = *savedDebugFlags;
|
||||
}
|
||||
battleZoneStates_.clear();
|
||||
battleZoneStates_.resize(level_.battleZones.size());
|
||||
activeBattleZoneIndex_ = -1;
|
||||
@@ -22,6 +29,11 @@ void WhiteboxScene::onEnter() {
|
||||
player_->SetMovementWorld(&level_.collision);
|
||||
AddChild(player_);
|
||||
configureCamera();
|
||||
|
||||
uiOverlay_ = frostbite2D::MakePtr<GameUiOverlay>();
|
||||
frostbite2D::SceneManager::get().ReplaceUIScene(uiOverlay_);
|
||||
updateUiOverlay();
|
||||
GameAudio::Get().PlayMusicCue("stage_01");
|
||||
}
|
||||
|
||||
void WhiteboxScene::Update(float deltaTime) {
|
||||
@@ -29,6 +41,7 @@ void WhiteboxScene::Update(float deltaTime) {
|
||||
updateBattleZones();
|
||||
updateCameraBoundsBlend(deltaTime);
|
||||
updateCamera(deltaTime);
|
||||
updateUiOverlay();
|
||||
}
|
||||
|
||||
bool WhiteboxScene::OnEvent(const frostbite2D::Event& event) {
|
||||
@@ -107,15 +120,19 @@ bool WhiteboxScene::handleDebugKey(frostbite2D::KeyCode keyCode) {
|
||||
case frostbite2D::KeyCode::F3:
|
||||
debugFlags_.showCollision = !debugFlags_.showCollision;
|
||||
debugFlags_.showStageGrid = debugFlags_.showCollision;
|
||||
persistDebugFlags();
|
||||
return true;
|
||||
case frostbite2D::KeyCode::F4:
|
||||
debugFlags_.showActorBounds = !debugFlags_.showActorBounds;
|
||||
persistDebugFlags();
|
||||
return true;
|
||||
case frostbite2D::KeyCode::F5:
|
||||
debugFlags_.showBattleZones = !debugFlags_.showBattleZones;
|
||||
persistDebugFlags();
|
||||
return true;
|
||||
case frostbite2D::KeyCode::F6:
|
||||
debugFlags_.showSpawnPoints = !debugFlags_.showSpawnPoints;
|
||||
persistDebugFlags();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -124,6 +141,7 @@ bool WhiteboxScene::handleDebugKey(frostbite2D::KeyCode keyCode) {
|
||||
|
||||
void WhiteboxScene::toggleDebugOverlay() {
|
||||
debugFlags_.enabled = !debugFlags_.enabled;
|
||||
persistDebugFlags();
|
||||
}
|
||||
|
||||
void WhiteboxScene::beginCameraBoundsBlend(
|
||||
@@ -197,6 +215,7 @@ void WhiteboxScene::updateBattleZones() {
|
||||
runtime.triggered = true;
|
||||
activeBattleZoneIndex_ = static_cast<int>(i);
|
||||
beginCameraBoundsBlend(level_.battleZones[i].cameraBounds);
|
||||
GameAudio::Get().PlaySoundCue("battle_zone_enter");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -214,4 +233,20 @@ void WhiteboxScene::updateCamera(float deltaTime) {
|
||||
cameraController_.Update(*camera, player_->GetWorldBounds(), deltaTime);
|
||||
}
|
||||
|
||||
void WhiteboxScene::updateUiOverlay() {
|
||||
if (!uiOverlay_) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameUiOverlayState state;
|
||||
state.debugFlags = debugFlags_;
|
||||
state.services = GameServices::Get().Status();
|
||||
state.activeBattleZoneIndex = activeBattleZoneIndex_;
|
||||
uiOverlay_->SetState(state);
|
||||
}
|
||||
|
||||
void WhiteboxScene::persistDebugFlags() {
|
||||
GameSave::Get().SaveDebugFlags(debugFlags_);
|
||||
}
|
||||
|
||||
} // namespace ns_game
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../core/debug_flags.h"
|
||||
#include "../data/level_definition.h"
|
||||
#include "../debug/debug_overlay.h"
|
||||
#include "../ui/game_ui_overlay.h"
|
||||
#include "camera_controller.h"
|
||||
#include "../stage/stage_renderer.h"
|
||||
|
||||
@@ -37,6 +38,8 @@ private:
|
||||
void updateCameraBoundsBlend(float deltaTime);
|
||||
void updateBattleZones();
|
||||
void updateCamera(float deltaTime);
|
||||
void updateUiOverlay();
|
||||
void persistDebugFlags();
|
||||
|
||||
LevelDefinition level_;
|
||||
DebugFlags debugFlags_;
|
||||
@@ -51,6 +54,7 @@ private:
|
||||
CameraController cameraController_;
|
||||
StageRenderer stageRenderer_;
|
||||
DebugOverlay debugOverlay_;
|
||||
frostbite2D::Ptr<GameUiOverlay> uiOverlay_;
|
||||
frostbite2D::Ptr<PlayerActor> player_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user