Esempio n. 1
0
int main(int argc, char *argv[])
{
    artemis::World world;

        artemis::SystemManager * sm = world.getSystemManager();
        MovementSystem * movementsys = (MovementSystem*)sm->setSystem(new MovementSystem());
        artemis::EntityManager * em = world.getEntityManager();

        sm->initializeAll();

        artemis::Entity & player = em->create();

        player.addComponent(new VelocityComponent(2,4));
        player.addComponent(new PositionComponent(0,0));
        player.refresh();

        PositionComponent * comp = (PositionComponent*)player.getComponent<PositionComponent>();

        while(true){

            world.loopStart();
            world.setDelta(0.0016f);
            movementsys->process();

            std::cout << "X:"<< comp->posX << std::endl;
            std::cout << "Y:"<< comp->posY << std::endl;
            //sleep(160);
        }

    return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	/*SATCollision::TestCollision();
	return 0;*/

	const int winWidth = 800;
	const int winHeight = 600;

	initRandom();

	sf::RenderWindow window(sf::VideoMode(winWidth, winHeight), "Test");
	sf::Clock deltaTimer;

	sf::Time frameTime = sf::seconds(1.0f/60.0f);

	deltaTimer.restart();

    artemis::World world;
    artemis::SystemManager * sm = world.getSystemManager();
    MovementSystem * movementsys = (MovementSystem*)sm->setSystem(new MovementSystem());
	AngularSystem * angularsys = (AngularSystem*)sm->setSystem(new AngularSystem());
    PlayerInputSystem * inputsys = (PlayerInputSystem*)sm->setSystem(new PlayerInputSystem());
	BeamSystem* beamsys = (BeamSystem*)sm->setSystem(new BeamSystem());
	RenderSystem * rendersys = (RenderSystem*)sm->setSystem(new RenderSystem(window));
	//RenderBoxSystem * renderboxsys = (RenderBoxSystem*)sm->setSystem(new RenderBoxSystem(window));
	CollisionSystem * collisionsys = (CollisionSystem*)sm->setSystem(new CollisionSystem());
	DestroySystem * destroysys = (DestroySystem*)sm->setSystem(new DestroySystem());
	AnimSystem * animatesys = (AnimSystem*)sm->setSystem(new AnimSystem());
	ExpiresSystem * expiresys = (ExpiresSystem*)sm->setSystem(new ExpiresSystem());
    artemis::EntityManager * em = world.getEntityManager();

    sm->initializeAll();

	EntityFactory::CreatePlayer(world, sf::Vector2f(0.0f, 0.0f));

	bool running = true;

    while(running){
        world.loopStart();
        world.setDelta(deltaTimer.getElapsedTime().asSeconds());
		deltaTimer.restart();

		inputsys->SetMouse(sf::Mouse::getPosition(window));
		beamsys->SetMouse(sf::Mouse::getPosition(window));
		sf::Event anEvent;
		while(window.pollEvent(anEvent)) {
			if(anEvent.type == sf::Event::KeyPressed) {
				inputsys->KeyDown(anEvent.key.code);
			} else if(anEvent.type == sf::Event::KeyReleased) {
				inputsys->KeyRelease(anEvent.key.code);
			} else if(anEvent.type == sf::Event::MouseButtonPressed) {
				inputsys->MousePress(anEvent.mouseButton.button);
			} else if(anEvent.type == sf::Event::MouseButtonReleased) {
				inputsys->MouseRelease(anEvent.mouseButton.button);
			} else if(anEvent.type == sf::Event::Closed) {
				running = false;
			}
		}

		expiresys->process();
		inputsys->process();
		animatesys->process();
        movementsys->process();
		angularsys->process();
		beamsys->process();
		collisionsys->process();
		destroysys->process();

		window.clear();
		rendersys->process();
		//renderboxsys->process();
		window.display();

		sf::Time timePassed = deltaTimer.getElapsedTime();
		if(timePassed < frameTime) {
			sf::sleep(frameTime - timePassed);
		}
    }

    return 0;
}