Exemplo n.º 1
0
void RenderSystem::draw(GameObject* gameObject)
{
	RenderComponent* render = gameObject->getComponent<RenderComponent>();
	if (render != nullptr)
	{
		RectangleShape shape = *render->getDrawable();

		TransformComponent* transform = gameObject->getComponent<TransformComponent>();
		if (transform != nullptr)
		{
			shape.setPosition(transform->getPosition());
		}
		else
		{
			BoardComponent* boardComp = gameObject->getComponent<BoardComponent>();
			if (boardComp != nullptr && mBoard != nullptr)
			{
				Vector2i boardPos = boardComp->getPosition();
				shape.setPosition(mBoard->getTilePosition(boardPos.x, boardPos.y));
			}
		}

		mWindow->draw(shape);
	}
}
Exemplo n.º 2
0
void RenderSystem::update(float dt, std::vector<GameObject*>* objects)
{
	for (Ite i = objects->begin(); i != objects->end(); i++)
	{
		RenderComponent* render = (*i)->getComponent<RenderComponent>();
		if (render != nullptr)
		{
			RectangleShape shape = *render->getDrawable();
			PhysicsComponent* physics = (*i)->getComponent<PhysicsComponent>();
			if (physics != nullptr)
			{
				Vector2f position = mScale * flipY(physics->getBody()->GetPosition());
				shape.setPosition(position);
				shape.setSize(1.02f * mScale * physics->getSize());
				shape.setOrigin(shape.getSize() * 0.5f);

				// positive direction is opposite in Box2D
				shape.setRotation(-1.0f * physics->getBody()->GetAngle() * 180 / b2_pi);
			}
			mWindow->draw(shape);
		}
	}
}