feat: 添加游戏核心模块,包括地图、角色、场景和世界管理
实现游戏基础架构,包含以下主要功能: - 地图系统:支持地图加载、图层管理和相机控制 - 角色系统:实现角色装备、动画和行为管理 - 场景系统:提供测试场景和世界场景切换 - 世界管理:处理城镇和区域切换逻辑 - 数据加载:添加角色和装备配置加载器 这些改动为游戏开发奠定了基础框架,支持后续功能扩展
This commit is contained in:
44
Game/include/character/CharacterAnimation.h
Normal file
44
Game/include/character/CharacterAnimation.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "character/CharacterDataLoader.h"
|
||||
#include "character/CharacterEquipmentManager.h"
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <frostbite2D/animation/animation.h>
|
||||
#include <frostbite2D/base/RefPtr.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class CharacterObject;
|
||||
|
||||
class CharacterAnimation : public Actor {
|
||||
public:
|
||||
using ActionAnimationList = std::map<std::string, std::vector<RefPtr<Animation>>>;
|
||||
|
||||
bool Init(CharacterObject* parent,
|
||||
const character::CharacterConfig& config,
|
||||
const CharacterEquipmentManager& equipmentManager);
|
||||
|
||||
void SetAction(const std::string& actionName);
|
||||
void SetDirection(int direction);
|
||||
const std::string& GetCurrentAction() const { return currentActionTag_; }
|
||||
|
||||
private:
|
||||
static std::string FormatImgPath(std::string path, Animation::ReplaceData data);
|
||||
|
||||
void CreateAnimationBySlot(const std::string& actionName,
|
||||
const std::string& slotName,
|
||||
const std::string& actionPath,
|
||||
const character::CharacterConfig& config,
|
||||
const CharacterEquipmentManager& equipmentManager);
|
||||
void ApplyFlipRecursive(Actor* actor, bool flipped) const;
|
||||
|
||||
CharacterObject* parent_ = nullptr;
|
||||
ActionAnimationList actionAnimations_;
|
||||
std::string currentActionTag_;
|
||||
int direction_ = 1;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
44
Game/include/character/CharacterDataLoader.h
Normal file
44
Game/include/character/CharacterDataLoader.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace frostbite2D::character {
|
||||
|
||||
struct JobConfig {
|
||||
std::string name;
|
||||
std::map<std::string, int> defaultAvatarList;
|
||||
};
|
||||
|
||||
struct CharacterConfig {
|
||||
int jobId = -1;
|
||||
std::string jobTag;
|
||||
std::string baseJobPath;
|
||||
JobConfig baseJobConfig;
|
||||
std::map<std::string, std::string> animationPath;
|
||||
};
|
||||
|
||||
struct EquipmentVariation {
|
||||
int layer = 0;
|
||||
std::string animationGroup;
|
||||
std::array<int, 2> imgFormat = {0, 0};
|
||||
};
|
||||
|
||||
struct EquipmentConfig {
|
||||
int id = -1;
|
||||
std::string path;
|
||||
std::string name;
|
||||
std::vector<int> usableJobs;
|
||||
std::map<int, std::vector<EquipmentVariation>> jobAnimations;
|
||||
};
|
||||
|
||||
bool loadCharacterIndex(std::map<int, std::string>& outIndex);
|
||||
std::optional<CharacterConfig> loadCharacterConfig(int jobId);
|
||||
|
||||
bool loadEquipmentIndex(std::map<int, std::string>& outIndex);
|
||||
std::optional<EquipmentConfig> loadEquipmentConfig(int equipmentId);
|
||||
|
||||
} // namespace frostbite2D::character
|
||||
22
Game/include/character/CharacterEquipmentManager.h
Normal file
22
Game/include/character/CharacterEquipmentManager.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "character/CharacterDataLoader.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class CharacterEquipmentManager {
|
||||
public:
|
||||
bool Init(const character::JobConfig& jobConfig);
|
||||
|
||||
const character::EquipmentConfig* GetEquip(const std::string& slotName) const;
|
||||
const std::map<std::string, character::EquipmentConfig>& GetDefaultEquipment() const {
|
||||
return defaultEquipment_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, character::EquipmentConfig> defaultEquipment_;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
43
Game/include/character/CharacterObject.h
Normal file
43
Game/include/character/CharacterObject.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "character/CharacterAnimation.h"
|
||||
#include "character/CharacterDataLoader.h"
|
||||
#include "character/CharacterEquipmentManager.h"
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class CharacterObject : public Actor {
|
||||
public:
|
||||
CharacterObject() = default;
|
||||
~CharacterObject() override = default;
|
||||
|
||||
bool Construction(int jobId);
|
||||
|
||||
void SetAction(const std::string& actionName);
|
||||
void SetDirection(int direction);
|
||||
void SetCharacterPosition(const Vec2& pos);
|
||||
|
||||
int GetJobId() const { return jobId_; }
|
||||
int GetGrowType() const { return growType_; }
|
||||
int GetDirection() const { return direction_; }
|
||||
const std::string& GetCurrentAction() const { return currentAction_; }
|
||||
|
||||
const character::CharacterConfig* GetConfig() const {
|
||||
return config_ ? &config_.value() : nullptr;
|
||||
}
|
||||
const CharacterEquipmentManager& GetEquipmentManager() const { return equipmentManager_; }
|
||||
|
||||
private:
|
||||
int jobId_ = -1;
|
||||
int growType_ = -1;
|
||||
int direction_ = 1;
|
||||
std::string currentAction_;
|
||||
std::optional<character::CharacterConfig> config_;
|
||||
CharacterEquipmentManager equipmentManager_;
|
||||
RefPtr<CharacterAnimation> animationManager_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user