Ejemplo n.º 1
0
void RenderSceneCB()
{
	glClear(GL_COLOR_BUFFER_BIT);

	static sf::Clock a_timer;
	static bool a_first_time = true;
	if (a_first_time) {
		a_first_time = false;
		a_timer.restart ();
	}
	float dt = a_timer.getElapsedTime ().asSeconds ();
	a_timer.restart ();
	// ֲ�גמה ג פאיכ פןס ט הוכ�עא ׂ
	//static FILE *out = fopen ((prefix_path + "inf/out.txt").c_str (), "w");
	//fprintf (out, "%4d %10g\n", int(1/dt), dt);
	if (in.kb.escape.pressed_now) {
		exit (0);
	}
	core.update (dt);
	core.render ();

	core.m_renderer.draw_everything ();

    glutSwapBuffers();
}
Ejemplo n.º 2
0
void display(sf::RenderWindow *window)
{
	if (frames==0)
		sfclock.restart();

	window->pushGLStates();
	window->resetGLStates();
	
	window->popGLStates();

	glClearColor(1.0f,1.0f,1.0f,1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
	glEnable(GL_DEPTH_TEST);
	v.draw(); 

	if (frames>500)
	{
		sf::Time t = sfclock.getElapsedTime();
		frame_rate = frames/t.asSeconds();
		frames = 0;
	}
	else
	{
		frames++;
	}
	stringstream str;

	str << "Frame rate " << frame_rate;

	//drawText(window,str.str(),window->getSize().x-200,50);

	window->display();

}
Ejemplo n.º 3
0
void DialogueMode::update(sf::RenderWindow &rw, sf::Clock &clock)
{
    float elapsed = clock.restart().asSeconds();
    rw.clear(sf::Color::White);                                     //should this be in highest loop?
    
    //handle all input
    sf::Event event;
    while (rw.pollEvent(event)) {
        if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space) {
            current = current->getNext();
            if (current == nullptr) {
                deletionOrder = true;
                return;
            }
        }
        else current->handleInput(event);
    }
    current->update(elapsed);
    
    //put into drawAll function?
    rw.setView(mapView);
    
    currentMap->drawAllObjects(rw, playerSprite);
    
    rw.setView(HUD);
    rw.draw(messageBox);
    current->draw(rw);
    rw.display();
}
Ejemplo n.º 4
0
//Process the player's inputs WASD and mouse buttons.
void Player::update(sf::RenderWindow &window, vector <Bullet *> &bullets, sf::Sound &laser, sf::FloatRect bounds, sf::Clock &fireRateTimer) {
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W) && this->getPosition().y > bounds.top) {
		this->velocity.y -= this->acceleration;
	}
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) && this->getPosition().x < bounds.width) {
		this->velocity.x += this->acceleration;
	}
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S) && this->getPosition().y < bounds.height) {
		this->velocity.y += this->acceleration;
	}
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) && this->getPosition().x > bounds.left) {
		this->velocity.x -= this->acceleration;
	}
	if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		if (fireRateTimer.getElapsedTime().asSeconds() >= this->rateOfFire && this->alive) {
			this->shoot(window, bullets, laser);
			fireRateTimer.restart();
		}
	}
	if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
		this->activateShield(window);
	}
	if (this->shieldCharge >= 200) {
		this->shieldCharge = 200;
	}
}
Ejemplo n.º 5
0
void game_state::broadcast_ping_data()
{
    static sf::Clock clk;
    const float send_time_ms = 1000;

    if(clk.getElapsedTime().asMicroseconds() / 1000.f < send_time_ms)
        return;

    clk.restart();

    byte_vector vec;
    vec.push_back(canary_start);
    vec.push_back(message::PING_DATA);

    int32_t num = player_list.size();

    vec.push_back<int32_t>(num);

    for(int i=0; i<player_list.size(); i++)
    {
        ///playerid int32_t
        ///playerping float

        vec.push_back<int32_t>(player_list[i].id);
        vec.push_back<float>(player_list[i].ping_ms);
    }

    vec.push_back(canary_end);

    int none = -1;

    broadcast(vec.ptr, none);
}
Ejemplo n.º 6
0
void render()
{
	std::stringstream ss;
	std::deque<Point> trails, vertices;
	window->clear();
	window->setView(camera);
	window->draw(bg);
	sf::Color color(sf::Color::Red);
	sf::ConvexShape tail;
	tail.setFillColor(sf::Color(128,0,0,128));
	for(auto& creature:creatures) {
		window->draw(*creature);
	}
	for(auto& f:food) {
		fToken->setPosition(f);
		window->draw(*fToken);
	}
	ss.str("");
	ss << "Generation: " << gen;
	text->setPosition(10,10);
	text->setString(ss.str());
	window->setView(window->getDefaultView());
	window->draw(*text);
	if(frameclock.getElapsedTime().asMilliseconds()>0) {
		ss.str("");
		ss << "FPS: " << (int)1000.f/frameclock.restart().asMilliseconds();
		text->setString(ss.str());
		text->move(0,text->getLocalBounds().height);
		window->draw(*text);
	}

	window->display();
}
Ejemplo n.º 7
0
void game_state::periodic_team_broadcast()
{
    static sf::Clock clk;

    ///once per second
    float broadcast_every_ms = 1000.f;

    if(clk.getElapsedTime().asMicroseconds() / 1000.f < broadcast_every_ms)
        return;

    clk.restart();

    for(auto& i : player_list)
    {
        ///network
        byte_vector vec;
        vec.push_back(canary_start);
        vec.push_back(message::TEAMASSIGNMENT);
        vec.push_back<int32_t>(i.id);
        vec.push_back<int32_t>(i.team);
        vec.push_back(canary_end);

        //printf("Team ass %i team player %i\n", i.team, i.id);

        int no_player = -1;

        broadcast(vec.ptr, no_player);
    }
}
Ejemplo n.º 8
0
void game_state::periodic_respawn_info_update()
{
    static sf::Clock clk;

    ///once per second
    float broadcast_every_ms = 100.f;

    if(clk.getElapsedTime().asMicroseconds() / 1000.f < broadcast_every_ms)
        return;

    clk.restart();

    for(auto& i : respawn_requests)
    {
        player play = get_player_from_player_id(i.player_id);

        if(play.id == -1)
            continue;

        float time_elapsed = i.clk.getElapsedTime().asMicroseconds() / 1000.f;

        byte_vector vec;
        vec.push_back(canary_start);
        vec.push_back(message::RESPAWNINFO);
        vec.push_back(time_elapsed);
        vec.push_back(i.time_to_respawn_ms);
        vec.push_back(canary_end);

        udp_send_to(play.sock, vec.ptr, (const sockaddr*)&play.store);
    }
}
void init()
{
	sf::ContextSettings settings;
	settings.depthBits = 24;
	settings.stencilBits = 8;
	settings.antialiasingLevel = 2;

	window.create(sf::VideoMode(800, 600), "Bezier_Spline_Wireframe", sf::Style::Close, settings);

	glewExperimental = true;
	glewInit();

	initShaders();

	// Store the data for the triangles in a buffer that the gpu can use to draw
	glGenVertexArrays(1, &vao0);
	glBindVertexArray(vao0);

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &ebo0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo0);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

	// Bind buffer data to shader values
	posAttrib = glGetAttribLocation(shaderProgram, "position");
	glEnableVertexAttribArray(posAttrib);
	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

	glGenVertexArrays(1, &vao1);
	glBindVertexArray(vao1);

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &ebo1);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo1);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(outlineElements), outlineElements, GL_STATIC_DRAW);

	// Bind buffer data to shader values
	posAttrib = glGetAttribLocation(shaderProgram, "position");
	glEnableVertexAttribArray(posAttrib);
	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

	timer.restart();

	time_t timer;
	time(&timer);
	srand((unsigned int)timer);

	generateTeapot();

	InputManager::Init(&window);
	CameraManager::Init(800.0f / 600.0f, 60.0f, 0.1f, 100.0f);

	glEnable(GL_DEPTH_TEST);
}
Ejemplo n.º 10
0
	void Present() {
		window_->display();
		//sleep enough time
		sf::Time t = tclock.restart();
		if(t.asMilliseconds() < 1000.0 / 60.0)
			sf::sleep(sf::milliseconds(1000.0 / 60.0) - t);
	}
Ejemplo n.º 11
0
void display(sf::RenderWindow *window)
{
	if (frames==0)
		sfclock.restart();
	
	// Draw using SFML
	window->pushGLStates();
	window->resetGLStates();
	//insert SFML drawing code here (any part you are using that does not involve opengl code)
	window->popGLStates();

	//set up the background color of the window. This does NOT clear the window. Right now it is (0,0,0) which is black
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //this command actually clears the window.
	glEnable(GL_DEPTH_TEST);
	v.draw(raytrace); //simply delegate to our view class that has all the data and does all the rendering

	if (frames>500)
	{
		sf::Time t = sfclock.getElapsedTime();
		frame_rate = frames/t.asSeconds();
		frames = 0;
	}
	else
	{
		frames++;
	}
	stringstream str;

	
	// Finally, display the rendered frame on screen
	window->display();
//	cout << "Rendering" << endl;
}
Ejemplo n.º 12
0
/**
Représente un tour de boucle, ici ce trouve
toutes la gestion du jeu
@return true si pas de collision
*/
bool Game::gameLoop(sf::Clock & clock)
{
	affichage();

	sf::Event event;
	recuperationEntree(event);

	//valeur qui sera retrournée a la fin de la GameLoop
	bool etat = m_map.collisionBloc(m_vaisseauJoueur, m_tirs, m_distanceParcouru);

	actualisationInfoJoueur();

	//actualisation du temps
	m_tempsPasse = clock.getElapsedTime().asMicroseconds() / 20000.;
	clock.restart().asMicroseconds();
	m_tempsPasse /= m_coefRalentissement;

	//calcul de la trajectoire puis la vitesse sera calculé a part
	traitement(event, m_tempsPasse);

	gestionScrolling(m_tempsPasse);

	//deplacement des tirs
	gererTirs(m_tempsPasse);

	rechargeDesVaisseaux(m_tempsPasse);

	actualiserAnimation(m_tempsPasse);

	//comp 1
	float tempsMaxComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeMax();
	float tempsActuelComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeActuel();
	float rapportComp1 = 1;

	if (tempsActuelComp != tempsMaxComp)
		rapportComp1 = ((tempsMaxComp - tempsActuelComp) / tempsMaxComp);

	//comp 2
	tempsMaxComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeMax();
	tempsActuelComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeActuel();
	float rapportComp2 = tempsActuelComp / tempsMaxComp;

	//comp 3
	tempsMaxComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeMax();
	tempsActuelComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeActuel();
	float rapportComp3 = 1;
	if (m_vaisseauJoueur.getCompetence(1)->estActive())
	{
		rapportComp3 = tempsActuelComp / tempsMaxComp;
	}
	else if (tempsActuelComp != tempsMaxComp)
	{
		rapportComp3 = (tempsMaxComp - tempsActuelComp) / tempsMaxComp;
	}

	tableauDeBord.actualiserAnimationAvecCompetence(rapportComp1, rapportComp2, rapportComp3, m_vaisseauJoueur.getCompetence(1)->estActive());

	return etat;
}
Ejemplo n.º 13
0
void pacman::update(){
    xpos += xvel;
    ypos += yvel;
    sprite.setPosition(sf::Vector2f(xpos, ypos));
    anspr.setPosition(sf::Vector2f(xpos, ypos));
    collision_box = anspr.getGlobalBounds();
    anspr.update(frame_time.restart());
}
Ejemplo n.º 14
0
 void                    CheckForEnemyCreate()       { if(enemy_create.getElapsedTime() > sf::milliseconds(500))
                                                         {
                                                             int willThereBeEnemy = rand()%10;
                                                             if(willThereBeEnemy >= 4)
                                                                 EnemyGroup.resize(EnemyGroup.size()+1);
                                                             enemy_create.restart();
                                                         }
                                                     }
Ejemplo n.º 15
0
	void update() {
		delta_t = clock.getElapsedTime();
		if (delta_t<max_frame_time)
			sf::sleep(max_frame_time - delta_t);
		delta_t = clock.restart();
		currentFPS = 1 / delta_t.asSeconds();
		delta_t *= time_factor;
	}
Ejemplo n.º 16
0
void Game_Manager::draw()
{
    static sf::Clock render_clock;
    if (render_clock.getElapsedTime().asMilliseconds() < 2) {
        return;
    }
    render_clock.restart();
    m_app->clear();

    if (is_tree)
    {
        tree_background.draw(0, 0);
        skill_button[0].draw();
        skill_button[3].draw();
        skill_button[4].draw();
        skill_button[5].draw();
        skill_button[6].draw();
        skill_button[7].draw();
        skill_button[8].draw();

        energy_text.refill(to_string(myPlayer.getEnergy()));
        energy_text.draw(0, 0, 55);
        if (skill_level < 3)
        {
            empty.draw(0, 500);
        }
        else if (skill_level >= 3)
        {
            empty.draw(0, 700);
        }
    }
    else if (is_menu_visible)
    {
        menu1.draw();
    }
    else
    {
        m_app->setView(m_view2);
        //Changes on the world
        world_sprite.draw(0, 0);
        afficherMapobjet();

        m_app->setView(m_view1);

        //Changes on the HUD, player
        myPlayer.draw();
        light_bar_background.draw(m_screen_x - light_bar_background.get_w(), 0);
        light_bar.draw(m_screen_x + 28 - light_bar_background.get_w(), 40);
        light_bar_grad.draw(m_screen_x - light_bar_background.get_w(), 0);
        energy_text.refill(to_string(myPlayer.getEnergy() ) );
        energy_text.draw(0, 0, 55);
        difficulter_text.refill(to_string(_difficulter-1));
        difficulter_text.draw(0, 100, 55);
    }
    m_app->display();
}
Ejemplo n.º 17
0
	virtual void init()
	
	
	{
		dt=0;
		select_switch = 0.2;
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
	//	darken = sf::RectangleShape(sf::Vector2f(800,400));
		
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))

{
     //error
}
blip.setBuffer(buffer);


		if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;

		t**s.setTexture(title);
		t**s.setOrigin(50,8);
		t**s.setScale(sf::Vector2f(3,3));
		t**s.setPosition(400,100);
		
		sf::FloatRect tempt ;
		
		for(int i =0 ; i<4;i++)
		{
			selector[i].setFont(standard_font);
			selector[i].setCharacterSize(28);
			 
		
		// dla centrowania obiektow
		
			tempt = selector[i].getGlobalBounds();
			selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
			
			selector[i].setPosition(350,150+30*i);
		}
		
		selector[0].setString("Start game");
		selector[1].setString("Info");
		selector[2].setString("Highscores");
		selector[3].setString("Exit");
		
		
		selector[0].setColor(sf::Color(0,127,127));
		
		timer.restart();
		
		};
Ejemplo n.º 18
0
void Boss::comportamiento(Personaje* s, Mapa *map){
    
   
    if(clock_comportamiento.getElapsedTime().asMilliseconds()>4000)      
    { srand(time(NULL));
        int num = rand()%2;
    actitud=num;
    clock_comportamiento.restart();         
    }
    if(actitud==0){
    if(detectada && !muriendo){
        if(!rapido){ this->set_speed(fast); rapido = true;}
        int distancia = this->pos->getX() - s->getPosicion()->getX();
        if(distancia > 0){ 
            if(distancia < 15){ this->attack(s); }
            else{ this->atacando = false; this->orientacion = 1;}
        }
        else{
            if(distancia > -15){ this->attack(s); }
            else{ this->atacando = false; this->orientacion = 0;}
        }
        
        int aux = this->colision_Boss(map);
        if(!(aux == 0 && this->orientacion == 0 || aux == 1 && this->orientacion == 1)){
            this->move();
        }
        else{
            this->pos->setInicial();
            clock_posicion.restart();
        }
    }}
    
    if(actitud==1){
       
     if(detectada){
         this->getPosition()->setInicial();
          clock_posicion.restart();
        //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.5){ this->quieto = false; }
        if(!rapido){ this->set_speed(fast); rapido = true;}
        int distancia = this->pos->getX() - s->getPosicion()->getX();
        if(distancia > 0){
            this->orientacion = 1; 
            this->attack2(s);
            //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.1){ this->orientacion = 0; }
        }
        else{
            this->orientacion = 0; 
            this->attack2(s);
            //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.1){ this->orientacion = 1; }
        }
        //this->move();
     }
    }
    
}
Ejemplo n.º 19
0
	void loop()
	{
		int dt = clock->restart().asMilliseconds();

		while (window->isOpen())
		{
			update(dt);
			draw();
			sf::sleep(sf::milliseconds(1));
		}
	}
Ejemplo n.º 20
0
void MenuStanje::Input()
{
    static sf::Clock clock;
    float deltaT=clock.restart().asSeconds();
	
	if(tranzicija==T_NEMA)
	{
		if(stanje==GLAVNI_MENU)
		{
			if(misOtpusten==true)
			{
				if(startGumb.odabran==true)
				{						
					stanje=NIVO_ODABIR;
				}
				if(oigriGumb.odabran==true)
				{					
					stanje=O_IGRI;
				}
				if(izlazGumb.odabran==true)
				{
					tranzicija=T_FADEOUT;			
				}
				misOtpusten=false;
			}
		}
		if(stanje==NIVO_ODABIR)
		if(misOtpusten==true)
		{
			if(natragGumb.odabran==true)
				stanje=GLAVNI_MENU;
			for(int i=0; i<nivoi.size(); i++)
			{
				if(nivoi[i].gumb.odabran==true)
				{
					RenderLoading();
					nivo_datoteka=nivoi[i].datoteka;
					nivo_datoteka_g=nivoi[i].datoteka_g;
					nivo_trenutni=i;
					igra->SetState(new GameState(), true);
					break;
				}
			}
			misOtpusten=false;
		}
		if(stanje==O_IGRI)
		if(misOtpusten==true)
		{
			if(natragGumb.odabran==true)
				stanje=GLAVNI_MENU;
		}
	}
	misOtpusten=false;	
}
void Engine::playerControl(Player *player, float &delta_time, bool pressed)
{
    sf::Vector2f vectors;
    static sf::Vector2f wektor;
    static sf::Clock clockCrash;
    static sf::Time timerCrash;

    if(player->lifes < -1)
    {
        game_over.setString(stringGameOver+toString(player->score));
        game_over.setPosition((windowSize.x-game_over.getGlobalBounds().width)/2, windowSize.y/2);
        gameOver = true;
    }

    if(crash)
    {
        player->ship.setOutlineColor(red);
        timerCrash = clockCrash.getElapsedTime();

        if(player->lifes >= 0)
            info.setString(stringInfo+toString(player->lifes));

        if(timerCrash >= sf::seconds(5))
        {
            crash = false;
            player->ship.setOutlineColor(cyan);
            clockCrash.restart();
            player->lifes -= 1;
        }
    }

    if(player->ship.getPosition().y < - 3.f)
        player->ship.setPosition(player->ship.getPosition().x, windowSize.y + 3.f);

    else if(player->ship.getPosition().y > windowSize.y + 3.f)
        player->ship.setPosition(player->ship.getPosition().x, - 3.f);

    else if(player->ship.getPosition().x > windowSize.x + 3.f)
        player->ship.setPosition(-3.f, player->ship.getPosition().y);

    else if(player->ship.getPosition().x < - 3.f)
        player->ship.setPosition(windowSize.x + 3.f, player->ship.getPosition().y);

    if(pressed)
    {
        wektor.x = std::sin((player->ship.getRotation()*M_PI) / 180.0f);
        wektor.y = -std::cos((player->ship.getRotation()*M_PI) / 180.0f);
    }

    vectors.x = wektor.x * player->velocity * delta_time;
    vectors.y = wektor.y * player->velocity * delta_time;

    player->ship.move(vectors);
}
Ejemplo n.º 22
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 


		tit.setString("Made by");

		explain.setFont(standard_font);
		explain.setString("Just a bored slacker");
		explain.setCharacterSize(36);
		explain.setPosition(260,320);

		tit.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));

		
		tit.setPosition(400,120);


if (!tex.loadFromFile("gfx/jabslogo.png"))
	
	{
		std::cout<<"Fuckup"<<std::endl;
		}

		spr.setTexture(tex);
		spr.setPosition(334,144);

		
		timer.restart();
		
		};
Ejemplo n.º 23
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 
		score.setFont(standard_font); 

		std::stringstream ss;
		ss << your_score;
		std::string str = ss.str();
		
		
		tit.setString("Congrats! You beat the game\nIt took you:");
		
		score.setString(str + " seconds");


		tit.setCharacterSize(24);
		score.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();
		sf::FloatRect tempr = score.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
		score.setOrigin(sf::Vector2f(tempr.width/2,tempr.height/2));

		
		tit.setPosition(400,150);
		score.setPosition(400,200);

		score.setColor(sf::Color(0,127,127));

		
		timer.restart();
		
		};
Ejemplo n.º 24
0
std::string Comunicare :: interactTastatura(sf::RenderWindow &fereastra, sf::Event &ev)
{
    static sf::Clock timpActiune;
    float timpRamas = timpActiune.getElapsedTime().asSeconds();
    if(ev.type == sf::Event::TextEntered)
        text_dl_tastatura += (char)ev.text.unicode;
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
        if(timpRamas > 0.1)
        {
            timpActiune.restart();
            text_dl_tastatura += '\n';
        }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace) && !text_dl_tastatura.empty())
        text_dl_tastatura.erase(text_dl_tastatura.size()-1,1);
}
Ejemplo n.º 25
0
void App::run()
{
  int frame_counter = 0;
  static sf::Clock clock;

  // Populate the state machine using a template method.
  _populate_states();

  // Set running boolean.
  impl->is_running = true;

  clock.restart();

  // Start the loop
  while (impl->is_running)
  {
    // Process events
    sf::Event event;
    while (impl->app_window->pollEvent(event))
    {
      handle_event(event);
    }

    impl->state_machine->execute();

    // Limit frame rate to 62.5 fps.
    if (clock.getElapsedTime().asMilliseconds() > 16)
    {
      clock.restart();
      impl->app_window->clear();
      impl->state_machine->render(*(impl->app_window.get()), frame_counter);
      impl->app_window->display();
      ++frame_counter;
    }
  }
}
Ejemplo n.º 26
0
float framesPerSecond(sf::Clock & clock) {
    frames_count++;
    if (frames_count >= MAX_FRAME_SAMPLES) {
        fps = ((float)frames_count / (float)clock.getElapsedTime().asMilliseconds()) * 1000;
        clock.restart();
        frames_count = 0;
    }
    //if (clock.getElapsedTime().asMilliseconds() >= 1000) {
    //    clock.restart();
    //    fps = count;
    //    count = 0;
    //}
    fflush(stdout);
    return fps;
}
Ejemplo n.º 27
0
    float step()
    {
        ++mySteps;

        float time(myClock.getElapsedTime().asSeconds());

        if (time >= 1.f)
        {
            std::ostringstream str; str.precision(4);
            str<<mySteps/time;
            setString(str.str());
            mySteps = 0;
            myClock.restart();
        }
        return time;
    }
Ejemplo n.º 28
0
	void update()
	{
		_deltaTime = _deltaClock.restart();
		elapsed = _deltaTime.asSeconds();
		elapsedThisSecond += elapsed;

		framesThisSecond++;
		if (elapsedThisSecond > 1.0f)
		{
			fps = framesThisSecond;
			elapsedThisSecond -= 1.0f;
			framesThisSecond = 0;
		}

		if (_world)
			_world->update();
	}
Ejemplo n.º 29
0
Archivo: hud.cpp Proyecto: dho1/Project
void update (sf::RenderWindow& window, sf::Clock& sclock) 
{
    sf::Time elapsed = sclock.restart();
    ((void) elapsed); // silence warning for now.
    
    sf::Event event;
    while (window.pollEvent(event)) 
    {
        if (event.type == sf::Event::Closed)
            window.close();
        else if (event.type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2f mouse = sf::Vector2f(sf::Mouse::getPosition(window));
        }
    }

    sf::Vector2f mouse = sf::Vector2f(sf::Mouse::getPosition(window));
    for (size_t i = 0; i < shapes.size(); ++i) 
    {
        if (shapes[i].getGlobalBounds().contains(mouse)) 
        {
            if (i != 0)
                shapes[i].setOutlineColor(sf::Color(255, 0,0));
        } else {
            shapes[i].setOutlineColor(sf::Color::White);
        }
    }

    window.clear();

    size_t i;
 
    for (i = 0; i < shapes.size(); ++i) 
    {
        window.draw(shapes[i]);
    }

    for (i = 0; i < lables.size(); ++i) 
    {
        window.draw(lables[i]);
    }

    window.display();
}
Ejemplo n.º 30
0
void MenuBackground::DoLogic()
{
    //Now the background of menu will move always at the same pace
    static sf::Clock frameTime;
    m_view.move(1.2f*frameTime.getElapsedTime().asMilliseconds(),0);
    frameTime.restart();

    //When the view reaches the End of the current level, reset the view and Load a new level
    if(m_view.getCenter().x >= m_tileSize.x * m_levelLength)
    {
        m_view = m_window.getView();

        m_view.setCenter(400,225);

        m_renderTex.setView(m_view);
        Init();
    }

    m_renderTex.setView(m_view);
}