Exemplo n.º 1
0
void GameScreen::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Space && !spacePressed)
    {
        ball->object->start();
        spacePressed = true;
        time->start(1000);
        emit(eventTriggered("Spacebar pressed"));
    }
    else if (event->key() == Qt::Key_Right && !cheatModeActive)
    {
        paddle->setDirection(EAST);
        paddle->object->start();
    }
    else if (event->key() == Qt::Key_Left && !cheatModeActive)
    {
        paddle->setDirection(WEST);
        paddle->object->start();
    }
    else if (event->key() == Qt::Key_C)
    {
        cheatModeActive ? cheatModeActive = false : cheatModeActive = true;
        cheatModeActive ? emit(eventTriggered("Cheat mode activated")) : emit(eventTriggered("Cheat mode deactivated"));
        toggleCheatMode(cheatModeActive);
        this->hasFocus();
    }
}
Exemplo n.º 2
0
void plugin::timeout() {
    QMutableMapIterator<QDateTime, EventTimeStructure>  i(mEvents);
    while(i.hasNext()) {
        i.next();
        if (abs(QDateTime::currentDateTime().secsTo(i.key())) < 10) {
            plugin::EventTimeStructure ts = i.value();
            qDebug()<<"Alarm triggered"<<ts.sceneid;
            eventTriggered(ts.eventid, ts.sceneid);
            i.remove();
            if (ts.periodic)
                calculate_next_periodic_timeout(ts);
        }
    }
    setupTimer();
}
Exemplo n.º 3
0
void GameScreen::createPaddle()
{
    paddle = new Label(this, "paddle");
    paddle->setPixmap(*paddleIcon);
    int width = (this->width() - (this->width() - ui->rightLine->pos().x()));
    paddle->setGeometry((width / 2) - (PADDLEWIDTH / 2), ui->bottomLine->pos().y() - 5, PADDLEWIDTH, PADDLEHEIGHT);
    paddle->setEnabled(false);
    Timer *tmr = new Timer(paddle, "paddle");
    paddle->object = tmr;
    tmr->object = paddle;
    tmr->setInterval(paddleSpeed);
    connect(tmr, SIGNAL(timeout()), tmr, SLOT(shiftPaddle()));
    paddle->show();

    emit(eventTriggered("Paddle created"));
}
Exemplo n.º 4
0
void GameScreen::createBall()
{
    ball = new Label(this, "ball");
    ball->setPixmap(*ballIcon);
    int width = (this->width() - (this->width() - ui->rightLine->pos().x()));
    ball->setGeometry((width / 2) - (BALLWIDTH / 2), paddle->pos().y() - PADDLEHEIGHT, BALLWIDTH, BALLHEIGHT);
    ball->setEnabled(false);
    ball->show();
    Timer *timer = new Timer(ball, "ball");
    ball->object = timer;
    timer->object = ball;
    timer->setInterval(ballSpeed);

    connect(timer, SIGNAL(lifeLost()), this, SLOT(decrementLives()));
    connect(timer, SIGNAL(gameWon()), this, SLOT(gameIsWon()));
    emit(eventTriggered("Ball created"));
}
int QtScriptedStateMachine::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QtStateMachine::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: eventTriggered((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 1: postNamedEvent((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 2: executeScript((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 3: registerSession(); break;
        case 4: unregisterSession(); break;
        default: ;
        }
        _id -= 5;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QUrl*>(_v) = baseUrl(); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setBaseUrl(*reinterpret_cast< QUrl*>(_v)); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 6
0
GameScreen::GameScreen(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GameScreen)
{
    ui->setupUi(this);
    tmp = new QMainWindow(this);
    paddleIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/paddle.png");
    ballIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/white_ball.png");
    gameOverIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/gameover.png");
    gameOverlay = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/background.jpg");
    gameWonIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/youwin.jpg");
    overlayLbl = new QLabel(this);
    overlayLbl->setPixmap(*gameOverlay);
    overlayLbl->setGeometry(0, ui->menuBar->height(), this->width() - (this->width() - ui->rightLine->pos().x()), this->height() - (this->height() - ui->bottomLine->pos().y()));

    connect(this, SIGNAL(eventTriggered(QString)), this, SLOT(writeEvent(QString)));
    connect(this, SIGNAL(gameEnded()), this, SLOT(gameOver()));

    diff = EASY;
    level = 1;
    newLevel(level);
    createActions();
    createMenus();
    createPaddle();
    createBall();
    numLives = 3;

    time = new Timer(this, "time");
    connect(time, SIGNAL(timeout()), this, SLOT(decrementTimer()));
    cheatModeActive = false;
    spacePressed = false;
    score = 0;
    createBlocks();
    eventLogFullSizePos = new QPoint(310, 10);
    eventLogHalfSizePos = new QPoint(310, 200);
    hideCheatMode();
    setLivesText(numLives);
    setTimeText(timeLeft);
    setLevelText(level);
    setScoreText(score);
}
Exemplo n.º 7
0
/*! Connected to the DeviceManager's emitEvent signal. Events received in
    here will be evaluated by the \l{RuleEngine} and the according \l{Action}{Actions} are executed.*/
void GuhCore::gotEvent(const Event &event)
{
    // first inform other things about it.
    emit eventTriggered(event);

    // Now execute all the associated rules
    foreach (const Action &action, m_ruleEngine->evaluateEvent(event)) {
        qDebug() << "executing action" << action.actionTypeId();
        DeviceManager::DeviceError status = m_deviceManager->executeAction(action);
        switch(status) {
        case DeviceManager::DeviceErrorNoError:
            break;
        case DeviceManager::DeviceErrorSetupFailed:
            qDebug() << "Error executing action. Device setup failed.";
            break;
        case DeviceManager::DeviceErrorInvalidParameter:
            qDebug() << "Error executing action. Invalid action parameter.";
            break;
        default:
            qDebug() << "Error executing action:" << status;
        }
    }
}
Exemplo n.º 8
0
void ZEventListenerParameter::sendEvent(QEvent *e, int w, int h)
{
  if (!isAcceptingEvent())
    return;

  if (QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(e)) {
    bool accept = false;
    for (int i=0; i<m_mouseEvents.size(); i++) {
      accept = true;
      accept &= (mouseEvent->modifiers() == m_mouseEvents[i].modifiers);
      accept &= (mouseEvent->type() == m_mouseEvents[i].type);
      if (mouseEvent->type() == QEvent::MouseMove)
        accept &= ((mouseEvent->buttons() == m_mouseEvents[i].buttons));
      else
        accept &= ((mouseEvent->button() == m_mouseEvents[i].buttons));
      if (accept)
        break;
    }
    if (accept) {
      emit eventTriggered(e, w, h);
      emit mouseEventTriggered(mouseEvent, w, h);
      // now all the slots have return
      if (m_sharing)
        e->ignore();
    }
  } else if (QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(e)) {
    bool accept = false;
    for (int i=0; i<m_mouseEvents.size(); i++) {
      accept = true;
      accept &= (wheelEvent->modifiers() == m_mouseEvents[i].modifiers);
      accept &= (wheelEvent->type() == m_mouseEvents[i].type);
      accept &= ((wheelEvent->buttons() == m_mouseEvents[i].buttons));
      if (accept)
        break;
    }
    if (accept) {
      emit eventTriggered(e, w, h);
      emit wheelEventTriggered(wheelEvent, w, h);
      // now all the slots have return
      if (m_sharing)
        e->ignore();
    }
  } else if (QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(e)) {
    bool accept = false;
    for (int i=0; i<m_keyEvents.size(); i++) {
      accept = true;
      accept &= (keyEvent->modifiers() == m_keyEvents[i].modifiers);
      accept &= (keyEvent->type() == m_keyEvents[i].type);
      accept &= (keyEvent->key() == m_keyEvents[i].key);
      if (accept)
        break;
    }
    if (accept) {
      emit eventTriggered(e, w, h);
      emit keyEventTriggered(keyEvent, w, h);
      // now all the slots have return
      if (m_sharing)
        e->ignore();
    }
  }
}