mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 15:53:42 +00:00
finished interact(), put down idea for getting closest entity
This commit is contained in:
parent
7c7c78cacf
commit
bc7a8dfdff
@ -14,8 +14,8 @@ public:
|
|||||||
void init() override;
|
void init() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
Entity* getClosestInteractableEntity(/*last direction key input*/ std::vector<Entity*> entities);
|
Entity* getClosestInteractableEntity(Key directionKey, Entity* interactor, std::vector<Entity*> entities);
|
||||||
bool interact(Entity* interactee);
|
bool interact(Entity* interactor, Entity* interactee);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool canInteract;
|
bool canInteract;
|
||||||
|
|||||||
@ -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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// code to interact, basically
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// 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/
|
||||||
// - 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, or if two entities are ex. left and right and the last
|
||||||
// maybe only make the one in direction of last input interactible
|
// 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 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?
|
// - add key input e for interact/maybe alt gr for other person?
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user