コード例 #1
0
ファイル: hud.hpp プロジェクト: K0teu/Squares-War
        void aktualizuj_kamere()
        {
            kamera.setCenter( gracz->zwroc_wsp().x, gracz->zwroc_wsp().y);
//            if( gracz->dmg_krytyczny ){
//                ::przyblizenie = 0.9;
//                gracz->dmg_krytyczny = false;
//            }

//            if( przyblizenie < 1 )
//                przyblizenie += 0.00000000000001;
//            if( przyblizenie > 1 )
//                przyblizenie = 1;

            kamera.zoom( przyblizenie );
        }
コード例 #2
0
bool handleResize(void){
    
    bool limitWindowSize = true;
    int minWindowSize = 71, smallSide;
    
    if ( (limitWindowSize) && (event.size.height < minWindowSize) )
    {
        event.size.height = minWindowSize;
        window.setSize( sf::Vector2u(event.size.width, event.size.height) );
    }
    
    view.setSize(event.size.width, event.size.height);
    
    if (event.size.width <= event.size.height)
    {
        view.zoom(1.0 * InitWinX / event.size.width);
    }
    else
    {
        view.zoom(1.0 * InitWinY / event.size.height);
    }

    window.setView(view);
}
コード例 #3
0
void gestionTouches (sf::View &View, sf::Clock &timer)
{
    float Offset =  timer.getElapsedTime().asMilliseconds();

    // le deplacement de la map
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) )      View.move( 0,      -Offset);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) )    View.move( 0,       Offset);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) )    View.move(-Offset,  0);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) )   View.move(Offset,   0);

    // le zoom
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Add) )         View.zoom(1.005f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Subtract) )    View.zoom(0.995f);

    // la gestion du "temps"
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) )    MonTimer::getSpeed() * 1.07;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) )    MonTimer::getSpeed() / 1.07;

    // clean
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::E) )     std::cout <<std::endl <<std::endl<<std::endl<<std::endl;

}
コード例 #4
0
ファイル: ironman.cpp プロジェクト: markus456/neural-network
bool update()
{
	sf::Event event;
	while(window->pollEvent(event)) {
		switch (event.type) {
		case sf::Event::Closed:
			return false;
		case sf::Event::KeyPressed:
			switch(event.key.code) {
			case sf::Keyboard::Up:
				camera.move(0,-1);
				break;
			case sf::Keyboard::Down:
				camera.move(0,1);
				std::cout << camera.getCenter().x;
				break;
			case sf::Keyboard::Left:
				camera.move(-1,0);
				break;
			case sf::Keyboard::Right:
				camera.move(1,0);
				break;
			case sf::Keyboard::F1:
				for(int i = 0; i<10; i++) {
					updateCreatures();
				}
				break;
			case sf::Keyboard::F2:
				for(int i = 0; i<100; i++) {
					updateCreatures();
				}
				break;
			case sf::Keyboard::F3:
				fastForward(10);
				break;
			case sf::Keyboard::F4:
				fastForward(50);
				break;
			}
			break;
		case sf::Event::MouseMoved:
			if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
				camera.move(mousepos-window->mapPixelToCoords(sf::Mouse::getPosition(),camera));
			}
			mousepos = window->mapPixelToCoords(sf::Mouse::getPosition(),camera);
			break;
		case sf::Event::MouseWheelMoved:
			if(event.mouseWheel.delta>0) {
				camera.zoom(1.15);
			} else if(event.mouseWheel.delta<0) {
				camera.zoom(0.85);
			}
			break;
		case sf::Event::MouseButtonPressed:
			if(mouseclock.getElapsedTime().asMilliseconds()<333) {
				auto center = window->mapPixelToCoords(sf::Vector2i(event.mouseButton.x,event.mouseButton.y),camera);
				camera.setCenter(center);
				camera.setSize(sf::Vector2f(SCREEN_W,SCREEN_H));
			}
			prev_click = mouseclock.restart();
			break;
		}
	}
	double ftest = 0;
	avg = 0;
	for(auto& creature: creatures) {
		creature->foodPool(food);
		creature->update();
		for(auto fd = food.begin(); fd<food.end(); fd++) {
			if(distance(creature->getPos(),*fd)<15) {
				fd = food.erase(fd);
				creature->increaseFitness(1.f);
			}
		}
		avg += creature->getFitness();
		if(creature->getFitness()>ftest) {
			ftest = creature->getFitness();
		}
	}
	pavg = avg;
	avg = avg/creatures.size();
	if(avg>bestavg) {
		best_so_far = vpop->getPopulationRef();
	} else if(avg < bestavg*0.85) {
		vpop->revertPopulation(best_so_far);
	}

	while(food.size()<FOOD_CAP) {
		food.push_back(sf::Vector2f(20 + rand() % (AREA_W-40), 10 + rand() % (AREA_H-20)));
	}

	if(counter>1) {
		counter--;
	} else {
		updateCreatures();
		counter = 60*evolution_rate;
		std::cout << "Generation: " << gen++;
		std::cout << " fittest: " << ftest;
		std::cout << " average: " << avg << std::endl;
	}
	return true;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: cyclohexanamine/shipbrain
	int render(Phys* phys)
	{
        window->clear(sf::Color::Black);
		
		sf::Vector2f viewmove(0, 0);
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) viewmove.x -= base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) viewmove.x += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) viewmove.y += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) viewmove.y -= base_camera_move;
		viewmove *= (phys->dt * view->getSize().x / scrw);
		viewmove = sv2rotate(viewmove, -view->getRotation());
		view->move(viewmove);
		
		view->zoom(pow(1.2, -mouse_wheel));
		mouse_wheel = 0;

		float viewrotate = 0;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::LBracket)) viewrotate += base_camera_rotate;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::RBracket)) viewrotate -= base_camera_rotate;
		viewrotate *= phys->dt;
		view->rotate(viewrotate);
		
		window->setView(*view);
		
		
		
		for (std::vector<Ship*>::iterator its = phys->ship_list.begin(); its != phys->ship_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}		
		for (std::vector<Shell*>::iterator its = phys->shell_list.begin(); its != phys->shell_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}
		
		char* str = new char[30];
		float acc = 0;
		for (int i = 0; i < frame_time_count; i++) acc += phys->last_frame_deltas[i];
		acc /= frame_time_count;
		sprintf(str, "%.1f", 1./acc);
		drawtext(str, 0.02, 0.98, 10);	
		
		int sc = (*phys->ship_list.begin())->score;
		sprintf(str, "%d", sc);
		drawtext(str, 0.98, 0.98, 10);
		
		delete str;
		
		
        window->display();
		
		return 0;
	}