Ejemplo n.º 1
0
static void
DrawSurfaceWithTextureCoords(DrawTarget *aDest,
                             const gfx::Rect& aDestRect,
                             SourceSurface *aSource,
                             const gfx::Rect& aTextureCoords,
                             gfx::Filter aFilter,
                             float aOpacity,
                             SourceSurface *aMask,
                             const Matrix* aMaskTransform)
{
  // Convert aTextureCoords into aSource's coordinate space
  gfxRect sourceRect(aTextureCoords.x * aSource->GetSize().width,
                     aTextureCoords.y * aSource->GetSize().height,
                     aTextureCoords.width * aSource->GetSize().width,
                     aTextureCoords.height * aSource->GetSize().height);

  // Floating point error can accumulate above and we know our visible region
  // is integer-aligned, so round it out.
  sourceRect.Round();

  // Compute a transform that maps sourceRect to aDestRect.
  Matrix matrix =
    gfxUtils::TransformRectToRect(sourceRect,
                                  gfx::IntPoint(aDestRect.x, aDestRect.y),
                                  gfx::IntPoint(aDestRect.XMost(), aDestRect.y),
                                  gfx::IntPoint(aDestRect.XMost(), aDestRect.YMost()));

  // Only use REPEAT if aTextureCoords is outside (0, 0, 1, 1).
  gfx::Rect unitRect(0, 0, 1, 1);
  ExtendMode mode = unitRect.Contains(aTextureCoords) ? ExtendMode::CLAMP : ExtendMode::REPEAT;

  FillRectWithMask(aDest, aDestRect, aSource, aFilter, DrawOptions(aOpacity),
                   mode, aMask, aMaskTransform, &matrix);
}
Ejemplo n.º 2
0
void entity_checkCollisionWithMap(const Entity& entity, sf::Vector2f& movement)
{
	for (auto &obj : level_getCollisions(*entity.level))
	{
		if (obj.GetType() == "solid")
		{
			sf::FloatRect objRect(createRect(OrthogonalToIsometric(obj.GetPosition()), obj.GetSize()));
			if (createRect(OrthogonalToIsometric(entity.objectEntity->GetPosition() + movement), entity.objectEntity->GetSize()).intersects(objRect))
			{
				if (movement.y > 0.f)
					movement.y = 0.f;
				if (movement.y < 0.f)
					movement.y = 0.f;
				if (movement.x > 0)
					movement.x = 0.f;
				if (movement.x < 0)
					movement.x = 0.f;
			}
		}
	}
	for (auto &unit : level_getUnits(*entity.level))
	{
		auto un = unit.GetPropertyString("dead");
		if (unit.GetName() != entity.objectEntity->GetName() && unit.GetPropertyString("dead") == "0")
		{
			sf::FloatRect unitRect(createRect(OrthogonalToIsometric(unit.GetPosition()), unit.GetSize()));
			if (createRect(OrthogonalToIsometric(entity.objectEntity->GetPosition() + movement), entity.objectEntity->GetSize()).intersects(unitRect))
			{
				if (movement.y > 0.f)
					movement.y = 0.f;
				if (movement.y < 0.f)
					movement.y = 0.f;
				if (movement.x > 0)
					movement.x = 0.f;
				if (movement.x < 0)
					movement.x = 0.f;
			}
		}
	}
}