From 7c7c78cacf224ba473cfaf5a9d85f1dcc805eb59 Mon Sep 17 00:00:00 2001 From: ineslelin Date: Fri, 21 Jun 2024 17:39:07 +0200 Subject: [PATCH] added interaction component --- include/InteractionComponent.h | 23 +++++++++++++++++ src/InteractionComponent.cpp | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 include/InteractionComponent.h create mode 100644 src/InteractionComponent.cpp diff --git a/include/InteractionComponent.h b/include/InteractionComponent.h new file mode 100644 index 0000000..ba07004 --- /dev/null +++ b/include/InteractionComponent.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Component.h" +#include "Entity.h" + +#include + +class InteractionComponent : public Component +{ +public: + InteractionComponent(bool canInteract, bool isInteractable); + ~InteractionComponent(); + + void init() override; + void update() override; + + Entity* getClosestInteractableEntity(/*last direction key input*/ std::vector entities); + bool interact(Entity* interactee); + +private: + bool canInteract; + bool isInteractable; +}; \ No newline at end of file diff --git a/src/InteractionComponent.cpp b/src/InteractionComponent.cpp new file mode 100644 index 0000000..62a83bb --- /dev/null +++ b/src/InteractionComponent.cpp @@ -0,0 +1,46 @@ +#include "InteractionComponent.h" + +InteractionComponent::InteractionComponent(bool canInteract, bool isInteractable) +{ + this->canInteract = canInteract; + this->isInteractable = isInteractable; +} + +InteractionComponent::~InteractionComponent() = default; + +void InteractionComponent::init() +{ + +} + +void InteractionComponent::update() +{ + +} + +Entity* getClosestInteractableEntity(/*last direction key input*/ std::vector entities) +{ + // code to compare and find closest entity + + +} + +bool InteractionComponent::interact(Entity* interactee) +{ + if(!interactee->hasComponent || !interactee->getComponent.isInteractable) + { + return false; + } + + return true; + + // code to interact, basically +} + +// TODO: +// - find a way to determine which entities are interactible (bool, map?) +// - get the last saved key input => if two interactible entities, favour the one closer to last input/m +// maybe only make the one in direction of last input interactible +// - add toggleable marker to show last direction => like stardew? (probably only possible once tmx + layers properly implemented) +// - add key input e for interact/maybe alt gr for other person? +