Exemple #1
0
// Caution: Can possibly deactivate this territory and activate another.
void Territory::collideBorderTiles()
{
	for (int i = 0; i < borderCoordinates.size(); i++)
	{
		Hexagon * tile = floorTiles[borderCoordinates[i].q][borderCoordinates[i].r];

		if (Collision::hitBoxesOverlap(tile->getBoundingBox(), player->getBoundingBox(), player->getSpeed()))
		{
			std::list<Vector2f> penetration;

			if (SAT::collides(player->getConvexHull(), tile->getConvexHull(), player->getSpeed(), penetration))
			{
				// Move the player into another territory if the player is in a safe zone.
				if (player->getIsInSafeZone())
				{
					Vector2f direction = Vector2fMath::unitVector(player->getPosition() - position);
					Vector2f seekPosition = position + (direction * radius * 1.1f);

					world->changeTerritory(seekPosition);

					break;
				}
				else
				{
					player->translate(SAT::getShortestPenetration(penetration));
				}
			}
		}
	}
}
Exemple #2
0
// Updates the player and checks if the player is in a safe zone.
void Territory::updatePlayer(UpdateInfo info, Controls * controls)
{
	player->update(info, controls);
	player->setIsInSafeZone(false);

	// Check if the player is in a safe zone.
	for (int i = 0; i < 6 && !player->getIsInSafeZone(); i++)
	{
		for (int j = 0; j < safeZonesTiles[i].size(); j++)
		{
			Hexagon * tile = safeZonesTiles[i][j];

			if (Collision::hitBoxesOverlap(tile->getBoundingBox(), Vector2f(), player->getBoundingBox(), player->getSpeed()))
			{
				std::list<Vector2f> penetration;

				if (SAT::collides(player->getConvexHull(), tile->getConvexHull(), player->getSpeed(), penetration))
				{
					player->setIsInSafeZone(true);
					player->setSafeZoneIndex(i);

					break;
				}
			}
		}
	}
}