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:
parent
7c7c78cacf
commit
bc7a8dfdff
@ -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;
|
||||
|
||||
@ -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?
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user