2026-02-13 13:56:18 +08:00
|
|
|
// ============================================================================
|
|
|
|
|
// SuccessScene.cpp - Push Box 通关场景实现
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-11 19:40:26 +08:00
|
|
|
#include "SuccessScene.h"
|
|
|
|
|
|
2026-02-25 06:23:53 +08:00
|
|
|
#include <extra2d.h>
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
namespace pushbox {
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
SuccessScene::SuccessScene() : BaseScene() {
|
|
|
|
|
// BaseScene 已处理视口设置
|
2026-02-11 19:40:26 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 加载菜单字体
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
static extra2d::Ptr<extra2d::FontAtlas> loadMenuFont() {
|
|
|
|
|
auto& resources = extra2d::Application::instance().resources();
|
|
|
|
|
auto font = resources.loadFont("assets/font.ttf", 28);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SuccessScene::onEnter() {
|
2026-02-13 13:56:18 +08:00
|
|
|
BaseScene::onEnter();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
auto& app = extra2d::Application::instance();
|
|
|
|
|
auto& resources = app.resources();
|
|
|
|
|
|
2026-02-26 00:38:31 +08:00
|
|
|
if (children().empty()) {
|
2026-02-13 13:56:18 +08:00
|
|
|
// 使用游戏逻辑分辨率
|
|
|
|
|
float screenW = GAME_WIDTH;
|
|
|
|
|
float screenH = GAME_HEIGHT;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
auto bgTex = resources.loadTexture("assets/images/success.jpg");
|
|
|
|
|
if (bgTex) {
|
|
|
|
|
auto background = extra2d::Sprite::create(bgTex);
|
|
|
|
|
float bgWidth = static_cast<float>(bgTex->getWidth());
|
|
|
|
|
float bgHeight = static_cast<float>(bgTex->getHeight());
|
|
|
|
|
float offsetX = (screenW - bgWidth) / 2.0f;
|
|
|
|
|
float offsetY = (screenH - bgHeight) / 2.0f;
|
|
|
|
|
|
|
|
|
|
background->setAnchor(0.0f, 0.0f);
|
|
|
|
|
background->setPosition(offsetX, offsetY);
|
|
|
|
|
addChild(background);
|
|
|
|
|
|
|
|
|
|
float centerX = screenW / 2.0f;
|
|
|
|
|
|
|
|
|
|
auto font = loadMenuFont();
|
|
|
|
|
if (font) {
|
|
|
|
|
// 创建按钮文本(仅显示,不响应鼠标)
|
|
|
|
|
auto backText = extra2d::Text::create("回主菜单", font);
|
|
|
|
|
backText->setPosition(centerX, offsetY + 350.0f);
|
|
|
|
|
backText->setTextColor(extra2d::Colors::Black);
|
|
|
|
|
addChild(backText);
|
|
|
|
|
|
|
|
|
|
// 创建选择指示器(箭头)
|
|
|
|
|
selectorText_ = extra2d::Text::create(">", font);
|
|
|
|
|
selectorText_->setTextColor(extra2d::Colors::Red);
|
|
|
|
|
selectorText_->setPosition(centerX - 80.0f, offsetY + 350.0f);
|
|
|
|
|
addChild(selectorText_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SuccessScene::onUpdate(float dt) {
|
2026-02-13 13:56:18 +08:00
|
|
|
BaseScene::onUpdate(dt);
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
auto& app = extra2d::Application::instance();
|
|
|
|
|
auto& input = app.input();
|
|
|
|
|
|
|
|
|
|
// A键确认返回主菜单
|
|
|
|
|
if (input.isButtonPressed(extra2d::GamepadButton::A)) {
|
|
|
|
|
auto& scenes = extra2d::Application::instance().scenes();
|
2026-02-13 13:56:18 +08:00
|
|
|
scenes.popScene(extra2d::TransitionType::Fade, 0.5f);
|
|
|
|
|
scenes.popScene(extra2d::TransitionType::Fade, 0.5f);
|
2026-02-11 19:40:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace pushbox
|