void PlayerManager::checkCollision(vector< InteractiveObject* > &objectsonScreen) { unsigned int i; InteractiveObject *interactiveObj; Car* car; Obstacles *obstacle; for(i = 0 ; i < objectsonScreen.size(); i++) { interactiveObj = objectsonScreen.at(i); collisionSide collSide = player->isCollidingThenFromWhere(interactiveObj); if(collSide && interactiveObj->getOnScreen()) { lprintf("collision detected\n"); //Handle all obstacle cases. if(interactiveObj->getObectType().compare("Obstacle") == 0) { obstacle = (Obstacles*)interactiveObj; obstacleType myObsType = obstacle->getObstacleType(); interactiveObj->setState(READY); interactiveObj->setOnScreen(no); player->bumpAction(myObsType); } //Handle all car cases. else { car = (Car*)interactiveObj; if(car->getCarType() != BONUS_CAR) { //In the case of car, we are interested in from where we are having the collision switch(collSide) { case COLLIDING_TOP_LEFT: player->setSlideDirection(DIRECTION_LEFT); break; case COLLIDING_TOP_RIGHT: player->setSlideDirection(DIRECTION_RIGHT); break; case COLLIDING_BOTTOM_LEFT: player->setSlideDirection(DIRECTION_LEFT); break; case COLLIDING_BOTTOM_RIGHT: player->setSlideDirection(DIRECTION_RIGHT); break; } } carType mycarType = car->getCarType(); if(car->isActive()) { car->setSlideDirection(player->getSlideDirection() == DIRECTION_LEFT ? DIRECTION_RIGHT : DIRECTION_LEFT); car->bumpAction(); player->bumpAction(mycarType); } } } } }
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(); } } } } } } }