void Player::update(int width, int height) { if (m_position.getX() < 0) { stopX(0); } if (m_position.getX() > (width - m_width)) { stopX(width - m_width); } if (m_position.getY() < 0) { stopY(0); } if (m_position.getY() > (height - m_height)) { stopY(height - m_height); } }
void Player::update() { int pixelsToChangeFrame = 12; Vector2D v0 = m_velocity; if (m_velocity.getX() > 0) { decrementAccelerationX(); } if (m_velocity.getX() < 0) { incrementAccelerationX(); } if (m_velocity.getY() > 0) { decrementAccelerationY(); } if (m_velocity.getY() < 0) { incrementAccelerationY(); } m_velocity += m_acceleration; if (m_velocity.getX()*v0.getX() < 0 || m_velocity.getX() == 0) { stopX(m_position.getX()); } if (m_velocity.getY()*v0.getY() < 0 || m_velocity.getY() == 0) { stopY(m_position.getY()); } if (m_velocity.length() > m_maxVelocity) { m_velocity = m_velocity.normalize()*m_maxVelocity; m_acceleration.setX(0); } m_position += m_velocity + m_acceleration * 1 / 2; m_currentFrame = (abs((int) (m_position - m_lastStop).length()) / pixelsToChangeFrame) % m_spriteNum; }
void QX::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitCode); Q_UNUSED(exitStatus); delete(process); process = NULL; stopX(); appRunScr->pixmap = QPixmap(); #ifdef QTOPIA powerConstraint = QtopiaApplication::Enable; #endif showScreen(QX::ScreenMain); }
void arduinoThread::digitalPinChanged(const int & pinNum) { // note: this will throw tons of false positives on a bare mega, needs resistors if (curState == HOMING) { if (pinNum == X_LIMIT_PIN && ard.getDigital(X_LIMIT_PIN)) { stopX(); homeY(); } if (pinNum == Y_LIMIT_PIN && ard.getDigital(Y_LIMIT_PIN)) { stopY(); homeZ(); } if (pinNum == Z_LIMIT_PIN && ard.getDigital(Z_LIMIT_PIN)) { stopZ(); curState = HOME; } } // if not homing or reseting and the switch is down, it's an error else if (curState != PREPRINT && curState != RESET && curState != HOME && curState != SHOOT_FACE) { if (ard.getDigital(pinNum) == ARD_HIGH){ curState = ERROR; } } }
void QX::runApp(QString filename, QString applabel, bool rotate) { //this->appName = filename; this->appName = applabel; this->rotate = rotate; terminating = false; showScreen(QX::ScreenStarting); if(!QFile::exists("/tmp/.X0-lock")) { xprocess = new QProcess(this); xprocess->setProcessChannelMode(QProcess::ForwardedChannels); QStringList args; args.append("-hide-cursor"); args.append("vt7"); args.append("-dpi"); args.append("128"); xprocess->start("X", args); if(!xprocess->waitForStarted()) { showScreen(QX::ScreenMain); QMessageBox::critical(this, tr("QX"), tr("Unable to start X server")); return; } } Display *dpy; for(int i = 0; i < 3; i++) { dpy = XOpenDisplay(NULL); if(dpy != NULL) { break; } Sleeper::msleep(1000); } if(dpy == NULL) { stopX(); showScreen(QX::ScreenMain); QMessageBox::critical(this, tr("QX"), tr("Unable to connect to X server")); return; } XCloseDisplay(dpy); process = new QProcess(this); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); process->setProcessChannelMode(QProcess::ForwardedChannels); process->start(filename, NULL); if(!process->waitForStarted()) { delete(process); process = NULL; stopX(); showScreen(QX::ScreenMain); QMessageBox::critical(this, tr("QX"), tr("Unable to start") + " " + filename); return; } showScreen(QX::ScreenRunning); }