Пример #1
0
void FlickCharm::timerEvent(QTimerEvent *event)
{
    int count = 0;
    QHashIterator<QWidget*, FlickData*> item(d->flickData);
    while (item.hasNext()) {
        item.next();
        FlickData *data = item.value();
        if (data->state == FlickData::AutoScrollAcceleration
            && data->waitingAcceleration
            && data->accelerationTimer.elapsed() > 40) {
            data->state = FlickData::ManualScroll;
            data->resetSpeed();
        }
        if (data->state == FlickData::AutoScroll || data->state == FlickData::AutoScrollAcceleration) {
            const int timeElapsed = d->timeCounter.elapsed();
            const QPoint delta = (data->speed) * timeElapsed / 1000;
            bool hasScrolled = data->scrollWidget(delta.x(), delta.y());

            if (data->speed.isNull() || !hasScrolled)
                data->state = FlickData::Steady;
            else
                count++;
            data->speed = deaccelerate(data->speed, timeElapsed);
        }
    }

    if (!count)
        d->ticker.stop();
    else
        d->timeCounter.start();

    QObject::timerEvent(event);
}
Пример #2
0
void FlickScroll::timerEvent(QTimerEvent *event)
{
    int count = 0;
    QHashIterator<QWebView*, FlickData*> item(flickScroll_pm->flickData);
    while(item.hasNext())
    {
        item.next(); //moves the pointer forward
        FlickData *data = item.value();
        //if moving manually, adjust the speed based on
        //the difference of the new cursor position from the old one
        if(data->state == FlickData::ManualScroll)
        {
            count++;
            data->speed = QCursor::pos() - data->dragPos;
            data->dragPos = QCursor::pos();
        }
        else if(data->state == FlickData::AutoScroll)
        {
            count++;
            data->speed = deaccelerate(data->speed);
            QPoint p = scrollOffset(data->widget);
            setScrollOffSet(data->widget, p - data->speed);

            scrollCustom(data->widget, data->speed.y());
            //printf("autoscroll %d\n", data->speed.y());
            if(data->speed == QPoint(0,0))
                data->state = FlickData::Steady;
        }
    }

    if(!count)
        flickScroll_pm->ticker.stop();

    QObject::timerEvent(event);
}
void RobotController::stop() 
{

    deaccelerate();
    leftMotor.setSpeed(motor_zeroSpeed);
    rightMotor.setSpeed(motor_zeroSpeed);
    setMotorsRun_RELEASE();
    currentSpeed = 0;
    delay(500);
}
Пример #4
0
void ImageViewer::myTimerEvent()
{
    speed = deaccelerate(speed);

    QPointF shiftOld = shift;
    shift += speed;
    updateShift();

    if(shift == shiftOld)
        speed = QPoint(0, 0);
    if (speed == QPoint(0, 0))
        timer.stop();
}
Пример #5
0
void Flickable::tick()
{
    if (d->state == FlickablePrivate:: AutoScroll) {
        d->speed = deaccelerate(d->speed);
        setScrollOffset(d->offset - d->speed);
        d->offset = scrollOffset();
        if (d->speed == QPoint(0, 0)) {
            d->state = FlickablePrivate::Steady;
            d->ticker->stop();
        }
    } else {
        d->ticker->stop();
    }
}
Пример #6
0
void kart::update() {
	if (!isAccelarating) {
		if (speed < 0) {
			speed += 0.1;
		}
		else if (speed > 0) {
			speed -= 0.1;
		}
	}
	else {
		if (!isReverse) {
			accelerate();
		}
		else
			deaccelerate();
	}
}
char* Player::update(char *input)
{
	//p is a char pointer to a mSendBuff which is the data that will be sent to the other players, it maps the Input data

	char *p=mSendBuff;
	
	//Get Xinput State
	XInputGetState(0,&gXInputState);

	if(eUserType==USERTYPE_SERVER)
	{

		if(eCarState==CARSTATE_COLLIDED)
		{
			if(eCollisionType==COLLISIONTYPE_MUD)
			{
				decAcceleration(0.2);
				p[4]='1';
				eCarState=CARSTATE_MOVINGREVERSE;
			}
	
			if(eCollisionType==COLLISIONTYPE_OIL)
			{
				decAcceleration(0.2);
				if(mPosition.x<(SCREEN_WIDTH/2))
					yaw(-5,-0.3);
				else
					yaw(5,0.3);
			
				eCarState=CARSTATE_MOVINGREVERSE;
				p[4]='2';
			}
		

			if(eCollisionType==COLLISIONTYPE_PEDESTRIAN)
			{
				deaccelerate(15);
				eCarState=CARSTATE_MOVINGREVERSE;
				p[4]='3';
			}
		
			if(eCollisionType==COLLISIONTYPE_ROADBLOCK || eCollisionType==COLLISIONTYPE_NPCCAR)
			{
				mCurrentVelocity=0;
				mCurrentBVelocity=0;
				deaccelerate(50);
				eCarState=CARSTATE_STOP;
				p[4]='4';
			}
			
				eCollisionType=COLLISIONTYPE_NONE;
		}
		else
		{
			p[4]='0';
		}

		if(hge->Input_GetKeyState(HGEK_UP) || gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_A && eCollisionType!=COLLISIONTYPE_ROADBLOCK)
		{
			accelerate(1);
			eCarState=CARSTATE_MOVING;
			p[0]='6';
		}
		else
		{
			p[0]='0';
			damp(1);
		}

		if(hge->Input_GetKeyState(HGEK_DOWN)||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_X)
		{
			deaccelerate(1);
			eCarState=CARSTATE_MOVING;
			p[1]='7';
		}
		else
		{
			p[1]='0';
			Bdamp(1);
		}

		if(hge->Input_GetKeyState(HGEK_LEFT) ||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_DPAD_LEFT&& (eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(-5,-0.3);
			p[2]='8';
		}
		else
		{
			p[2]='0';
			RLdamp();
		}

		if(hge->Input_GetKeyState(HGEK_RIGHT)||gXInputState.Gamepad.wButtons&XINPUT_GAMEPAD_DPAD_RIGHT && (eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(5,0.3);
			p[3]='9';
		}
		else
		{
			RRdamp();
			p[3]='0';
		}
		/*char c[256];
		sprintf(c,"send : %s \n",mSendBuff);
		OutputDebugString(c);*/

		sprintf(SpeedString,"Speed : %d ",(int)mCurrentVelocity);
		//OutputDebugString(SpeedString);
		Integrator();
		
		p[5]='\0';
	}
		else if(eUserType==USERTYPE_CLIENT)
	{
			if(input[4]=='1')
			{
				//MUD COLLISION
				decAcceleration(0.2);
				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='2')
			{
				//OIL COLLISION
				decAcceleration(0.2);
				if(mPosition.x<(SCREEN_WIDTH/2))
					yaw(-5,-0.3);
				else
					yaw(5,0.3);

				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='3')
			{
				//PEDESTRIAN COLLISION
				deaccelerate(15);
				eCarState=CARSTATE_MOVINGREVERSE;
			}

			if(input[4]=='4')
			{
				//NPC CAR COLLISION
				mCurrentVelocity=0;
				mCurrentBVelocity=0;
				deaccelerate(50);
				eCarState=CARSTATE_STOP;
			}
		
		if(input[0]=='6' || hge->Input_GetKeyState(HGEK_W))
		{
			accelerate(1);
			eCarState=CARSTATE_MOVING;
		}
		else
		{
			damp(1);
		}

		if(input[1]=='7')
		{
			deaccelerate(1);
			eCarState=CARSTATE_MOVING;
		}
		else
		{
			Bdamp(1);
		}

		if(input[2]=='8'&&(eCarState==CARSTATE_MOVING || eCarState==CARSTATE_DAMPING))
		{
			yaw(-5,-0.3);
		}
		else
		{
			RLdamp();
		}

		if(input[3]=='9'&& (eCarState==CARSTATE_MOVING|| eCarState==CARSTATE_DAMPING))
		{
			yaw(5,0.3);
		}
		else
		{
			RRdamp();
		} 

		Integrator();

	}
	return p;
}