generated from avadae/minigin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stable version w/ score, shooting and player respawn
- Loading branch information
1 parent
c5788e6
commit f5a5eba
Showing
22 changed files
with
872 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#pragma once | ||
#include <string> | ||
#include <unordered_map> | ||
#include <stdexcept> | ||
|
||
#pragma region BlackboardTypes | ||
|
||
static const std::string OWNER_PARAM{ "Owner" }; | ||
|
||
#pragma endregion | ||
|
||
class IBlackBoardField | ||
{ | ||
public: | ||
IBlackBoardField() = default; | ||
virtual ~IBlackBoardField() = default; | ||
}; | ||
|
||
//BlackboardField does not take ownership of pointers whatsoever! | ||
template<typename T> | ||
class BlackboardField : public IBlackBoardField | ||
{ | ||
public: | ||
explicit BlackboardField(const std::string& name, const T& data) : m_Name{ name }, m_Data{ data } { } | ||
|
||
inline const std::string& GetName() const { return m_Name; } | ||
inline const T& GetData() const { return m_Data; }; | ||
inline void SetData(const T& data) { m_Data = data; } | ||
|
||
private: | ||
const std::string m_Name; | ||
T m_Data; | ||
}; | ||
|
||
class Blackboard final | ||
{ | ||
public: | ||
Blackboard() = default; | ||
~Blackboard() | ||
{ | ||
for (auto& el : m_BlackboardData) | ||
delete el.second; | ||
m_BlackboardData.clear(); | ||
} | ||
|
||
Blackboard(const Blackboard& other) = delete; | ||
Blackboard& operator=(const Blackboard& other) = delete; | ||
Blackboard(Blackboard&& other) = delete; | ||
Blackboard& operator=(Blackboard&& other) = delete; | ||
|
||
template<typename T> | ||
bool GetData(const std::string& name, T& data) const | ||
{ | ||
const auto& it = m_BlackboardData.find(name); | ||
if (it != m_BlackboardData.end()) | ||
{ | ||
if (const BlackboardField<T>* p = dynamic_cast<BlackboardField<T>*>((*it).second)) | ||
{ | ||
data = p->GetData(); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
template<typename T> | ||
bool SetData(const std::string& name, const T& data) | ||
{ | ||
auto it = m_BlackboardData.find(name); | ||
if (it == m_BlackboardData.end()) | ||
{ | ||
m_BlackboardData[name] = new BlackboardField<T>(name, data); | ||
return true; | ||
} | ||
|
||
if (auto* p = dynamic_cast<BlackboardField<T>*>((*it).second)) | ||
{ | ||
p->SetData(data); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool GetBoolData(const std::string& name) const | ||
{ | ||
bool value; | ||
return GetData(name, value) ? value : false; | ||
} | ||
|
||
void RemoveData(const std::string& name) | ||
{ | ||
m_BlackboardData.erase(name); | ||
} | ||
|
||
private: | ||
std::unordered_map<std::string, IBlackBoardField*> m_BlackboardData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
#pragma once | ||
#include "Component.h" | ||
#include "Event.h" | ||
#include "IEventListener.h" | ||
#include <string> | ||
#include <glm\glm.hpp> | ||
|
||
namespace Fluffy | ||
{ | ||
class GameObject; | ||
class Event; | ||
class SpriteColliderComponent; | ||
struct IEventParam; | ||
} | ||
class Character : public Fluffy::Component | ||
|
||
const int INVALID_PLAYER_INDEX{ -1 }; | ||
|
||
class Character : public Fluffy::Component, public Fluffy::IEventListener | ||
{ | ||
public: | ||
virtual ~Character() = default; | ||
|
||
void Start() override; | ||
|
||
inline int GetLivesCount() const { return m_LivesCount; } | ||
inline const glm::vec2& GetSpriteSize() const { return m_SpriteSize; } | ||
inline Fluffy::Event& GetOnDamageTaken() { return m_OnDamageTaken; } | ||
inline Fluffy::Event& GetOnDeath() { return m_OnDeath; } | ||
|
||
void Kill(int killerIndex = 0); | ||
virtual int GetPlayerIndex() const { return INVALID_PLAYER_INDEX; } | ||
virtual void Kill(int killerIndex = INVALID_PLAYER_INDEX); | ||
|
||
void OnNotify(const Fluffy::EventType& eventType, const Fluffy::IEventParam* pParam) override; | ||
|
||
protected: | ||
Character(Fluffy::GameObject* pOwner, int livesCount); | ||
|
||
|
||
virtual const std::string& GetCollisionLayer() const = 0; | ||
virtual void OnCollisionEnter(Fluffy::GameObject* pOtherGameObject) = 0; | ||
|
||
glm::vec2 m_SpriteSize{}; | ||
int m_LivesCount; | ||
|
||
Fluffy::Event m_OnDamageTaken{ Fluffy::EventType::OnDamageTaken }; | ||
Fluffy::Event m_OnDeath{ Fluffy::EventType::OnCharacterDeath }; | ||
}; | ||
|
Oops, something went wrong.