void resetGame() { resetLevel(); initRobot(); setFadeMode(&reset_fade,FADE_OUT,1); }
void playGame() { lives = MAX_LIVES; score = 0; startLevel(); resetLevel(); int resetPressed = FALSE; // game loop while (lives > 0) { //test select button release if (KEY_DOWN_NOW(BUTTON_SELECT)) { resetPressed = TRUE; } if (resetPressed && !KEY_DOWN_NOW(BUTTON_SELECT)) { titleScreen(); } waitForVBlank(); erase(); updateVars(); checkOutsideScreen(); generateObjs(); draw(); } gameOverScreen(); }
void GameLayer::loadLevel (int level) { clearLayer(); _currentLevel = level; resetLevel(); CCDictionary * levelData = (CCDictionary *) _levels->objectAtIndex(_currentLevel); int count; CCDictionary * data; //create platforms CCArray * platforms = (CCArray *) levelData->objectForKey("platforms"); Platform * platform; count = platforms->count(); for (int i = 0; i < count; i++) { platform = (Platform *) _platformPool->objectAtIndex(_platformPoolIndex); _platformPoolIndex++; if (_platformPoolIndex == _platformPool->count()) _platformPoolIndex = 0; data = (CCDictionary *) platforms->objectAtIndex(i); platform->initPlatform ( data->valueForKey("width")->intValue() * TILE, data->valueForKey("angle")->floatValue(), ccp(data->valueForKey("x")->floatValue() * TILE, data->valueForKey("y")->floatValue() * TILE) ); } }
void GameScreen::nextLevelTick(float delta) { // Maybe do some fancy animation. But for now, just give them a fat score bonus // and reset the level // We have to see if the player messed up and deployed his/her chute though if(player->mChuteState == ParachuteState::CLOSED) { mPlayerScore += 10000; resetLevel(); } else { resetLevel(); player->setBoned(); } }
void CGame::update() { switch (gamestate) { case GAME: handleEvents(); plane.move(); plane.setCamera(); enemyMovement(); collideShellsWithEnemies(); collideShellsWithPowerups(); powerupsCollision(); handleEnemyShots(); if (groundCollision(plane.getBox()) || enemyCollision(plane.getBox()) || collidePlaneWithEnemyShells() || (plane.getFuel() == 0)) { plane.removeLife(); resetLevel(); } if (plane.getLives() == 0) { gameOverHandler(); gamestate = GAMEOVER; } break; case START: handleMenuEvents(); break; case GAMEOVER: handleMenuEvents(); break; } }
void BattleState::cleanAll() { resetLevel(); score = 0; cleanStage(); delete player; player = 0; }
CheckPointManager::~CheckPointManager(void) { resetLevel(); delete pTargets; mPosition->detachAllObjects (); mPosition->removeAndDestroyAllChildren (); mSceneMgr->destroySceneNode (mName + "_node"); mSceneMgr->destroyParticleSystem(mName + "_particlesystem"); }
void Game::onDie() { //TODO: Exercise 4 //Optional global_lives--; if (global_lives == 0) restartGame(); else resetLevel(); }
void respawn(){ dead = false; if (gameState == GAME_RUNNING) { gameState = GAME_LSCREEN; } glutPostRedisplay(); resetLevel(); }
void GameScreen::deathTick(float delta) { // If the player hits "R", restart the game if(sf::Keyboard::isKeyPressed(sf::Keyboard::R)) { resetLevel(); mPlayerScore = 0; } else { // If death hasn't been initialized (ie: the death animation hasn't started) start it if(mDeathObjects.size() == 0) { mPromptText.setString("Press [R] to restart the level"); // This is a list of directions. Basically it's an array of Vectors without the overhead int numDirs = 8; // Start pointing straight right, then spiral around clockwise int xDir[] = { 1, 1, 0,-1,-1,-1, 0, 1}; int yDir[] = { 0, 1, 1, 1, 0,-1,-1,-1}; float velocity = 50.0f; DeathParticle* tPart; // Build a bunch of death particles for(int i = 0; i < 33; ++i) { tPart = new DeathParticle((float)xDir[i % numDirs], (float)yDir[i % numDirs], velocity * (i + 1)/ numDirs); tPart->position.x = player->position.x; tPart->position.y = player->position.y; mDeathObjects.push_back(tPart); // Push it to GameObjects to automagically handle drawing. This should probably be extracted // into a renderables list, and a gameobjects list, but for jam, not necessary addRenderable(tPart); } // Change the player to not render player->mRenderingEnabled = false; } // Meow update them all for(std::vector<GameObject*>::iterator itor = mDeathObjects.begin(); itor != mDeathObjects.end(); ++itor) { (*itor)->update(delta); } } }
void Game::setCurrentLevel(int level) { this->level = level; resetLevel(); }
void GameLayer::ccTouchesEnded(CCSet* touches, CCEvent* event) { CCTouch *touch = (CCTouch *)touches->anyObject(); if (touch) { CCPoint tap = touch->getLocation(); CCRect boundary; //handle button touches CCSprite * button; CCSprite * buttonPress; for (int i = 0; i < 5; i++) { button = (CCSprite *) _buttons->objectAtIndex(i); if (!button->isVisible()) continue; boundary = button->boundingBox(); if (boundary.containsPoint(tap)) { buttonPress = (CCSprite *) button->getChildByTag(kSpriteBtnOn); buttonPress->setVisible(false); switch (button->getTag()) { case kSpriteBtnAgain: _running = false; _btnAgain->setVisible(false); _btnMenu->setVisible(false); resetLevel(); SimpleAudioEngine::sharedEngine()->playEffect("button.wav"); break; case kSpriteBtnReset: _running = false; resetLevel(); break; case kSpriteBtnPause: if (_running) { _messages->setString("paused"); _messages->setVisible(true); } else { _messages->setVisible(false); } _running = !_running; break; case kSpriteBtnStart: SimpleAudioEngine::sharedEngine()->playEffect("button.wav"); _btnPause->setVisible(true); _btnReset->setVisible(true); _btnStart->setVisible(false); _messages->setVisible(false); _running = true; if (_currentLevel == 0) { _tutorialLabel->setVisible(true); } break; case kSpriteBtnMenu: SimpleAudioEngine::sharedEngine()->playEffect("button.wav"); SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); unscheduleUpdate(); CCScene* newScene = CCTransitionMoveInL::create(0.2f, MenuLayer::scene()); CCDirector::sharedDirector()->replaceScene(newScene); } return; } } if (!_running) return; _player->setSwitchShape(true); } }
void CheckPointManager::loadLevel(String level) { resetLevel(); if( level == "random" ) { CPState status = CURRENT; AddCheckPoint(Vector3(0,0,1000), status); status = TODO; for( int i = 1; i < 15; i++ ) // generate 3 CPs AddCheckPoint(Vector3(Math::RangeRandom (-600, 600),Math::RangeRandom(-600, 600),Math::RangeRandom (0000, 15000)), status); done = false; } else if( level == "level 1" ) { CPState status = CURRENT; AddCheckPoint(Vector3(0,0,3000), status); status = TODO; AddCheckPoint(Vector3(3000,0,3000), status); AddCheckPoint(Vector3(3000,0,0), status); AddCheckPoint(Vector3(0,0,0), status); done = false; mSolid->begin("BaseWhiteNoLighting",RenderOperation::OT_LINE_STRIP); //BaseWhiteNoLighting"); //Ogre/Compositor/OldTV"); mSolid->position(0,0,3000); mSolid->colour(0,0,1); mSolid->position(3000,0,3000); mSolid->colour(1,0,1); mSolid->position(3000,0,0); mSolid->colour(1,0,0); mSolid->position(0,0,0); mSolid->colour(0,0,0); mSolid->position(0,0,3000); mSolid->colour(0,0,1); mSolid->end(); } else if( level == "level 2" ) { CPState status = CURRENT; AddCheckPoint(Vector3(0,0,3000), status); status = TODO; AddCheckPoint(Vector3(0,3000,3000), status); AddCheckPoint(Vector3(3000,3000,3000), status); AddCheckPoint(Vector3(3000,0000,3000), status); AddCheckPoint(Vector3(3000,0,0), status); AddCheckPoint(Vector3(3000,3000,0), status); AddCheckPoint(Vector3(0,3000,0), status); AddCheckPoint(Vector3(0,0,0), status); done = false; mSolid->begin("BaseWhiteNoLighting",RenderOperation::OT_LINE_LIST); //BaseWhiteNoLighting"); //Ogre/Compositor/OldTV"); mSolid->position(0,0,0); mSolid->colour(0,0,0); mSolid->position(0,0,3000); mSolid->colour(0,0,1); mSolid->position(3000,0,3000); mSolid->colour(1,0,1); mSolid->position(3000,0,0); mSolid->colour(1,0,0); mSolid->position(0,3000,0); mSolid->colour(0,1,0); mSolid->position(0,3000,3000); mSolid->colour(0,1,1); mSolid->position(3000,3000,3000); mSolid->colour(1,1,1); mSolid->position(3000,3000,0); mSolid->colour(1,1,0); mSolid->index(0); mSolid->index(1); mSolid->index(0); mSolid->index(3); mSolid->index(0); mSolid->index(4); mSolid->index(1); mSolid->index(2); mSolid->index(1); mSolid->index(5); mSolid->index(2); mSolid->index(3); mSolid->index(2); mSolid->index(6); mSolid->index(3); mSolid->index(7); mSolid->index(4); mSolid->index(5); mSolid->index(4); mSolid->index(7); mSolid->index(5); mSolid->index(6); mSolid->index(6); mSolid->index(7); mSolid->end(); } else if( level == "level 3" ) { CPState status = CURRENT; AddCheckPoint(Vector3(0,0,3000), status); status = TODO; AddCheckPoint(Vector3(0,3000,0), status); AddCheckPoint(Vector3(3000,0,0), status); AddCheckPoint(Vector3(-3000,0,0), status); AddCheckPoint(Vector3(0,-3000,0), status); AddCheckPoint(Vector3(0,0,-3000), status); done = false; mSolid->begin("BaseWhiteNoLighting",RenderOperation::OT_LINE_LIST); //BaseWhiteNoLighting"); //Ogre/Compositor/OldTV"); mSolid->position(0,0,3000); mSolid->colour(0,0,1); mSolid->position(0,3000,0); mSolid->colour(0,1,0); mSolid->position(3000,0,0); mSolid->colour(1,0,0); mSolid->position(-3000,0,0); mSolid->colour(0,1,1); mSolid->position(0,-3000,0); mSolid->colour(1,0,1); mSolid->position(0,0,-3000); mSolid->colour(1,1,0); mSolid->index(0); mSolid->index(1); mSolid->index(0); mSolid->index(2); mSolid->index(0); mSolid->index(3); mSolid->index(0); mSolid->index(4); mSolid->index(1); mSolid->index(2); mSolid->index(1); mSolid->index(3); mSolid->index(1); mSolid->index(5); mSolid->index(2); mSolid->index(4); mSolid->index(2); mSolid->index(5); mSolid->index(3); mSolid->index(4); mSolid->index(3); mSolid->index(5); mSolid->index(4); mSolid->index(5); mSolid->end(); } else { CPState status = CURRENT; AddCheckPoint(Vector3(0,0,0), status); status = TODO; for( int i = 1; i < 15; i++ ) // generate 3 CPs AddCheckPoint(Vector3(Math::RangeRandom (-600, 600),Math::RangeRandom(-600, 600),Math::RangeRandom (0, 15000)), status); done = false; } }
void Scene::run(double elapsed) { ball->update(elapsed); text2d->update(elapsed); for(int i = 0;i<numPlatforms;i++) { platforms[i]->update(elapsed); } if(elapsed>10000000) elapsed = 0.016; dynamicsWorld->stepSimulation(elapsed,10,1./120.); btVector3 ballPos = ball->getBody()->getWorldTransform().getOrigin(); std::stringstream out; out << "ball pos : " << ballPos.x(); *(moduleRegistry->getText2D()->print()) = out.str(); if(ballPos.z() < -100) { text3d->setColor(osg::Vec4(1, 0, 0, 1)); text3d->setText("Perdu !"); if(time_elapsed_lost < 2) { time_elapsed_lost += elapsed; text3d->setPosition(textOffset-osg::Vec3f(0., 0., time_elapsed_lost*20)); } else { text3d->setText(""); resetLevel(); createLevel(currentLevel); setBallPos(*lastCheckpoint); time_elapsed_lost = 0; cameraAngle = 0; } } else { osg::Matrix cameraMatrix; //cameraMatrix.makeLookAt(Utils::asOsgVec3(ballPos) + osg::Vec3f(-15*cos(cameraAngle), 15*sin(cameraAngle), 10), Utils::asOsgVec3(ballPos), osg::Vec3f(0, 0, 1)); cameraMatrix.makeLookAt(Utils::asOsgVec3(ballPos) + osg::Vec3f(-20*cos(cameraAngle), 20*sin(cameraAngle), 10), Utils::asOsgVec3(ballPos) + osg::Vec3f(0, 0, 10), osg::Vec3f(0, 0, 1)); rootNode->setMatrix(cameraMatrix); } if(!allowMovement) { time_elapsed_begin += elapsed; text3d->setPosition(textOffset-osg::Vec3f(0, 0., time_elapsed_begin*20)); if(time_elapsed_begin > 2) { allowMovement = true; time_elapsed_begin = 0; text3d->setText(""); } } if(moduleRegistry->playerReachedEnd) { time_elapsed_end_level += elapsed; if(currentLevel == MAX_LEVEL) { time_elapsed_end_game += elapsed; if(!hasStartedEndText) { text3d->setText("THE END !"); text3d->setColor(osg::Vec4d(0, 0, 1, 1)); text3d->setPosition(textOffset); hasStartedEndText = true; } text3d->setPosition(textOffset-osg::Vec3f(0, 0., time_elapsed_end_game*20)); if(time_elapsed_end_game > 2) { text3d->setText(""); exit(0); } } else { if(!hasStartedEndText) { std::stringstream out; out << currentLevel; text3d->setText("You reached the end of level " + out.str() + " !"); text3d->setColor(osg::Vec4d(0, 1, 1, 1)); text3d->setPosition(textOffset); hasStartedEndText = true; } text3d->setPosition(textOffset-osg::Vec3f(0, 0., time_elapsed_end_level*20)); if(time_elapsed_end_level > 2) { moduleRegistry->playerReachedEnd = false; setBallPos(btVector3(0, 0, 50)); cameraAngle = 0; resetLevel(); createLevel(++currentLevel); } } } }
void volleyballWorldInit(struct VolleyballWorld* world) { /* TODOS - calibrate gravity - something to separate the field to halves - score system */ world->super.vtable = &VolleyballWorldVTable; world->super.b_running = true; world->super.entities = NULL; world->super.camera.pos.x = 0; world->super.camera.pos.y = 0; world->wphysics.gravity.x = 0; world->wphysics.gravity.y = 8; world->score_max = 8; world->score_player1 = 4; world->score_sprite1 = spriteLoad("data/usa_score.kgf"); world->score_sprite2 = spriteLoad("data/cccp_score.kgf"); world->score_offset_x = 2; world->score_offset_y = 1; world->score_gap = 0; world->player1 = entityCreate(spriteLoad("data/usa_ball.kgf"), 15, 41, 10, 0); world->player1->ephysics.center.x = world->player1->sprite->w / 2; world->player1->ephysics.center.y = world->player1->sprite->h; world->player1->ephysics.radius = 8.75; world->player2 = entityCreate(spriteLoad("data/cccp_ball.kgf"), 55, 41, 10, 0); world->player2->ephysics.center.x = world->player2->sprite->w / 2; world->player2->ephysics.center.y = world->player2->sprite->h; world->player2->ephysics.radius = 8.75; world->ball = entityCreate(spriteLoad("data/mini_hitler.kgf"), 10, 10, 9, 0); world->ball->ephysics.center.x = world->ball->sprite->w / 2; world->ball->ephysics.center.y = world->ball->sprite->h / 2; world->ball->ephysics.radius = 4.75; resetLevel(world); int floor_w = 100; int floor_h = 20; CHAR_INFO** floor_bitmap = malloc(sizeof(CHAR_INFO*)); floor_bitmap[0] = malloc(floor_w * floor_h * sizeof(CHAR_INFO)); for (int i = 0; i < floor_w * floor_h; i++) { floor_bitmap[0][i].Attributes = 10; floor_bitmap[0][i].Char.AsciiChar = 1; } struct Entity* floor = entityCreate(spriteCreate(floor_bitmap, floor_w, floor_h, 0), -10.0, 50.0, 0, 0); floor->ephysics.b_static = true; floor->ephysics.b_collides = true; floor->ephysics.b_affected_by_collisions = false; int wall_w = 20; int wall_h = 70; CHAR_INFO** wall_bitmap = malloc(sizeof(CHAR_INFO*)); wall_bitmap[0] = malloc(wall_w * wall_h * sizeof(CHAR_INFO)); for (int i = 0; i < wall_w * wall_h; i++) { wall_bitmap[0][i].Attributes = 1; wall_bitmap[0][i].Char.AsciiChar = 1; } struct Entity* west_wall = entityCreate(spriteCreate(wall_bitmap, wall_w, wall_h, 0), -20, -10, 0, 0); west_wall->ephysics.b_static = true; west_wall->ephysics.b_collides = true; west_wall->ephysics.b_affected_by_collisions = false; struct Entity* east_wall = entityCreate(spriteCreate(wall_bitmap, wall_w, wall_h, 0), 80, -10, 0, 0); east_wall->ephysics.b_static = true; east_wall->ephysics.b_collides = true; east_wall->ephysics.b_affected_by_collisions = false; world->super.entities = entityListCreate(world->ball); entityListPush(world->super.entities, world->player1); entityListPush(world->super.entities, world->player2); //entityListPush(world->super.entities, floor); //entityListPush(world->super.entities, west_wall); //entityListPush(world->super.entities, east_wall); }
void GameState::init() { resetLevel( -1 ); m_gameOver = true; // start out not playing m_score = 0; }
void Intestine::update(sf::RenderWindow &window) { // Specific event loop for gameRun state sf::Event gEvent; while (window.pollEvent(gEvent)) { if (gEvent.type == sf::Event::Closed) window.close(); if (gEvent.key.code == sf::Keyboard::R) resetLevel(window); } // Updates independent of state if (!Toolbox::getPlayerIsAlive()) { resetLevel(window); } mLevelMusic.playMusic(LevelMusic::INTESTINEMUSIC); // Updates depending on state if (mLevelState == "Cutscene") { mCamera.updateStomachCam(window, mLevelState); mLevelState = "ZoomOut"; } if (mLevelState == "ZoomOut") { if (!mZoomedOut) { mCamera.updateStomachCam(window, mLevelState); mZoomedOut = true; } mLevelState = "ZoomedOut"; } if (mLevelState == "ZoomedOut") { mCamera.updateStomachCam(window, "Standard"); mEntityHandler->update(); mTerrainHandler->update(); mCollisionHandler.checkCollision(mEntityHandler->getEntities(), mTerrainHandler->getTerrains(), mTerrainHandler->getCollisionTerrains()); mEntityHandler->bringOutTheDead(); mTerrainHandler->bringOutTheDead(); window.setView(mCamera.getTileView()); sf::Vector2f tileViewCoordPos = Toolbox::findCoordPos(sf::Vector2i(mCamera.getTileView().getCenter().x, 0), window); window.setView(mCamera.getSceneryView()); sf::Vector2f sceneViewCoordPos = Toolbox::findCoordPos(sf::Vector2i(tileViewCoordPos.x, 0), window); mLayerHandler.moveBackgroundHorizontal(window, mCamera, sceneViewCoordPos, tileViewCoordPos); mLayerHandler.moveStationaryForeground(window, mCamera, sceneViewCoordPos, tileViewCoordPos); mLayerHandler.moveMiddleground(window, mCamera, sceneViewCoordPos, tileViewCoordPos, "Top"); mLayerHandler.updateHud(mCamera.getTileView().getCenter(), tileViewCoordPos); if (sf::Keyboard::isKeyPressed(sf::Keyboard::L)) { mLevelMusic.stopAllMusic(); mEntityHandler->stopAllSound(); GameRun::getInstance(std::string(""), std::string(""))->changeLevel("Hub"); } } if (mLevelState == "Rising") { mCamera.updateStomachCam(window, mLevelState); mEntityHandler->update(); mTerrainHandler->update(); mCollisionHandler.checkCollision(mEntityHandler->getEntities(), mTerrainHandler->getTerrains(), mTerrainHandler->getCollisionTerrains()); mEntityHandler->bringOutTheDead(); mTerrainHandler->bringOutTheDead(); window.setView(mCamera.getTileView()); sf::Vector2f tileViewCoordPos = Toolbox::findCoordPos(sf::Vector2i(mCamera.getTileView().getCenter().x, 0), window); window.setView(mCamera.getSceneryView()); sf::Vector2f sceneViewCoordPos = Toolbox::findCoordPos(sf::Vector2i(tileViewCoordPos.x, 0), window); mLayerHandler.moveBackgroundHorizontal(window, mCamera, sceneViewCoordPos, tileViewCoordPos); mLayerHandler.updateHud(mCamera.getTileView().getCenter(), tileViewCoordPos); } if (mLevelState == "Reset") { resetLevel(window); } if (mLevelState == "Dialogue") { Dialoguehandler::getInstance().updateDialogue(); if (Dialoguehandler::getInstance().isInDialogue == false) mLevelState = "ZoomedOut"; } }
//update all game-related variables void updateVars() { t = (t + 1) % 3600; road.row = (road.row + road.speed) % road.height; for (int i = 0; i < numGas; i++) { gas[i].row += road.speed; } if (player.row == SCREEN_HEIGHT) { player.dead = TRUE; } if (player.dead || player.fuel <= 0) { player.row += road.speed; if (player.row > SCREEN_HEIGHT + player.height) { lives--; resetLevel(); } } else { if (KEY_DOWN_NOW(BUTTON_RIGHT)) { player.col++; } if (KEY_DOWN_NOW(BUTTON_LEFT)) { player.col--; } if (KEY_DOWN_NOW(BUTTON_UP)) { player.row--; } if (KEY_DOWN_NOW(BUTTON_DOWN)) { player.row++; } boundsCheck(&(player.row), 0, SCREEN_HEIGHT + CAR_HEIGHT, player.height); boundsCheck(&(player.col), road.col + 2, road.col + road.width - 2, player.width); if (t % player.fuelDecInterval == 0 && player.fuel > 0) { player.fuel--; } } for (int i = 0; i < numCarsUp; i++) { if (carsUp[i].dead) { carsUp[i].row += road.speed; } else { //move at the fractional rate vSpeedNum / vSpeedDenom if (t % carsUp[i].speedDenom == 0) { carsUp[i].row += carsUp[i].speedNum; } } } for (int i = 0; i < numCarsDown; i++) { if (carsDown[i].dead) { carsDown[i].row += road.speed; } else { //move at the fractional rate vSpeedNum / vSpeedDenom if (t % carsDown[i].speedDenom == 0) { carsDown[i].row += carsDown[i].speedNum; } } } if (police.exists) { if (police.dead) { police.row += road.speed; } else { //move at the fractional rate vSpeedNum / vSpeedDenom if (t % police.vSpeedDenom == 0) { police.row -= police.vSpeedNum; } //police follows player in terms of horizontal movement if no other cars in the way if (player.col <= police.col - police.hSpeed) { int canMove = TRUE; for (int i = 0; i < numCarsUp && canMove; i++) { if (checkCollision(police.row, police.col - police.hSpeed, police.height, police.width , carsUp[i].row, carsUp[i].col, carsUp[i].height, carsUp[i].width)) { canMove = FALSE; } } for (int i = 0; i < numCarsDown && canMove; i++) { if (checkCollision(police.row, police.col - police.hSpeed, police.height, police.width , carsDown[i].row, carsDown[i].col, carsDown[i].height, carsDown[i].width)) { canMove = FALSE; } } if (canMove) { police.col -= police.hSpeed; } } if (player.col >= police.col + police.hSpeed) { int canMove = TRUE; for (int i = 0; i < numCarsUp && canMove; i++) { if (checkCollision(police.row, police.col + police.hSpeed, police.height, police.width , carsUp[i].row, carsUp[i].col, carsUp[i].height, carsUp[i].width)) { canMove = FALSE; } } for (int i = 0; i < numCarsDown && canMove; i++) { if (checkCollision(police.row, police.col + police.hSpeed, police.height, police.width , carsDown[i].row, carsDown[i].col, carsDown[i].height, carsDown[i].width)) { canMove = FALSE; } } if (canMove) { police.col += police.hSpeed; } } //update animation frame if (t % police.updateInterval == 0) { police.frame = (police.frame + 1) % 2; } } } //collision checking for (int i = 0; i < numGas; i++) { //if the player is in contact with a gas container if (checkCollision(player.row, player.col, player.height, player.width, gas[i].row, gas[i].col, gas[i].height, gas[i].width)) { player.fuel = MAX_FUEL; //remove the gas object //replace what was previously in index i with the last element and decrement size of array gas[i] = gas[(numGas--) - 1]; i--; } } for (int i = 0; i < numCarsUp; i++) { if (checkCollision(player.row, player.col, player.height, player.width, carsUp[i].row, carsUp[i].col, carsUp[i].height, carsUp[i].width)) { player.dead = TRUE; carsUp[i].dead = TRUE; } } for (int i = 0; i < numCarsDown; i++) { if (checkCollision(player.row, player.col, player.height, player.width, carsDown[i].row, carsDown[i].col, carsDown[i].height, carsDown[i].width)) { player.dead = TRUE; carsDown[i].dead = TRUE; } } if (police.exists) { if (checkCollision(player.row, player.col, player.height, player.width, police.row, police.col, police.height, police.width)) { player.dead = TRUE; police.dead = TRUE; } for (int i = 0; i < numCarsUp; i++) { if (checkCollision(police.row, police.col, police.height, police.width, carsUp[i].row, carsUp[i].col, carsUp[i].height, carsUp[i].width)) { police.dead = TRUE; carsUp[i].dead = TRUE; } } for (int i = 0; i < numCarsDown; i++) { if (checkCollision(police.row, police.col, police.height, police.width, carsDown[i].row, carsDown[i].col, carsDown[i].height, carsDown[i].width)) { police.dead = TRUE; carsDown[i].dead = TRUE; } } } score++; }