Esempio n. 1
0
Level::Level(sf::RenderWindow& window,const std::string& filename) :
    onPickup(defaultFunc),
    _map(sfutils::VMap::createMapFromFile(filename)),
    _viewer(window,*_map,Configuration::mapInputs),
    _mouseLayer(new sfutils::Layer<sf::ConvexShape>("ConvexShape",1)),
    _entitiesLayer(new sfutils::Layer<Entity*>("Entity",2))
{
    //Map
    if(_map == nullptr)
    {
        //do some error
        throw std::runtime_error("Impossible to load file " + filename);
    }


    {
        _mouse_light = _mouseLayer->add(_map->getShape());
        _mouse_light->setFillColor(sf::Color(255,255,255,64));
        _map->add(_mouseLayer);
    }
    _map->add(_entitiesLayer);

    //Viewer
    _viewer.bind(Configuration::MapInputs::TakeScreen,[&window](const sf::Event& event) {
        sf::Image screen = window.capture();

        time_t rawtime;
        struct tm * timeinfo;
        char buffer[128];

        std::time(&rawtime);
        timeinfo = std::localtime(&rawtime);
        std::strftime (buffer,128,"screen/%F_%T.png",timeinfo);
        screen.saveToFile(std::string(buffer));
    });

    //ES
    systems.add<SysAIMain>();
    systems.add<SysAIWarrior>(*this);
    systems.add<SysAIDefender>(*this);
    systems.add<SysAISpawner>(*this);
    systems.add<SysAIWalker>(*this);
    systems.add<SysAIFlyer>(*this);
    systems.add<SysSkin>();
    systems.add<SysHp>(*this);
    systems.add<SysEffect>(*this);


}
void EffectsHandler::fadeOut(sf::RenderWindow &rw)
{
    sf::Texture ScreenCap;
    ScreenCap.loadFromImage(rw.capture());
    sf::Sprite SpleenCrap;
    SpleenCrap.setTexture(ScreenCap);

    sf::Clock timer;
    float opacity = 0;
    
    while (opacity < 255) {
        rw.clear();
        opacity += timer.restart().asSeconds() * 100;
        SpleenCrap.setColor(sf::Color(0,0,0,opacity));
        
        rw.draw(SpleenCrap);
        rw.display();
    }
}
Esempio n. 3
0
/*
 * Simple window loop, won't redraw (but f**k it, this is testing)
 */
void window_loop(sf::RenderWindow &window) {
    sf::Image img = window.capture();
    sf::Texture texture;
    texture.loadFromImage(img);
    sf::Sprite sprite;
    sprite.setTexture(texture, true);
    
    sf::Event event;
	while (window.isOpen()) {
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
			} else if (event.type == sf::Event::KeyPressed) {
                if (event.key.code == sf::Keyboard::Escape) {
                    window.close();
				}
			}
            
		}
        window.draw(sprite);
        window.display();
        sf::sleep(sf::seconds(0.1f));
	}
}