feat: 添加游戏核心模块,包括地图、角色、场景和世界管理
实现游戏基础架构,包含以下主要功能: - 地图系统:支持地图加载、图层管理和相机控制 - 角色系统:实现角色装备、动画和行为管理 - 场景系统:提供测试场景和世界场景切换 - 世界管理:处理城镇和区域切换逻辑 - 数据加载:添加角色和装备配置加载器 这些改动为游戏开发奠定了基础框架,支持后续功能扩展
This commit is contained in:
129
Game/src/bootstrap/main.cpp
Normal file
129
Game/src/bootstrap/main.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "SDL_log.h"
|
||||
#include "frostbite2D/2d/sprite.h"
|
||||
#include "frostbite2D/base/RefPtr.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <frostbite2D/2d/text_sprite.h>
|
||||
#include <frostbite2D/audio/audio_system.h>
|
||||
#include <frostbite2D/core/application.h>
|
||||
#include <frostbite2D/core/task_system.h>
|
||||
#include <frostbite2D/graphics/font_manager.h>
|
||||
#include <frostbite2D/resource/asset.h>
|
||||
#include <frostbite2D/resource/audio_database.h>
|
||||
#include <frostbite2D/resource/npk_archive.h>
|
||||
#include <frostbite2D/resource/pvf_archive.h>
|
||||
#include <frostbite2D/resource/sound_pack_archive.h>
|
||||
#include <frostbite2D/scene/scene.h>
|
||||
#include <frostbite2D/scene/scene_manager.h>
|
||||
#include "scene/GameMapTestScene.h"
|
||||
#include "world/GameWorld.h"
|
||||
|
||||
using namespace frostbite2D;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
AppConfig config = AppConfig::createDefault();
|
||||
config.appName = "Frostbite2D Test App";
|
||||
config.appVersion = "1.0.0";
|
||||
config.windowConfig.width = 1280;
|
||||
config.windowConfig.height = 720;
|
||||
config.windowConfig.title = "Frostbite2D - Async Init Demo";
|
||||
|
||||
Application &app = Application::get();
|
||||
if (!app.init(config)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to initialize application!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
app.run([]() {
|
||||
auto &fontManager = FontManager::get();
|
||||
fontManager.init();
|
||||
fontManager.registerFont("default", "assets/Fonts/VonwaonBitmap-12px.ttf",
|
||||
12);
|
||||
|
||||
auto &audioSystem = AudioSystem::get();
|
||||
audioSystem.init();
|
||||
audioSystem.setMasterVolume(1.0f);
|
||||
audioSystem.setSoundVolume(0.8f);
|
||||
audioSystem.setMusicVolume(0.6f);
|
||||
|
||||
SDL_Log("游戏启动");
|
||||
|
||||
auto LoadingScene = MakePtr<Scene>();
|
||||
SceneManager::get().PushScene(LoadingScene);
|
||||
|
||||
auto Background = Sprite::createFromFile("assets/ImagePacks2/Loading0.jpg");
|
||||
Background->SetSize(1280, 720);
|
||||
LoadingScene->AddChild(Background);
|
||||
|
||||
auto BackgroundBar =
|
||||
Sprite::createFromFile("assets/ImagePacks2/Loading1.png");
|
||||
BackgroundBar->SetPosition(0, 686);
|
||||
LoadingScene->AddChild(BackgroundBar);
|
||||
|
||||
auto LoadCircleSp =
|
||||
Sprite::createFromFile("assets/ImagePacks2/Loading2.png");
|
||||
LoadCircleSp->SetAnchor(Vec2(0.5f, 0.5f));
|
||||
LoadCircleSp->SetPosition(1280 / 2.0f, 686 - 60);
|
||||
LoadCircleSp->SetBlendMode(BlendMode::Additive);
|
||||
LoadCircleSp->AddUpdateListener([](Actor &self, float dt) {
|
||||
auto rotation = self.GetRotation();
|
||||
self.SetRotation(rotation + 180.0f * dt);
|
||||
});
|
||||
LoadingScene->AddChild(LoadCircleSp);
|
||||
|
||||
TaskSystem::get().submitThen(
|
||||
[]() -> std::string {
|
||||
SDL_Log("Async init task on main thread: %s",
|
||||
TaskSystem::get().isMainThread() ? "true" : "false");
|
||||
|
||||
auto &pvf = PvfArchive::get();
|
||||
if (!pvf.open("assets/Script.pvf")) {
|
||||
throw std::runtime_error("Failed to open assets/Script.pvf");
|
||||
}
|
||||
pvf.init();
|
||||
|
||||
auto &npk = NpkArchive::get();
|
||||
npk.setImagePackDirectory("assets/ImagePacks2");
|
||||
npk.setDefaultImg("sprite/interface/base.img", 0);
|
||||
npk.init();
|
||||
|
||||
auto &archive = SoundPackArchive::get();
|
||||
archive.setSoundPackDirectory("assets/SoundPacks");
|
||||
archive.init();
|
||||
|
||||
auto &audioDatabase = AudioDatabase::get();
|
||||
audioDatabase.loadFromFile("assets/audio.xml");
|
||||
|
||||
return "后台资源加载成功";
|
||||
},
|
||||
[](std::string message) mutable {
|
||||
SDL_Log("后台资源加载成功");
|
||||
|
||||
auto testMapScene = MakePtr<GameMapTestScene>();
|
||||
SceneManager::get().ReplaceScene(testMapScene);
|
||||
},
|
||||
[](std::exception_ptr error) {
|
||||
try {
|
||||
if (error) {
|
||||
std::rethrow_exception(error);
|
||||
}
|
||||
} catch (const std::exception &ex) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Async init failed: %s",
|
||||
ex.what());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
SDL_Log("Application exited normally");
|
||||
app.shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user