实现NPC系统的核心功能,包括: 1. 新增NpcDataLoader用于加载NPC索引和配置数据 2. 添加NpcAnimation处理NPC动画显示 3. 创建NpcObject实现NPC交互和显示逻辑 4. 在GameMapTestScene中集成测试NPC功能
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#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
|