本文整理汇总了C++中sf::Clock类的典型用法代码示例。如果您正苦于以下问题:C++ Clock类的具体用法?C++ Clock怎么用?C++ Clock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Clock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: periodic_respawn_info_update
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);
}
}
示例2: Update
void Train::Update(const sf::Input &input) {
static sf::Clock clock;
static bool waiting = false;
acceleration = (1/mass) *(push_force - speed * brakes_factor);
speed += acceleration;
position.z += speed;
if (position.z > 900 || position.z < -900) {
position.z = -position.z;
//comingSound.SetPosition(this->position);
comingSound.Play();
StopGas();
}
if (!user_controlled){
if (position.z < -250 && position.z > -300){
StopGas();
Brakes();
}
if (IsStopped() && !waiting){
clock.Reset();
alarm=false;
waiting = true;
printf("\n\n\n waiting\n");
}
if (waiting && clock.GetElapsedTime() > waiting_time) {
Gas();
waiting = false;
printf(" timed out\n");
}
if (waiting && clock.GetElapsedTime() > waiting_time-4 && !alarm) {
alarm=true;
sound.SetBuffer(Buffer);
//sound.SetPitch(0.6);
//sound.SetAttenuation(0.4);
sound.SetRelativeToListener(true);
sound.SetPosition(this->position);
sound.SetMinDistance(100);
sound.Play();
//movmetnSound.SetPosition(this->position);
movmetnSound.Play();
}
light->position = sf::Vector3f(-40.900002,10,position.z + 5) ;
if(camera !=NULL)
camera->SetOrigin(position.x+8.3,position.y+15,position.z);
}else {
if (input.IsKeyDown(sf::Key::Z)) {
push_force = 0.1f;
}else if (input.IsKeyDown(sf::Key::X)){
brakes_factor = 0.05f;
}
}
}
示例3:
bool MultiShootGraphical::update(sf::Clock const& clock)
{
bool ret = MultiShoot::update(clock);
_sprite->setPosition(
_pos.x,
_pos.y
);
if ((clock.getElapsedTime() - _lastUpdate) > _referential)
{
if (_incr)
{
if (_angle >= 30)
_incr = !_incr;
_angle++;
}
else
{
if (_angle <= -30)
_incr = !_incr;
_angle--;
}
_sprite->setRotation(_angle);
_lastUpdate = clock.getElapsedTime();
}
return ret;
}
示例4: broadcast_ping_data
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);
}
示例5: RenderSceneCB
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();
}
示例6: periodic_team_broadcast
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);
}
}
示例7: update
//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;
}
}
示例8: getTime
float GameTime::getTime()
{
static sf::Clock gameTime;
sf::Time time = gameTime.getElapsedTime();
return (time.asSeconds());
}
示例9: gameLoop
/**
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;
}
示例10: Turing_StdlibSFML_PeriodicCallback
// called every couple of lines. Use it to check for events
void Turing_StdlibSFML_PeriodicCallback() {
// check every quarter of a second. This does make input delayed.
// It only stops the system from deeming us unresponsive
if(WinMan && eventClock.GetElapsedTime() > 0.5) {
WinMan->surface();
eventClock.Reset();
}
}
示例11: draw
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();
}
示例12: getDelta
unsigned long getDelta()
{
static sf::Clock clock; // starts the clock
static unsigned long last, now = clock.getElapsedTime().asMilliseconds();
last = now;
now = clock.getElapsedTime().asMilliseconds();
return (now-last);
}
示例13: playerControl
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);
}
示例14: draw
void draw(sf::Clock &Clock)
{
// Apply move direction
if (dir == 0)
glRotatef(Clock.GetElapsedTime() * 90, 1.f, 0.f, 0.f);
else if (dir == 1)
glRotatef(Clock.GetElapsedTime() * -90, 1.f, 0.f, 0.f);
else if (dir == 2)
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 1.f, 0.f);
else if (dir == 3)
glRotatef(Clock.GetElapsedTime() * -90, 0.f, 1.f, 0.f);
// Draw a cube
glBegin(GL_QUADS);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
}
示例15: render
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();
}