Exemple #1
0
void CarManager::destroyAllCars()
{
	int i = 0;
	int totalCars = cars.size();
	Car *car;
	for(i = 0; i < totalCars; i++)
	{
		car = cars.at(i);
		car->destroy();
	}
	setCanSpawnNewCars(no);
}
Exemple #2
0
void CarManager::checkCollision(vector< InteractiveObject* > &objectsonScreen)
{
	unsigned int i, j;;
	InteractiveObject *interactiveObj;
	Car *car;
	Car* otherCar;
	Obstacles *obstacle;
	for(i = 0 ; i < cars.size(); i++)
	{
		car = cars.at(i);
		for(j = 0 ; j < objectsonScreen.size(); j++)
		{
			interactiveObj = objectsonScreen.at(j);

			//preventing collision from itself
			if(interactiveObj->getObectType().compare("Car") == 0 && i == j)
			{
				break;
			}

			Logical colliding = car->isCollidingWith(interactiveObj);
			if(colliding && interactiveObj->getOnScreen())
			{
				//Handle all obstacle cases.
				if(interactiveObj->getObectType().compare("Obstacle") == 0)
				{
					obstacle = (Obstacles*)interactiveObj;
					obstacleType myObsType = obstacle->getObstacleType();
					interactiveObj->setState(READY);
					interactiveObj->setOnScreen(no);
					car->bumpAction();
				}
				//Handle all car cases.
				else
				{
					otherCar = (Car*)interactiveObj;

					if(otherCar->isActive())
					{
						if(car->getCarType() == BONUS_CAR && otherCar->getCarType() != TRUCK_CAR)
						{
							otherCar->destroy();
						}
						else if(otherCar->getCarType() == BONUS_CAR && car->getCarType() != TRUCK_CAR)
						{
							car->destroy();
						}
						else
							if(car->getCarType() != TRUCK_CAR && otherCar->getCarType() != TRUCK_CAR)
						{
							otherCar->destroy();
						}
						else if(car->getCarType() == TRUCK_CAR && otherCar->getCarType() != TRUCK_CAR)
						{
							otherCar->destroy();
						}
						else if(otherCar->getCarType() == TRUCK_CAR && car->getCarType() != TRUCK_CAR)
						{
							car->destroy();
						}
					}
				}
			}
		}
	}
}