2026-02-13 13:56:18 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// PlayScene.h - Push Box 游戏场景
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
2026-02-11 19:40:26 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
|
#include "BaseScene.h"
|
2026-02-11 19:40:26 +08:00
|
|
|
|
#include "data.h"
|
|
|
|
|
|
#include <extra2d/extra2d.h>
|
2026-02-13 17:34:46 +08:00
|
|
|
|
#include <extra2d/utils/object_pool.h>
|
|
|
|
|
|
#include <stack>
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace pushbox {
|
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Push Box 游戏场景
|
|
|
|
|
|
*/
|
|
|
|
|
|
class PlayScene : public BaseScene {
|
2026-02-11 19:40:26 +08:00
|
|
|
|
public:
|
2026-02-13 13:56:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 构造函数
|
|
|
|
|
|
* @param level 关卡编号
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
explicit PlayScene(int level);
|
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 场景进入时调用
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void onEnter() override;
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 每帧更新
|
|
|
|
|
|
* @param dt 帧间隔时间
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void onUpdate(float dt) override;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2026-02-13 13:56:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 更新菜单颜色
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void updateMenuColors();
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 执行选中的菜单项
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void executeMenuItem();
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 刷新地图显示
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void flush();
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 设置关卡
|
|
|
|
|
|
* @param level 关卡编号
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void setLevel(int level);
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 设置步数
|
|
|
|
|
|
* @param step 步数
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void setStep(int step);
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 移动玩家
|
|
|
|
|
|
* @param dx X方向偏移
|
|
|
|
|
|
* @param dy Y方向偏移
|
|
|
|
|
|
* @param direct 方向(1=上,2=下,3=左,4=右)
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void move(int dx, int dy, int direct);
|
2026-02-13 13:56:18 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 游戏通关
|
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
|
void gameOver();
|
2026-02-13 17:34:46 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 撤销上一步移动(对象池使用示例)
|
|
|
|
|
|
*/
|
|
|
|
|
|
void undoMove();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
|
|
int step_ = 0;
|
|
|
|
|
|
int menuIndex_ = 0;
|
|
|
|
|
|
Map map_{};
|
|
|
|
|
|
|
|
|
|
|
|
extra2d::Ptr<extra2d::FontAtlas> font28_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::FontAtlas> font20_;
|
|
|
|
|
|
|
|
|
|
|
|
extra2d::Ptr<extra2d::Text> levelText_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Text> stepText_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Text> bestText_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Text> restartText_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Text> soundToggleText_;
|
2026-02-13 17:34:46 +08:00
|
|
|
|
extra2d::Ptr<extra2d::Text> undoText_;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
extra2d::Ptr<extra2d::Node> mapLayer_;
|
|
|
|
|
|
|
2026-02-13 13:56:18 +08:00
|
|
|
|
extra2d::Ptr<extra2d::Button> soundBtn_;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texWall_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texPoint_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texFloor_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texBox_;
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texBoxInPoint_;
|
|
|
|
|
|
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texMan_[5];
|
|
|
|
|
|
extra2d::Ptr<extra2d::Texture> texManPush_[5];
|
2026-02-13 17:34:46 +08:00
|
|
|
|
|
|
|
|
|
|
// 对象池使用示例:使用智能指针管理 MoveRecord
|
|
|
|
|
|
std::stack<extra2d::Ptr<MoveRecord>> moveHistory_;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace pushbox
|