コード例 #1
0
ファイル: BoxCar.cpp プロジェクト: shtras/BlindAM
void BoxCar::handleEvent( SDL_Event& event )
{
  switch (event.type)
  {
  case SDL_QUIT:
    quit();
    break;
  case SDL_MOUSEBUTTONDOWN:
  case SDL_MOUSEBUTTONUP:
  case SDL_MOUSEMOTION:
    Renderer::getInstance().handleGUIEvent(event);
    break;
  case SDL_KEYDOWN:
    Renderer::getInstance().handleKeyboardEvent(event);
    if (event.key.keysym.sym == SDLK_SPACE) {
      togglePause();
    }
    if (Renderer::getInstance().hasKeyboardListener()) {
      break;
    }
    if (event.key.keysym.sym == SDLK_a) {
      speedUp();
    }
    if (event.key.keysym.sym == SDLK_d) {
      speedDown();
    }
    break;
  case SDL_VIDEORESIZE:
    Renderer::getInstance().resize(event.resize.w, event.resize.h);
    break;
  default:
    break;
  }
}
コード例 #2
0
void MainWindow::createMenus()
{
	exitAct = new QAction(tr("E&xit"), this);
    exitAct->setShortcut(tr("Ctrl+Q"));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

	startAct = new QAction(tr("Start animation"), this);
    startAct->setShortcut(tr("Ctrl+p"));
    connect(startAct, SIGNAL(triggered()), this, SLOT(startAnimation()));
	
	stopAct = new QAction(tr("St&op animation"), this);
    stopAct->setShortcut(tr("Ctrl+l"));
    connect(stopAct, SIGNAL(triggered()), this, SLOT(stopAnimation()));
    
    toggleF = new QAction(tr("Toggle flying"), this);
    toggleF->setShortcut(tr("Ctrl+t"));
    connect(toggleF, SIGNAL(triggered()), this, SLOT(toggleFly()));
    
    turnL = new QAction(tr("Turn left"), this);
    turnL->setShortcut(tr("Ctrl+a"));
    connect(turnL, SIGNAL(triggered()), this, SLOT(turnLeft()));
    
    turnR = new QAction(tr("Turn right"), this);
    turnR->setShortcut(tr("Ctrl+d"));
    connect(turnR, SIGNAL(triggered()), this, SLOT(turnRight()));
    
    turnU = new QAction(tr("Turn up"), this);
    turnU->setShortcut(tr("Ctrl+w"));
    connect(turnU, SIGNAL(triggered()), this, SLOT(turnUp()));
    
    turnD = new QAction(tr("Turn down"), this);
    turnD->setShortcut(tr("Ctrl+s"));
    connect(turnD, SIGNAL(triggered()), this, SLOT(turnDown()));
    
    speedU = new QAction(tr("Speed up"), this);
    speedU->setShortcut(tr("Ctrl+i"));
    connect(speedU, SIGNAL(triggered()), this, SLOT(speedUp()));

    speedD = new QAction(tr("Speed down"), this);
    speedD->setShortcut(tr("Ctrl+k"));
    connect(speedD, SIGNAL(triggered()), this, SLOT(speedDown()));
    
    fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(exitAct);

    animationMenu = menuBar()->addMenu(tr("&Animation"));
    animationMenu->addAction(startAct);
    animationMenu->addAction(stopAct);
    
    flyingMenu = menuBar()->addMenu(tr("&Flying"));
    flyingMenu->addAction(toggleF);
    flyingMenu->addAction(turnL);
    flyingMenu->addAction(turnR);
    flyingMenu->addAction(turnU);
    flyingMenu->addAction(turnD);
    flyingMenu->addAction(speedU);
    flyingMenu->addAction(speedD);
}
コード例 #3
0
void RobotController::driveForward()
{
    if (isDrivingBackward()) 
    {
        stop();
    }
    speedUp();
    setMotorsSpeed_currentSpeed();
    setMotorsRun_FORWARD();
}
コード例 #4
0
void RobotController::driveBackward()
{
    if (isDrivingForward()) 
    {
        this->stop();
    }
    speedUp();
    setMotorsSpeed_currentSpeed();
    setMotorsRun_BACKWARD();
}
コード例 #5
0
ファイル: console.cpp プロジェクト: NedFreed/master_clock
//_____________________________________
// Read user input and act on it
bool controlMode( char ch ) {
    static int arg = -1;
    int retval = false;
    if (isdigit( ch )) {
      if (arg < 0) arg = 0;
      arg = arg * 10 + (ch - '0');
      return false;
    }
    switch ( ch ) {
    // 'N' triggers the NTP protocol manually
    case 'N': case 'n': triggerNtp() ; retval = true ; break ;

    // Left-arrow (Less-Than) slows down the clock for simulation runs
    case '<': case ',': slowDown() ;   retval = true ; break ;

    // Right-arrow (Greater-Than) speeds up the clock for simulation runs
    case '>': case '.': speedUp() ;    retval = true ; break ;

    // PLUS advances the digital clock minute
    case '+': case '=': incMinutes() ; retval = true ; break ;

    // MINUS decrements the digital clock minute
    case '_': case '-': decMinutes() ; retval = true ; break ;

    // H, M, S set hours, minutes, seconds
    case 'H': case 'h': if (arg >= 0) setHours(arg);                retval = true ;      break ;
    case 'M': case 'm': if (arg >= 0) setMinutes(arg);              retval = true ;      break ;
    case 'S': case 's': if (arg >= 0) setSeconds(arg); syncTime() ; retval = true ;      break ;

    // 'Z' resets the digital clock seconds
    case 'z': case 'Z': setSeconds(0) ; syncTime() ; return true ;

    // A, B and C manually force the A/B output pulses but do not affect the internal clock
    // A and B add to the force count for the A and B signals.  C adds to both signals.
    case 'A': case 'a': if (arg < 0) arg = 1 ;    sendPulsesA(arg) ;                     break ;
    case 'B': case 'b': if (arg < 0) arg = 1 ;    sendPulsesB(arg) ;                     break ;
    case 'C': case 'c': if (arg < 0) arg = 1 ;    sendPulsesA(arg) ;  sendPulsesB(arg) ; break ;
    case 'D': case 'd': if (arg < 0) arg = 1 ;    sendPulsesD(arg) ;                     break ;
    case 'E': case 'e':                           sendPulsesE(1)   ;                     break ;

    case 'f':                                     setState(LOW);                         break ;
    case 'F':                                     setState(HIGH);                        break ;

    case 'I': case 'i': if (arg < 0) arg = 60*60; clockHold(arg, arg) ;                  break ;
    case 'U': case 'u': if (arg < 0) arg = 60*60; clockHold(arg, 0) ;                    break ;
    case 'V': case 'v': if (arg < 0) arg = 60*60; clockHold(0, arg) ;                    break ;
    default: break;
  }
  arg = -1;
  return retval ;
}
コード例 #6
0
ファイル: acc.c プロジェクト: frmi/nxt-car-assists
void ACC(float actualTimeBetweenVehicles, S32 distanceToVehicle, float leadVehicleVelocity)
{
    if(actualTimeBetweenVehicles > MAXIMUM_TIME_BETWEEN_VEHICLES) //No vehicle to follow or too far away. (Zone A)
    {
        controlMotors(INITIAL_MOTOR_POWER, BRAKE_OFF);
        /*Drive accordingly to normal Cruise Control*/
    }
    else if(actualTimeBetweenVehicles < MINIMUM_TIME_BETWEEN_VEHICLES) //Vehicle too close. (Zone E)
    {
        //brake();
        slowDown(MOTOR_POWER_ADJUST);
    }
    else
    {
        if(leadVehicleVelocity > vehicle.vFront)
        {//Vehicle in front drives faster than set speed.
            if((DESIRED_TIME_BETWEEN_VEHICLES - MAXIMUM_DEVIATION) > actualTimeBetweenVehicles &&
                MINIMUM_TIME_BETWEEN_VEHICLES < actualTimeBetweenVehicles)
            {//Vehicle in front is too close to cruise but not close enought to brake. (Zone D)
                slowDown(MOTOR_POWER_ADJUST);
            }
            else
            {  //(Zone C)
                maintainDistance();
            }
        }
        else //Vehicle in front drives slower than set speed.
        {
            if((DESIRED_TIME_BETWEEN_VEHICLES + MAXIMUM_DEVIATION) >= actualTimeBetweenVehicles &&
               (DESIRED_TIME_BETWEEN_VEHICLES - MAXIMUM_DEVIATION) <= actualTimeBetweenVehicles)
            {//Within tolerance. (Zone C)
                maintainDistance();
            }
            else
            {//(Zone B)
                speedUp(MOTOR_POWER_ADJUST);
            }
        }
        acc.firstDistanceMeasurement = acc.secondDistanceMeasurement;
    }
}
コード例 #7
0
ファイル: worker.cpp プロジェクト: Ashatta/tools
void Worker::readEntry()
{
	if (mStream.atEnd()) {
		PRINT("Done.\n");
		return;
	}

	++mCurrentLine;
	mCurrentEntry = LogEntry(mStream.readLine());
	if (mCurrentEntry.timestamp() < mLastTimestamp) {
		PRINT(QString("Timestamp on the line %1 is invalid. Terminating.\n").arg(QString(mCurrentLine)));
		return;
	}

	qint64 const lastTimestamp =  mLastTimestamp
			? mLastTimestamp
			: mCurrentEntry.timestamp() - timeToWaitForLoaded;
	qint64 const toWait = speedUp(mCurrentEntry.timestamp() - lastTimestamp);
	mLastTimestamp = mCurrentEntry.timestamp();
	QTimer::singleShot(toWait, this, SLOT(invokeEntry()));
}
コード例 #8
0
ファイル: Tram.cpp プロジェクト: yoms/Project-STR-ISI
void Tram::run()
{
    for(;;) {
        pthread_mutex_lock(&m_mutexTram);
        if(m_state != Tram::OutOfOrder)
            obstacleTracking();
        if(m_nbTick == m_velocity - 1) {
            this->m_nbTick = ++m_nbTick % m_velocity;
            switch(m_state) {
            case Tram::Acceleration:
                speedUp();
                move();
                break;
            case Tram::OutOfOrder:
                m_velocity = VITESSE_MIN;
                break;
            case Tram::Desceleration:
                slowDown();
                if(m_obstacle != NULL) {
                    if(m_obstacle->place() == m_trip->next(m_coordinate)) {
                        m_velocity = VITESSE_MIN;
                        m_state = Tram::Off;
                        sendIsStoped();
                    } else
                        move();
                }
                break;
            case Tram::On:
                move();
                break;
            case Tram::Off:
                m_velocity = VITESSE_MIN;
                break;
            }
        }
    }
}
コード例 #9
0
ファイル: obiekty.cpp プロジェクト: manixq/Monster-Race
void plansza()
{
	if (keys[VK_BACK])
		Restart();
	if (((x > 100 && x < 200 && z>300 && z < 450) || GAME_OVER == 2)&&GAME_OVER!=1)
	{
		GAME_OVER = 2;
		winner();
	}
	else
	{
		if (random == 0)
		{
			tajm = 0;
			random = rand() % 100 + 200;
			randomNum = rand() % 8;
		}
		if (tajm >= random)	tajm = -50 * 3 / speed;
		if (tajm < 0)	speedUp(randomNum);

		if (!graSnd)
		{
			PlaySound("Pliki/witcher3/HuntOrBeHunted", NULL, SND_LOOP | SND_ASYNC);
			menuSnd = false;
			graSnd = true;
		}

		bool animka = 0;
		
		if (lefty)
			alpha -= 3 * speed / 5;
		if (righty)
			alpha += 3 * speed / 5;
		
		if (upty)
		{
			
			animka = 1;
			z -= speed*cos(alpha / 180 * 3.1415926);
			x += speed*sin(alpha / 180 * 3.1415926);

			if (!detektorKolizji(ceil(z), ceil(x)))
			{
				animka = 0;
				z += speed*cos(alpha / 180 * 3.1415926);
    if (!detektorKolizji(ceil(z), ceil(x)))
    {
     z -= speed*cos(alpha / 180 * 3.1415926);
     x -= speed*sin(alpha / 180 * 3.1415926);
     if (!detektorKolizji(ceil(z), ceil(x)))
     {
      z += speed*cos(alpha / 180 * 3.1415926);
     }
    }
			}
		}
		


		glPushMatrix();
		glRotated(180, 0, 1, 0);
		glScaled(0.5, 0.5, 0.5);
		gracz(0, 5, 0, animka);  
		glPopMatrix();

		glRotated(alpha, 0, 1, 0);  //obracam i przesuwam mape, a nie gracza
		glTranslated(-x, 0, -z);

		glUseProgramObjectARB(0);
		glPushMatrix();
		glTranslated(-1, 1, 0);  
		 particless.rysuj(x,z, upty && !animka);
		glTranslated(2, 0, 0);  
	 	particless.rysuj(x,z, upty && !animka);
		glPopMatrix();
  if(LIGHTS)
		podstawowy_shader->Use();
		glPushMatrix();
		teksturnik(16, 17);
		for (int i = 0; i < 20; i++)
		{
			
			for (int j = 0; j < 26; j++)
			{
				glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "lightPos"), 50, 80, -50);
				teksturnik(16, 17);
				if (mapa[i][j] == 2)
				{
					glTranslated(0, 300, 0);
					inne(0, 0, 0, 4, potworbig, 1);
					mapBlok();
					glTranslated(0, -300, 0);
					teksturnik(16, 17);
				}
				if (mapa[i][j] == 1)
					mapBlok();
				glTranslatef(100.0f, 0, 0);
			}
			glTranslatef(-2600, 0, 100.0f);
		}
		glTranslatef(0, 0, -2000);
		if (GAME_OVER == 0)
			enemyAI(xE, zE);
		glPopMatrix();

		glTranslated(150, 70, 350);
		glPushMatrix();
		glScaled(15, 15, 15);
		if (GAME_OVER == 0)
		{
			inne(0, 0, 0, NULL, sgup, 0);
			if (xE > 100 && xE < 200 && zE>300 && zE < 450)
				GAME_OVER = 1;
		}
		else
			inne(0, 0, 0, NULL, sgdown, 0);
		glPopMatrix();
	}
}