mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 21:23:41 +00:00
added interaction component
This commit is contained in:
parent
58e2bb0d30
commit
7c7c78cacf
23
include/InteractionComponent.h
Normal file
23
include/InteractionComponent.h
Normal 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;
|
||||||
|
};
|
||||||
46
src/InteractionComponent.cpp
Normal file
46
src/InteractionComponent.cpp
Normal 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?
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user