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 CGame::cleanup() { gameOverHandler(); plane.reset(); SDL_DestroyTexture(clip_image); SDL_DestroyTexture(score_tex); SDL_DestroyTexture(gameover_tex1); SDL_DestroyTexture(gameover_tex2); Window::Quit(); }
bool GameScreen::onContactBegin(const PhysicsContact& contact) { //Boto collision with brick //Boto is destroyed if (CollisionManager::CheckCollision(contact, BLOCKS_BITMASK, BOTO_BITMASK)) { CCLog("Block collision with boto"); if(contact.getShapeA()->getBody()->getTag() != 0 || contact.getShapeB()->getBody()->getTag() != 0) { //we got bonus here if(contact.getShapeA()->getBody()->getCollisionBitmask() == BLOCKS_BITMASK) { bonus = contact.getShapeA()->getBody()->getTag(); } else { bonus = contact.getShapeB()->getBody()->getTag(); } bonusHandler(); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(BONUS_PICKUP); } else { botoIsAlive = false; BotoSprite::remove(contact, this); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(MEGABLOCK_DESTROYED); gameOverHandler(); //endgame } point = Blocks::remove(contact, this); Blocks::emittParticles(this, point); } //block collision with Ground //block is destroyed if (CollisionManager::CheckCollision(contact, BLOCKS_BITMASK, GROUND_BITMASK)) { CCLog("Block collision with ground"); point = Blocks::remove(contact, this); Blocks::emittParticles(this, point); Coins::generateCoins(this, 1, point, COINS_ZORDER); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(BLOCK_BREAK); } //collsion with coin //coin is destroyed if (CollisionManager::CheckCollision(contact, COIN_BITMASK, BOTO_BITMASK)) { CCLog("Coin collision with boto"); Coins::remove(contact, this); points += POINTS * multiplier; sprintf(text, "Points: %d", points); pointsLabel->setString(text); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(COIN_PICKUP); } //collision with megablock if (CollisionManager::CheckCollision(contact, MEGABLOCK_BITMASK, BOTO_BITMASK) || CollisionManager::CheckCollision(contact, MEGABLOCK_BITMASK, GROUND_BITMASK)) { CCLog("MEGABLOCK PREVOZMOGAET!!"); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(MEGABLOCK_DESTROYED); botoSprite->remove(this); point = megaBlock->remove(this); for(int i = 0; i < 5; i++) { Blocks::emittParticles(this, Point( point.x + rand() % (int)visibleSize.width/10 - visibleSize.width/20, point.y + rand() % (int)visibleSize.height/10 - visibleSize.height/20)); } gameOverHandler(); } return true; }