Build first scene skeleton
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "../core/game_config.h"
|
||||
|
||||
#include <frostbite2D/core/application.h>
|
||||
#include <frostbite2D/event/key_event.h>
|
||||
#include <frostbite2D/graphics/camera.h>
|
||||
#include <frostbite2D/graphics/renderer.h>
|
||||
#include <algorithm>
|
||||
@@ -14,6 +15,7 @@ void WhiteboxScene::onEnter() {
|
||||
level_ = CreateWhiteboxLevel();
|
||||
|
||||
player_ = frostbite2D::MakePtr<PlayerActor>();
|
||||
player_->SetTopLeftPosition(level_.playerSpawn);
|
||||
player_->SetMovementWorld(&level_.collision);
|
||||
AddChild(player_);
|
||||
}
|
||||
@@ -23,6 +25,19 @@ void WhiteboxScene::OnUpdate(float deltaTime) {
|
||||
updateCamera();
|
||||
}
|
||||
|
||||
bool WhiteboxScene::OnEvent(const frostbite2D::Event& event) {
|
||||
if (event.getType() == frostbite2D::EventType::KeyDown) {
|
||||
const auto& keyEvent = static_cast<const frostbite2D::KeyEvent&>(event);
|
||||
if (!keyEvent.isRepeat() &&
|
||||
keyEvent.getKeyCode() == frostbite2D::KeyCode::F1) {
|
||||
toggleDebugOverlay();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return frostbite2D::Scene::OnEvent(event);
|
||||
}
|
||||
|
||||
void WhiteboxScene::Render() {
|
||||
stageRenderer_.Render(level_, debugFlags_);
|
||||
frostbite2D::Scene::Render();
|
||||
@@ -31,6 +46,18 @@ void WhiteboxScene::Render() {
|
||||
debugOverlay_.Render(level_, debugFlags_, player_ ? &playerBounds : nullptr);
|
||||
}
|
||||
|
||||
void WhiteboxScene::toggleDebugOverlay() {
|
||||
const bool enabled = !(debugFlags_.showStageGrid || debugFlags_.showCollision ||
|
||||
debugFlags_.showActorBounds ||
|
||||
debugFlags_.showBattleZones ||
|
||||
debugFlags_.showSpawnPoints);
|
||||
debugFlags_.showStageGrid = enabled;
|
||||
debugFlags_.showCollision = enabled;
|
||||
debugFlags_.showActorBounds = enabled;
|
||||
debugFlags_.showBattleZones = enabled;
|
||||
debugFlags_.showSpawnPoints = enabled;
|
||||
}
|
||||
|
||||
void WhiteboxScene::updateCamera() {
|
||||
if (!player_) {
|
||||
return;
|
||||
@@ -43,8 +70,8 @@ void WhiteboxScene::updateCamera() {
|
||||
|
||||
const auto playerPos = player_->GetTopLeftPosition();
|
||||
const float targetX = std::clamp(playerPos.x - 420.0f,
|
||||
level_.collision.levelLeft,
|
||||
level_.collision.levelRight -
|
||||
level_.cameraBounds.left(),
|
||||
level_.cameraBounds.right() -
|
||||
static_cast<float>(config::kVirtualWidth));
|
||||
renderer->getCamera()->setPosition(frostbite2D::Vec2(targetX, 0.0f));
|
||||
}
|
||||
|
||||
@@ -15,9 +15,11 @@ class WhiteboxScene : public frostbite2D::Scene {
|
||||
public:
|
||||
void onEnter() override;
|
||||
void OnUpdate(float deltaTime) override;
|
||||
bool OnEvent(const frostbite2D::Event& event) override;
|
||||
void Render() override;
|
||||
|
||||
private:
|
||||
void toggleDebugOverlay();
|
||||
void updateCamera();
|
||||
|
||||
LevelDefinition level_;
|
||||
|
||||
Reference in New Issue
Block a user