0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

added interaction component

This commit is contained in:
ineslelin 2024-06-21 17:39:07 +02:00
parent 58e2bb0d30
commit 7c7c78cacf
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#pragma once
#include "Component.h"
#include "Entity.h"
#include <vector>
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<Entity*> entities);
bool interact(Entity* interactee);
private:
bool canInteract;
bool isInteractable;
};

View File

@ -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<Entity*> entities)
{
// code to compare and find closest entity
}
bool InteractionComponent::interact(Entity* interactee)
{
if(!interactee->hasComponent<InteractionComponent> || !interactee->getComponent<InteractionComponent>.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?