Exemplo n.º 1
0
  void perform_logic() 
  {
    const float time_passed = m_chrono.seconds();
    const float time_step = time_passed - m_time_passed;
    m_time_passed = time_passed;
 
    // without a multiplier, this will rotate a full turn after ~6.28s
    // this rotates clockwise of c-clockwise depending on m_turn_????
    //m_tank.turn_left((m_turn_left - m_turn_right) * time_step);
    m_tank.move_lr((m_turn_left - m_turn_right) * time_step * 100.0f);
    
    // without the '100.0f', it would move at ~1px/s
    m_tank.move_ud((m_forward - m_backward) * time_step * 100.0f);

    if(m_fire) 
    {
      m_fire = false;
      m_bullets.push_back(m_tank.fire());
    }

    // move bullets
    for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end(); ++it)
      (*it)->move_ud(time_step * 200.0f);

    // remove off screen bullets for perfrmance boost
    for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end();) {
      const Point2f &p = (*it)->get_position();
 
      if(p.x < -10.0f || p.x > 10.0f + get_Window().get_width() ||
         p.y < -10.0f || p.y > 10.0f + get_Window().get_height())
      {
        delete *it;
        it = m_bullets.erase(it);
      }
      else
        ++it;
    }
  }