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

finished interact(), put down idea for getting closest entity

This commit is contained in:
ineslelin 2024-06-22 12:58:51 +02:00
parent 7c7c78cacf
commit bc7a8dfdff
2 changed files with 30 additions and 11 deletions

View File

@ -14,8 +14,8 @@ public:
void init() override;
void update() override;
Entity* getClosestInteractableEntity(/*last direction key input*/ std::vector<Entity*> entities);
bool interact(Entity* interactee);
Entity* getClosestInteractableEntity(Key directionKey, Entity* interactor, std::vector<Entity*> entities);
bool interact(Entity* interactor, Entity* interactee);
private:
bool canInteract;

View File

@ -18,29 +18,48 @@ void InteractionComponent::update()
}
Entity* getClosestInteractableEntity(/*last direction key input*/ std::vector<Entity*> entities)
Entity* getClosestInteractableEntity(Key directionKey, Entity* interactor, std::vector<Entity*> entities)
{
// code to compare and find closest entity
for(auto e : entities)
{
if(!e->hasComponent<InteractionComponent>() || !e->getComponent<InteractionComponent>().isInteractable)
{
auto it = std::remove(entities.begin(), entities.end(), e);
entities.erase(it, entities.end());
}
}
if(entities.empty())
{
return nullptr;
}
for(auto e : entities)
{
if(e->getComponent<TransformComponent>().position.x)
}
}
bool InteractionComponent::interact(Entity* interactee)
bool InteractionComponent::interact(Entity* interactor, Entity* interactee)
{
if(!interactee->hasComponent<InteractionComponent> || !interactee->getComponent<InteractionComponent>.isInteractable)
if(!interactor->hasComponent<InteractionComponent>() || !interactor->getComponent<InteractionComponent>().canInteract)
{
throw std::logic_error("Interactor entity cannot interact");
}
if(!interactee->hasComponent<InteractionComponent>() || !interactee->getComponent<InteractionComponent>().isInteractable)
{
return false;
}
return true;
// code to interact, basically
return true;
}
// 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
// - get the last saved key input => if two interactible entities, favour the one closer to last input/
// maybe only make the one in direction of last input interactible, or if two entities are ex. left and right and the last
// input was down, then either try to calc the closer one or if theyre the same distance away, favour one side automatically
// - 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?