#include "component_behavior_act_in_rectangle.h"

/* DEPENDENCIES: Physics */

/* Only allows enemies to act when within a certain range; prevents off-screen chicanery. */

void
component_behavior_act_in_rectangle_init(ComponentBehaviorActInRectangle* self, Rectangle rectangle)
{
	self->rectangle = rectangle;
}

/* Ticks behavior_act_in_rectangle component. */
void
component_behavior_act_in_rectangle_tick(ComponentBehaviorActInRectangle* self, ECS* ecs)
{	
	ComponentPhysics* physics;
	Rectangle physicsRectangle;

	physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->component.id);

	component_physics_rectangle_get(physics, &physicsRectangle);

	if (rectangle_collide(&physicsRectangle, &self->rectangle))
		self->isAbleToAct = true;
	else
		self->isAbleToAct = false;
}
