feat: 添加游戏核心模块,包括地图、角色、场景和世界管理
实现游戏基础架构,包含以下主要功能: - 地图系统:支持地图加载、图层管理和相机控制 - 角色系统:实现角色装备、动画和行为管理 - 场景系统:提供测试场景和世界场景切换 - 世界管理:处理城镇和区域切换逻辑 - 数据加载:添加角色和装备配置加载器 这些改动为游戏开发奠定了基础框架,支持后续功能扩展
This commit is contained in:
61
Game/src/character/CharacterObject.cpp
Normal file
61
Game/src/character/CharacterObject.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "character/CharacterObject.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
bool CharacterObject::Construction(int jobId) {
|
||||
RemoveAllChildren();
|
||||
animationManager_ = nullptr;
|
||||
config_.reset();
|
||||
currentAction_.clear();
|
||||
|
||||
auto config = character::loadCharacterConfig(jobId);
|
||||
if (!config) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"CharacterObject: failed to load job %d config", jobId);
|
||||
return false;
|
||||
}
|
||||
|
||||
jobId_ = jobId;
|
||||
growType_ = -1;
|
||||
direction_ = 1;
|
||||
config_ = *config;
|
||||
equipmentManager_.Init(config_->baseJobConfig);
|
||||
|
||||
animationManager_ = MakePtr<CharacterAnimation>();
|
||||
if (!animationManager_->Init(this, *config_, equipmentManager_)) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"CharacterObject: no layered avatar animations available, character will stay empty");
|
||||
}
|
||||
AddChild(animationManager_);
|
||||
|
||||
if (config_->animationPath.count("rest") > 0) {
|
||||
SetAction("rest");
|
||||
} else if (!config_->animationPath.empty()) {
|
||||
SetAction(config_->animationPath.begin()->first);
|
||||
}
|
||||
|
||||
SetDirection(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CharacterObject::SetAction(const std::string& actionName) {
|
||||
currentAction_ = actionName;
|
||||
if (animationManager_) {
|
||||
animationManager_->SetAction(actionName);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterObject::SetDirection(int direction) {
|
||||
direction_ = direction >= 0 ? 1 : -1;
|
||||
if (animationManager_) {
|
||||
animationManager_->SetDirection(direction_);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterObject::SetCharacterPosition(const Vec2& pos) {
|
||||
SetPosition(pos);
|
||||
SetZOrder(static_cast<int>(pos.y));
|
||||
}
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user