void Oh_Oh_Robot::escapeLight(){ LDR_getValues(); int vL=map(LDR_sensR,0,LDR_thresholdR*0.9,255,95); int vR=map(LDR_sensL,0,LDR_thresholdL*0.9,255,95); LDR_sensR>LDR_thresholdR?vL=0:0; LDR_sensL>LDR_thresholdL?vR=0:0; //valueL<LDR_thresholdL*0.9?speedL=255:speedL=0; //valueR<LDR_thresholdR*0.9?speedR=255:speedR=0; backward(); changeSpeed(vL,1); changeSpeed(vR,2); }
void Ship::update(WorldInterface& world) { if (m_health <= 0 && m_status == dying){ m_status = dead; world.addExplosion(getPositionPrevious(), EXPLOSION_SIZE, 0); } if (m_status == alive){ if (isUnitAiSet()){ double duration = TimeSystem::getFrameDuration(); m_coordinate.rotateToVector(m_desired_velocity, duration*m_rotation_rate); changeSpeed(m_desired_velocity.getNorm(), duration*m_acceleration); if (m_fire_bullet_desired && isBulletReady()){ world.addBullet(getPosition(), m_coordinate.getForward(), m_id); m_fire_bullet_desired = false; reloadBullet(); } } updateBasic(); m_reloadTimer.update(); } else if (m_health > 0 && m_status == dead){ m_status = alive; Vector3 position = m_coordinate.getPosition(); position -= 500 * m_coordinate.getForward(); m_coordinate.setPosition(position); } }
//DefaultSettings loader void SettingsUI::setupSettings(Settings *s){ settings = s; if(s->getSetting("GPS") == "true") ui->checkBox_GPS->setChecked(true); else ui->checkBox_GPS->setChecked(false); if(s->getSetting("Anenometer") == "true") ui->checkBox_Anenometer->setChecked(true); else ui->checkBox_Anenometer->setChecked(false); if(s->getSetting("Compass") == "true") ui->checkBox_Compass->setChecked(true); else ui->checkBox_Compass->setChecked(false); if(s->getSetting("Clock") == "true") ui->checkBox_Clock->setChecked(true); else ui->checkBox_Clock->setChecked(false); double boatPosLon = settings->getSetting("boatPosLongitude").toDouble(); double boatPosLat = settings->getSetting("boatPosLatitude").toDouble(); int time = s->getSetting("Timer").toInt(); ui->boatPosLonDSpinBox->setValue(boatPosLon); ui->boatPosLatDSpinBox->setValue(boatPosLat); ui->horizontalSlider_velocity->setValue(time); changeSpeed(time); }
void Motor::stopSmoothly() { int i; speed = getSpeed(); for (i = speed; i >= 0; i = i - COUNT_CONST) { changeSpeed(i); delay(COUNT_CONST * damping); speed = i; pwm = speed * mean_speed / 100; } lockMotor(); }
void VideoPlayer::ResetVideoPlayer() { if (config->get("SPEED")=="NORMAL") { ui->FastButton->setChecked(true); changeSpeed(1); } else if (config->get("SPEED")=="SLOW") { ui->SlowButton->setChecked(true); changeSpeed(0.5); } else { ui->VerySlowButton->setChecked(true); changeSpeed(0.25); } if (config->get("MIRRORED")=="TRUE") { ui->MirrorButton->setChecked(true); Mirrored=true; } else { ui->NormalButton->setChecked(true); Mirrored=false; } ui->SpeedControl->setEnabled(false); ui->MirrorControl->setEnabled(false); videoWidget.hide(); player.stop(); CurrentSentence=""; }
int CockpitGrid::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QFrame::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: changeSpeed(); break; case 1: changeGradient(); break; case 2: changeAngle(); break; default: ; } _id -= 3; } return _id; }
void Motor::startSmoothly(int Speed) { if (Speed > 100) Speed = 100; if (Speed < -100) Speed = -100; int i; if (Speed >= 0) { digitalWrite(dir1_pin, HIGH); digitalWrite(dir2_pin, LOW); } else { digitalWrite(dir1_pin, LOW); digitalWrite(dir2_pin, HIGH); } for (i = 0; i <= Speed; i = i + COUNT_CONST) { changeSpeed(i); delay(COUNT_CONST * damping); speed = i; pwm = speed * mean_speed / 100; } }
void GameEngine::repaintMovingObjects() { m_bar.repaint(); foreach (Ball *ball, m_balls) { ball->repaint(); } foreach (Gift *gift, m_gifts) { if (!gift->isVisible()) { continue; } gift->repaint(); } // avoid infinite loops of the ball ++randomCounter; if (randomCounter == 1024) { randomCounter = 0; foreach (Ball *ball, m_balls) { if (qrand() % 2) { ball->directionX += 0.002; } else { ball->directionY += 0.002; } } // increase the speed a little // if there is at least one ball moving // and the game isn't paused bool ballMoving = false; foreach (Ball *ball, m_balls) { if (!ball->toBeFired) { ballMoving = true; break; } } if (ballMoving && !gameIsPaused()) { changeSpeed(AUTO_SPEED_INCREASE); } }
QwtDial *CockpitGrid::createDial( int pos ) { QwtDial *dial = NULL; switch( pos ) { case 0: { d_clock = new QwtAnalogClock( this ); #if 0 // disable minor ticks d_clock->scaleDraw()->setTickLength( QwtScaleDiv::MinorTick, 0 ); #endif const QColor knobColor = QColor( Qt::gray ).light( 130 ); for ( int i = 0; i < QwtAnalogClock::NHands; i++ ) { QColor handColor = QColor( Qt::gray ).light( 150 ); int width = 8; if ( i == QwtAnalogClock::SecondHand ) { handColor = Qt::gray; width = 5; } QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle( QwtDialSimpleNeedle::Arrow, true, handColor, knobColor ); hand->setWidth( width ); d_clock->setHand( static_cast<QwtAnalogClock::Hand>( i ), hand ); } QTimer *timer = new QTimer( d_clock ); timer->connect( timer, SIGNAL( timeout() ), d_clock, SLOT( setCurrentTime() ) ); timer->start( 1000 ); dial = d_clock; break; } case 1: { d_speedo = new SpeedoMeter( this ); d_speedo->setScaleStepSize( 20.0 ); d_speedo->setScale( 0.0, 240.0 ); d_speedo->scaleDraw()->setPenWidth( 2 ); QTimer *timer = new QTimer( d_speedo ); timer->connect( timer, SIGNAL( timeout() ), this, SLOT( changeSpeed() ) ); timer->start( 50 ); dial = d_speedo; break; } case 2: { d_ai = new AttitudeIndicator( this ); d_ai->scaleDraw()->setPenWidth( 3 ); QTimer *gradientTimer = new QTimer( d_ai ); gradientTimer->connect( gradientTimer, SIGNAL( timeout() ), this, SLOT( changeGradient() ) ); gradientTimer->start( 100 ); QTimer *angleTimer = new QTimer( d_ai ); angleTimer->connect( angleTimer, SIGNAL( timeout() ), this, SLOT( changeAngle() ) ); angleTimer->start( 100 ); dial = d_ai; break; } } if ( dial ) { dial->setReadOnly( true ); dial->setLineWidth( 4 ); dial->setFrameShadow( QwtDial::Sunken ); } return dial; }
// mouse event that calls all functions pertaining to mouse clicks void GameWindow::mousePressEvent(QMouseEvent *e){ int x = e->x(); int y = e->y(); // if a empty space is clicked, get coordinates to select tower choice if(towerPick){ for(size_t i = 0, n = CONSTANTS::B_ROWS; i < n; i++){ for(size_t j = 0, n = CONSTANTS::B_COLS; j < n; j++){ if(gameBoard[i][j].isClicked){ // pick squirrel if(x>gameBoard[i][j].xC-CONSTANTS::T_SIZE && x<gameBoard[i][j].xC && y<gameBoard[i][j].yC && y>gameBoard[i][j].yC-CONSTANTS::T_SIZE && money >= GAME_CONST::TOWER1COST){ towerPick = false; gameBoard[i][j].isClicked = false; gameBoard[i][j].set_air(2); money -= GAME_CONST::TOWER1COST; } // pick porcupine else if(x>gameBoard[i][j].xC+CONSTANTS::T_SIZE && x<gameBoard[i][j].xC+(CONSTANTS::T_SIZE*2) && y<gameBoard[i][j].yC && y>gameBoard[i][j].yC-CONSTANTS::T_SIZE && money >= GAME_CONST::TOWER2COST ){ towerPick = false; gameBoard[i][j].isClicked = false; gameBoard[i][j].set_air(3); money -= GAME_CONST::TOWER2COST; } // pick spider else if(x>gameBoard[i][j].xC-CONSTANTS::T_SIZE && x<gameBoard[i][j].xC && y<gameBoard[i][j].yC+(CONSTANTS::T_SIZE*2) && y>gameBoard[i][j].yC+CONSTANTS::T_SIZE && money >= GAME_CONST::TOWER3COST ){ towerPick = false; gameBoard[i][j].isClicked = false; gameBoard[i][j].set_air(4); money -= GAME_CONST::TOWER3COST; } // pick frog else if(x>gameBoard[i][j].xC+CONSTANTS::T_SIZE && x<gameBoard[i][j].xC+(CONSTANTS::T_SIZE*2) && y<gameBoard[i][j].yC+(CONSTANTS::T_SIZE*2) && y>gameBoard[i][j].yC+CONSTANTS::T_SIZE && money >= GAME_CONST::TOWER4COST ){ towerPick = false; gameBoard[i][j].isClicked = false; gameBoard[i][j].set_air(5); money -= GAME_CONST::TOWER4COST; } // else close pick menu else{ towerPick = false; gameBoard[i][j].isClicked = false; } } } } }else{ // select empty tile for(size_t i = 0, n = CONSTANTS::B_ROWS; i < n; i++){ for(size_t j = 0, n = CONSTANTS::B_COLS; j < n; j++){ if(!towerClicked && gameBoard[i][j].airID==-1 && gameBoard[i][j].groundID ==0 && y>i*CONSTANTS::T_SIZE && y<(i+1)*CONSTANTS::T_SIZE && x>(j)*CONSTANTS::T_SIZE && x<(j+1)*CONSTANTS::T_SIZE){ towerPick = true; gameBoard[i][j].isClicked = true; } } } // UPGRADING if(towerClicked ){ for(size_t i = 0, n = CONSTANTS::B_ROWS; i < n; i++){ for(size_t j = 0, n = CONSTANTS::B_COLS; j < n; j++){ // sell tower if(gameBoard[i][j].isClicked){ if(x>gameBoard[i][j].xC-40 && x<gameBoard[i][j].xC+10 && y<gameBoard[i][j].yC-CONSTANTS::T_SIZE/2+50 && y>gameBoard[i][j].yC-CONSTANTS::T_SIZE/2 ){ towerClicked = false; gameBoard[i][j].isClicked = false; gameBoard[i][j].sellTower(money); } // cancel if(x>gameBoard[i][j].xC+10 && x<gameBoard[i][j].xC+65 && y<gameBoard[i][j].yC+CONSTANTS::T_SIZE+50 && y>gameBoard[i][j].yC+CONSTANTS::T_SIZE ){ towerClicked = false; gameBoard[i][j].isClicked = false; } // upgrade if(x>gameBoard[i][j].xC+55 && x<gameBoard[i][j].xC+105 && y<gameBoard[i][j].yC-CONSTANTS::T_SIZE/2+50 && y>gameBoard[i][j].yC-CONSTANTS::T_SIZE/2){ towerClicked = false; gameBoard[i][j].isClicked = false; if(gameBoard[i][j].upgradeCost<=money){ money -= gameBoard[i][j].upgradeCost; gameBoard[i][j].upgrade(); } } } } } } else{ // DETECTS WAVE STARTER icon for(size_t i = 0, n = CONSTANTS::B_ROWS; i < n; i++){ if(gameBoard[i][0].groundID==1){ if(!waves[wave_num].started&&x<CONSTANTS::T_SIZE&&x>0&&y>i*CONSTANTS::T_SIZE && y < (i+1)*CONSTANTS::T_SIZE ){ waves[wave_num].start(); } } } // CLICK ON TOWER TO UPGRADE for(size_t i = 0, n = CONSTANTS::B_ROWS; i < n; i++){ for(size_t j = 0, n = CONSTANTS::B_COLS; j < n; j++){ if(y>i*CONSTANTS::T_SIZE&&y<(i+1)*CONSTANTS::T_SIZE &&x>(j)*CONSTANTS::T_SIZE&&x<(j+1)*CONSTANTS::T_SIZE && gameBoard[i][j].airID!=-1 && gameBoard[i][j].groundID==0&&!towerClicked) { gameBoard[i][j].isClicked = true; towerClicked = true; } } } } } // PAUSE GAME if(x > (CONSTANTS::T_SIZE*11) && x < (CONSTANTS::T_SIZE*11)+50 && y > 8*CONSTANTS::T_SIZE+15 && y < 8*CONSTANTS::T_SIZE+15+50){ started = false; } // IF PAUSED, OPEN MENU if(!started){ // RESUME if(x > 350 && x < 500 && y > 200 && y < 275){ started = true; timer->start(); } // QUITS LEVEL, TAKES BACK TO LEVEL PICK else if (x > 350 && x < 500 && y > 300 && y < 375){ emit quitGame(); this->close(); } // RESTART else if (x > 350 && x < 500 && y > 400 && y < 475){ newGame(levelPicked,diff); } } // CHANGE SPEED OF GAME if(x > 10*CONSTANTS::T_SIZE && x < 10*CONSTANTS::T_SIZE+50 && y > 8*CONSTANTS::T_SIZE+15 && y < 8*CONSTANTS::T_SIZE+15+50 ){ changeSpeed(); } }
void VideoPlayer::on_VerySlowButton_clicked() { changeSpeed(0.25); }
void VideoPlayer::on_SlowButton_clicked() { changeSpeed(0.5); }
void VideoPlayer::on_FastButton_clicked() { changeSpeed(1); }