BeatTheStreet/src/obsticle.cpp
//Void function that moves the sprite along the lane
Void function that moves the sprite along the lane
Void function that moves the sprite along the lane
void obsticle::moveObsticle(float extraspeed)
{
	float  laneSpeed2, laneSpeed3, laneSpeed4, laneSpeed5, laneSpeed6, laneSpeed8, laneSpeed9, laneSpeed11, laneSpeed12, laneSpeed13, laneSpeed14, laneSpeed15;
		laneSpeed2 = 5.;
		laneSpeed3 = 4;
		laneSpeed4 = 3;
		laneSpeed5 = 2;
		laneSpeed6 = 1;
		laneSpeed8 = 10;
		laneSpeed9 = 25;
		laneSpeed11 = 5;
		laneSpeed12 = 6;
		laneSpeed13 = 4;
		laneSpeed14 = 5;
		laneSpeed15 = 3;
	 if (fLane == 2) { fSpeedOfStrip = laneSpeed2; }
	else if (fLane == 3) { fSpeedOfStrip = laneSpeed3; }
	else if (fLane == 4) { fSpeedOfStrip = laneSpeed4; }
	else if (fLane == 5) { fSpeedOfStrip = laneSpeed5; }
	else if (fLane == 6) { fSpeedOfStrip = laneSpeed6; }
	else if (fLane == 8) { fSpeedOfStrip = laneSpeed8; }
	else if (fLane == 9) { fSpeedOfStrip = laneSpeed9; }
	else if (fLane == 11) { fSpeedOfStrip = laneSpeed11; }
	else if (fLane == 12) { fSpeedOfStrip = laneSpeed12; }
	else if (fLane == 13) { fSpeedOfStrip = laneSpeed13; }
	else if (fLane == 14) { fSpeedOfStrip = laneSpeed14; }
	else if (fLane == 15) { fSpeedOfStrip = laneSpeed15; }
	fSpeedOfStrip = fSpeedOfStrip + extraspeed;
	float fHorizontalPossision = oSprite.getPosition().x;
	float fMovebackDistance;
	if (bIsTrain) fMovebackDistance = 1500.f; 
	else fMovebackDistance = 150.f; 
	if (!bObsticalDirection && fHorizontalPossision < -fMovebackDistance)
	{
		float sprtieypos = oSprite.getPosition().y;
		oSprite.setPosition(800 + fMovebackDistance, sprtieypos);
	}
	if (bObsticalDirection && fHorizontalPossision > 800+fMovebackDistance)
	{
		float sprtieypos = oSprite.getPosition().y;
		oSprite.setPosition(-fMovebackDistance, sprtieypos);
	}
	if (!bObsticalDirection) oSprite.move(-fSpeedOfStrip, 0);
	else if (bObsticalDirection)oSprite.move(fSpeedOfStrip, 0);
}
void obsticle :: moveObsticle ( float extraspeed ) { float laneSpeed2 , laneSpeed3 , laneSpeed4 , laneSpeed5 , laneSpeed6 , laneSpeed8 , laneSpeed9 , laneSpeed11 , laneSpeed12 , laneSpeed13 , laneSpeed14 , laneSpeed15 ; laneSpeed2 = 5. ; laneSpeed3 = 4 ; laneSpeed4 = 3 ; laneSpeed5 = 2 ; laneSpeed6 = 1 ; laneSpeed8 = 10 ; laneSpeed9 = 25 ; laneSpeed11 = 5 ; laneSpeed12 = 6 ; laneSpeed13 = 4 ; laneSpeed14 = 5 ; laneSpeed15 = 3 ; if ( fLane == 2 ) { fSpeedOfStrip = laneSpeed2 ; } else if ( fLane == 3 ) { fSpeedOfStrip = laneSpeed3 ; } else if ( fLane == 4 ) { fSpeedOfStrip = laneSpeed4 ; } else if ( fLane == 5 ) { fSpeedOfStrip = laneSpeed5 ; } else if ( fLane == 6 ) { fSpeedOfStrip = laneSpeed6 ; } else if ( fLane == 8 ) { fSpeedOfStrip = laneSpeed8 ; } else if ( fLane == 9 ) { fSpeedOfStrip = laneSpeed9 ; } else if ( fLane == 11 ) { fSpeedOfStrip = laneSpeed11 ; } else if ( fLane == 12 ) { fSpeedOfStrip = laneSpeed12 ; } else if ( fLane == 13 ) { fSpeedOfStrip = laneSpeed13 ; } else if ( fLane == 14 ) { fSpeedOfStrip = laneSpeed14 ; } else if ( fLane == 15 ) { fSpeedOfStrip = laneSpeed15 ; } fSpeedOfStrip = fSpeedOfStrip + extraspeed ; float fHorizontalPossision = oSprite . getPosition ( ) . x ; float fMovebackDistance ; if ( bIsTrain ) fMovebackDistance = 1500.f ; else fMovebackDistance = 150.f ; if ( ! bObsticalDirection && fHorizontalPossision < - fMovebackDistance ) { float sprtieypos = oSprite . getPosition ( ) . y ; oSprite . setPosition ( 800 + fMovebackDistance , sprtieypos ) ; } if ( bObsticalDirection && fHorizontalPossision > 800 + fMovebackDistance ) { float sprtieypos = oSprite . getPosition ( ) . y ; oSprite . setPosition ( - fMovebackDistance , sprtieypos ) ; } if ( ! bObsticalDirection ) oSprite . move ( - fSpeedOfStrip , 0 ) ; else if ( bObsticalDirection ) oSprite . move ( fSpeedOfStrip , 0 ) ; }
Void function that moves the sprite along the lane
Void function that moves the sprite along the lane
//float variables to hold the speeds of all the lanes. ///////////////////// ///////////////////// ///////////////////// ///////////////////// ///////////////////// ///////////////////// ///////////////////// ///////////////////// //set the strip speed depending on lane  //add extra speed that is given as a parameter from the main. extra speed is added when presents are collected //fHorizontalPosision is set from the sprites origin x position. //Move back distance is the distance off the screen that the sprite is reset to. //if the object is a train moveback is set to 1500px due to the long size of the train //else set to 150px //if the sprite goes off the screen the position is reset using the moveback. //if the sprite goes off the screen the position is reset using the moveback. //move the sprite in specific direction