feat(npc): 添加NPC数据加载、动画和对象功能
实现NPC系统的核心功能,包括: 1. 新增NpcDataLoader用于加载NPC索引和配置数据 2. 添加NpcAnimation处理NPC动画显示 3. 创建NpcObject实现NPC交互和显示逻辑 4. 在GameMapTestScene中集成测试NPC功能
This commit is contained in:
59
Game/include/npc/NpcObject.h
Normal file
59
Game/include/npc/NpcObject.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "character/CharacterActionTypes.h"
|
||||
#include "npc/NpcAnimation.h"
|
||||
#include <frostbite2D/2d/text_sprite.h>
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class NpcObject : public Actor {
|
||||
public:
|
||||
NpcObject() = default;
|
||||
~NpcObject() override = default;
|
||||
|
||||
bool Construction(int npcId);
|
||||
|
||||
void SetDirection(int direction);
|
||||
void SetNpcPosition(const Vec2& pos);
|
||||
void SetWorldPosition(const CharacterWorldPosition& pos);
|
||||
void SetInteractable(bool interactable);
|
||||
void BeginInteract();
|
||||
void EndInteract();
|
||||
|
||||
bool CanInteract() const;
|
||||
bool IsInteracting() const { return interacting_; }
|
||||
int GetNpcId() const { return npcId_; }
|
||||
int GetDirection() const { return direction_; }
|
||||
const std::string& GetName() const;
|
||||
const std::string& GetFieldName() const;
|
||||
const std::string& GetDisplayName() const;
|
||||
const CharacterWorldPosition& GetWorldPosition() const { return worldPosition_; }
|
||||
bool IsAnimationFinished() const;
|
||||
|
||||
const npc::NpcConfig* GetConfig() const {
|
||||
return config_ ? &config_.value() : nullptr;
|
||||
}
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
private:
|
||||
void EnsureNameLabel();
|
||||
void RefreshNameLabel();
|
||||
void SyncActorPositionFromWorld();
|
||||
|
||||
int npcId_ = -1;
|
||||
int direction_ = 1;
|
||||
CharacterWorldPosition worldPosition_;
|
||||
std::optional<npc::NpcConfig> config_;
|
||||
RefPtr<NpcAnimation> animation_ = nullptr;
|
||||
std::array<RefPtr<TextSprite>, 8> nameOutlineLabels_;
|
||||
RefPtr<TextSprite> nameLabel_ = nullptr;
|
||||
bool interactable_ = true;
|
||||
bool interacting_ = false;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user