Exemplo n.º 1
0
int main()
{
	new EventSystem;
	new GraphicsSystem;
	InputSystem* input = new InputSystem();
	EventSystem::ptr()->registerListener(input);


	new EntityManager;
	new PhysicsSystem(9.81f);

	EventSystem::ptr()->registerListener(GraphicsSystem::ptr());
	EventSystem::ptr()->registerListener(EntityManager::ptr());

	// THE GROUND //////////////////////////////////
	GraphicsSystem::ptr()->loadTexture("brick", "2DGame.jpg");
	GraphicsSystem::ptr()->loadTexture("box", "box.png");
	GraphicsSystem::ptr()->loadTexture("mario", "mario.jpg");

	Entity* ent = new Entity();
	b2PolygonShape* shape = new b2PolygonShape();
	shape->SetAsBox(25.0f, 2.5f);
	ent->init(Vec2(50.0f, 5.0f), Vec2(20, 25), shape, true);

	EntityManager::ptr()->addEntity(ent);
	ent->setTexture("brick");
	ent->getBody()->GetFixtureList()->SetFriction(0.3f);

	Player* karl = new Player();
	EventSystem::ptr()->registerListener(karl);

	b2PolygonShape* boxs = new b2PolygonShape();
	boxs->SetAsBox(0.5f, 0.5f);

	for (int i = 0; i < 20; i++)
	{
		Entity* box = new Entity();
		box->init(Vec2(1.0, 1.0), Vec2(10.0, -5.0*i), boxs);
		EntityManager::ptr()->addEntity(box);
		box->getBody()->GetFixtureList()[0].SetDensity(i*100.0);
		box->setTexture("box");
	}
	

	////////// SETUP
	float32 timeStep = 1.0f / 60.0f;
	int32 velocityIterations = 8;
	int32 positionIterations = 3;

	//

	while (GraphicsSystem::ptr()->getRenderWindow()->isOpen())
	{
		input->update(*GraphicsSystem::ptr()->getRenderWindow());
		GraphicsSystem::ptr()->update();
		PhysicsSystem::ptr()->getWorld()->Step(timeStep, velocityIterations, positionIterations);
		
		EntityManager::ptr()->update();
	}

	EventSystem::release();
	return 0;
}