Example #1
0
void updateTankFlashing() {
	if (isTankHit() && TankFlashTime >= TANK_FLASH_TICKS && tankFlashNum != FLASH_TICKS){
		setExplosionFlag(1);
		tankFlashNum++;
		TankFlashTime = 0;
		TankFlashState = !TankFlashState;
		if (tankFlashNum <= 1)
			flashTank(TankFlashState, true);
		else
			flashTank(TankFlashState, false);
	}
	if (isTankHit() && tankFlashNum == FLASH_TICKS){
		tankFlashNum = 0;
		TankFlashState = true;
		flashTank(TankFlashState, false);
		setTankHit(false);
		setLives(getLives()-1);
		// Take out one of the lives
		int startRow = 5;
		int startCol = 490 + (getLives())*40;
		drawTank(true, startRow , startCol);
		// Check if game over
		if (getLives() == 0) {
			setEndOfGame(true);
		} else {
			setTankPositionGlobal(20); // Reset Tank
			drawTank(false, 0, 0);
		}
	}
	TankFlashTime++;
}
Example #2
0
    void Paddle::die() {
        setLives(getLives() - 1);
        updateLives();

        if(getLives() > 0) {
            reset();
            updateView(_view);
        }
    }
Example #3
0
void StudentWorld::setDisplayText()
{
	int score = getScore();
	int round = roundNumber();
	double energyPercent = (double(m_player->currentEnergy()/50)*100);
	int torpedoes = m_player->numberOfTorpedoes();
	int shipsLeft = getLives();
	std::string s = FormatGameStatText(score, round, energyPercent, torpedoes, shipsLeft);
	setGameStatText(s);
}
Example #4
0
void StudentWorld::updateDisplayText()
{
	int score = getScore();
	int round = getRoundNumber();
	double energyPercent = ptrToShip->getEnergyPct();
	int torpedos = ptrToShip->getNumTorpedos();
	int shipsLeft = getLives();
	string s = formatDisplay(score, round, energyPercent, torpedos, shipsLeft);
	setGameStatText(s);
}
Example #5
0
void Game::reset()
{
	// Called when the ball is off screen (missed by paddle)
	// Reset the ball object

	// Subtract one life
	setLives(getLives() - 1);
	Ball* ball = (Ball*)getGameObjectByType(GAME_BALL_TYPE);
	if(ball != NULL)
	{
		float prevSpeed = ball->getSpeed();
		ball->reset();
		ball->setSpeed(prevSpeed);
	}

	// Once the player runs out of lives call the gameOver function
	if(getLives() <= 0)
	{
		gameOver();
	}
}
bool Battleship::checkEnd() {
	if (getHitPoints() == getScore()) { // Has all of battleship been hit?
		cout << "You sunk the battleship!" << endl;
		cout << "YOU WIN!" << endl;

		asciiThumbsUp();

		return true;
	}
	else if (getLives() == 0) {
		cout << "You have no shots left..." << endl << endl;
		cout << "YOU LOSE!" << endl << endl;
		cout << "Here is where the battleship was:" << endl;
		printBattleground();
		return true;
	}
	else {
		cout << "You have " << getScore() << " hits and " << getLives() << " shots left..." << endl << endl;
		return false;
	}
}
Example #7
0
    void Paddle::aquire(const Item& item, Ball& ball) {
        switch(item.getType()) {
            case Item::Type::PaddleSize:
                if(getWidth() < 90) {
                    setWidth(getWidth() + 10);
                    setPositionRange(255, 544 - getWidth());

                    if(_position.x - 5 > _positionRange.x)
                        _position.x -= 5;

                    updateView(_view);
                }
                break;

            case Item::Type::ExtraLive:
                setLives(getLives() + 1);
                updateLives();
                break;

            case Item::Type::BallSpeedReduction:
                ball.resetSpeedFactor();
                break;
        }
    }
Example #8
0
 void Paddle::updateLives() const {
     Game::get().getWindow().appendTitle(std::string(" | Lives left: ") + std::to_string(getLives()));
 }
Example #9
0
 void Paddle::update(double deltaTime) {
     if(getLives() > 0)
         updatePosition(deltaTime);
 }
Example #10
0
void Game::levelUp()
{
	// This function is called when a player clears all bricks from the screen

	// Increase the number of lives by 1
	setLives(getLives() + 1);
	// Increase the rounds
	m_Round++;

	// If the current round is equal to or greater than the max rounds 
	if(m_Round > GAME_MAX_ROUNDS)
	{
		// Start a new game
		newGame();
	}

	// Sets the background image colour based on the current round
	switch(m_Round)
		{
		case 0:
			// Default
			m_Textures[0]->setColor(OpenGLColorRGB(1.0f, 1.0f, 1.0f));
			break;
		case 1:
			// Green
			m_Textures[0]->setColor(OpenGLColorRGB(0.5f, 1.0f, 0.5f));
			break;
		case 2:
			// Orange
			m_Textures[0]->setColor(OpenGLColorRGB(1.0f, 0.5f, 0.0f));
			break;
		case 3:
			// Purple
			m_Textures[0]->setColor(OpenGLColorRGB(0.5f, 0.5f, 0.0f));
			break;
		case 4:
			// Red
			m_Textures[0]->setColor(OpenGLColorRGB(1.0f, 0.5f, 0.5f));
			break;
		case 5:
			// Yellow
			m_Textures[0]->setColor(OpenGLColorRGB(1.0f, 1.0f, 0.0f));
			break;
		}

	// Add another row of bricks
	for(int i = 0; i < GAME_BRICKS_PER_ROW; i++)
	{
		addGameObject(new Brick());
	}


	Ball* ball = (Ball*)getGameObjectByType(GAME_BALL_TYPE);
	if(ball != NULL)
	{
		// Increases the ball's speed by 25% each time this function is called
		// Change GAME_SPEED_MOD in globals to change the speed increase per level
		float prevSpeed = ball->getSpeed();

		// Go through all game objects and reset them
		// Except for the paddle
		for(int i = 0; i < m_GameObjects.size(); i++)
		{
			if(m_GameObjects.at(i)->getType() != GAME_PADDLE_TYPE)
			{
				m_GameObjects.at(i)->reset();
			}
		}

		ball->setSpeed(prevSpeed * GAME_SPEED_MOD);
	}

	// Call the placeBrick function to space bricks
	// For a new round of play
	placeBricks();
}
Example #11
0
bool Campaign::loadProgress ()
{
	if (!_persister->loadCampaign(this)) {
		return false;
	}
	Log::info(LOG_CAMPAIGN, "loaded campaign progress for: %s (lives: %i)", getId().c_str(), static_cast<int>(getLives()));
	_currentMap = 0;
	for (Campaign::MapListConstIter i = _maps.begin(); i != _maps.end(); ++i) {
		if (!(*i)->isLocked())
			++_currentMap;
		else
			break;
	}

	return true;
}
Example #12
0
void Campaign::setLives (uint8_t lives)
{
	Log::debug(LOG_CAMPAIGN, "set lives: %i", static_cast<int>(getLives()));
	_lives = lives;
}