Exemple #1
0
Player::Player()
{
    isPlayer = true;
    isBot = false;

    timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(keyActions()));

    keyDelay = 20; // задержка между действиями клавиш

    wou = false;

    // нажатые кнопки
    mf = mb = rr = rl = hr = hl = fr = false;

    // стрельба
    fireTime = 2000;

    alive = true;
    isFiring = 0;

    defaultTank();

    game->centerOn(this);

    //звук перезарядки
    bulletready = new QMediaPlayer();
    bulletready->setMedia(QUrl("qrc:/sounds/sounds/tank/reload.mp3"));
    bulletready->setVolume(game->veffects);

    // выделить танк на сцене - для действий с ним
    setFlag(QGraphicsItem::ItemIsFocusable);
    setFocus();
}
Exemple #2
0
/**
 * The loop for the program.
 */
void loop(int n) {
   keyActions();
   long old_start_loop = start_loop;
   start_loop = (long) glutGet(GLUT_ELAPSED_TIME);
   float dt = (float) (start_loop - old_start_loop);
   dt /= d_time;
   
   if (is_screen_saver) {
      screenSaver(dt);
   }

   glutWarpPointer(GW / 2, GH / 2); //Cursor At Center of Screen
   /* Allows movement */
   lastx = p2wx(GW / 2);
   lasty = p2wy(g2py(GH / 2));
   //lasty = p2wy(GH / 2);

   /* Updates all objects in world */
   for (unsigned int i = 0; i < objs.size(); i++) {
      objs[i]->update(dt);
   }

   glutPostRedisplay();
   glutTimerFunc(d_time, loop, d_time);
}
Exemple #3
0
void Player::onKey()
{
    keyActions();
    emit KeyPressed();

    if (alive == true && (mf == true || mb == true || rl == true || rr == true || hl == true || hr == true || fr == true ||
                          fireReady == false || tankhrotate->state() == QMediaPlayer::PlayingState || out == true))
    {
        timer->start(keyDelay);
    }
}