// add one to stack counter
void MapManager::addStackToCounter() {
	df::LogManager &lm = df::LogManager::getInstance();
	lm.writeLog("IM GETTIN CALLED\n\n\n");
	if (stackCounter == stackNeeded){
		loadNextLevel();
	}
	else {
		stackCounter++;
	}
}
Beispiel #2
0
void GameEngine::cheatSkipLevel() 
{
    if (m_cheatsEnabled) {
        loadNextLevel();
    }
}
Beispiel #3
0
//the primary method for the game
//initializes the level and loops until the level is beaten
void Game::playLevel()
{
	//re-saves the player's stats
	al.SaveStats();

	char dir;
	int x, y;
	string place;

	bool bossBeaten = false;
	bool keyFound = false;
	bool moved = false;

	//creates and stores the first 2 bosses
	Enemy** bosses = new Enemy*[2];
	bosses[0] = new Dragon();
	bosses[1] = new Gorilla();

	//creates the final boss
	Seminole s;

	//creates the random enemies that will pop up throughout the game
	//type 1 is weaker than type 2
	Enemy** type1 = new Enemy*[3];
	Enemy** type2 = new Enemy*[3];

	//prints out the intro screen based on the level
	switch (level)
	{
	case 1:
		Level1IntroScrn();
		break;

	case 2:
		Level2IntroScrn();
		break;

	case 3:
		Level3IntroScrn();
		break;
	}

	//stores the maps data in a game field
	mapData = map.getMapData();

	//place character: bottom middle
	x = (map.getColumns() - 1) / 2;
	y = map.getRows() - 1;
	al.SetLocation(x, y);

	//a random number generator that will determine what events take place in the game
	uniform_int_distribution < mt19937::result_type > dist(1, 100);
	mt19937 gen = al.GetGen();
	int random;

	//loops until the player quits or the boss is beaten
	while (playing == true && !bossBeaten)
	{
		//checks if al has enough experience to level up
		if (al.GetExperience() >= al.GetLevelUpEXP())
		{
			al.LevelUp();
			LevelUpScrn();
		}

		//prints out the map screen
		update();

		//reverts the values stored in game at the start of each loop
		message = "";
		random = dist(gen);
		moved = false;

		//sets x and y to the player's new location
		x = al.GetxLocation();
		y = al.GetyLocation();

		//adds new enemies to the enemy type vectors to randomize their levels
		type1[0] = new Bat();
		type1[1] = new Rhino();
		type1[2] = new Centaur();

		type2[0] = new Scorpion();
		type2[1] = new Tiger();
		type2[2] = new Griffin();

		//if possible -> move
		dir = getch();

		switch (dir)
		{
		case 'w':
			//if possible, move up
			if ((y - 1) >= 0 && allow[y - 1][x])
			{
				al.MoveUp();
				moved = true;
			}
			break;
		case 's':
			//if possible, move down
			if ((y + 1) < map.getRows() && allow[y + 1][x])
			{
				al.MoveDown();
				moved = true;
			}
			break;
		case 'a':
			//if possible, move left
			if ((x - 1) >= 0 && allow[y][x - 1])
			{
				al.MoveLeft();
				moved = true;
			}
			break;
		case 'd':
			//if possible, move right
			if ((x + 1) < map.getColumns() && allow[y][x + 1])
			{
				al.MoveRight();
				moved = true;
			}
			break;
		case '3':
			//if possible, eat
			message = al.Eat();
			break;
		case '4':
			//if possible, drink
			message = al.Drink();
			break;
		case 'q':
			//calls quit screen
			QuitScrn();
			break;
		default:
			//creates error if invalid key is pressed
			message = "Invalid key pressed!";
			break;
		}

		//runs if the player has moved on the map
		if (moved)
		{
			//with new position
			x = al.GetxLocation();
			y = al.GetyLocation();

			//stores the place value located at the player's location
			place = mapData[y][x];

			//triggers if the player enters a house
			if (place.compare("H") == 0)
			{
				//find food
				if (random <= 75)
				{
					message = "You found some food in the House";
					al.FindFood();
				}
				//trigger non-fleeable combat
				if (random > 75 && random <= 85)
				{
					playing = NFCombat(&al, type1[level - 1]);
				}
				//find bed and sleep
				if (random > 85 && random <= 95)
				{
					message = "You found a nice comfy bed. Gained health && stamina!";
					al.Sleep();
				}
				//stub toe and lose health
				if (random > 95)
				{
					message = "You stubbed your toe! You lost 5 health!";
					al.ChangeHealth(-5);
				}
				//makes the house no longer enterable
				allow[y][x] = 0;
			}
			//triggers if the player enters a tower
			else if (place.compare("T") == 0)
			{
				//combat with an enemy of both type
				playing = NFCombat(&al, type1[level - 1]);
				playing = NFCombat(&al, type2[level - 1]);

				//if the player survives he gets the key to the boss
				if (playing)
				{
					keyFound = true;
				}
				//makes the tower no longer enterable
				allow[y][x] = 0;
			}
			//triggers if the player finds a gatorade machine
			else if (place.compare("G") == 0)
			{
				//find gatorade
				al.FindGatorade();
				message = "You found a Gatorade machine! Your Gatorade has increased!";
				allow[y][x] = 0;
			}
			//triggers if the player enters barracks
			else if (place.compare("M") == 0)
			{
				//step on landmine
				if (random <= 10)
				{
					message = "You stepped on a landmine";
					al.ChangeHealth(-20);
				}
				//find extra food
				if (random > 10 && random <= 30)
				{
					message = "You found some army rations!";
					al.FindFood();
					al.FindFood();
				}
				//fight two strong enemies
				if (random > 30 && random <= 50)
				{
					playing = NFCombat(&al, type2[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//fight a strong and weak enemy
				if (random > 50 && random <= 65)
				{
					playing = NFCombat(&al, type1[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//caught in a booby trap and lose health
				if (random > 65 && random <= 75)
				{
					message = "You got caught in a booby trap, oops!";
					al.ChangeHealth(-5);
				}
				//find scale and gain stamina
				if (random > 75 && random <= 97)
				{
					message = "You found one of Alberta's scales! Your stamina returns!";
					al.ChangeStamina(10);
				}
				//fight 3 monsters
				if (random > 97)
				{
					playing = NFCombat(&al, type2[level - 1]);
					playing = NFCombat(&al, type1[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//makes the barracks no longer enterable
				allow[y][x] = 0;
			}
			//level boss
			else if (place.compare("B") == 0)
			{
				//key used to fight boss
				if (keyFound)
				{
					//first two bosses
					if (level < 3)
					{
						bossBeaten = NFCombat(&al, bosses[level - 1]);
						playing = bossBeaten;
					}
					//final boss
					if (level == 3)
					{
						bossBeaten = FinalBossCombat(&al, &s);
						playing = true;
					}

					if (bossBeaten)
					{
						//beat game
						if (level == 3)
						{
							BeatGameScrn();
						}
						//move to next level
						else
						{
							loadNextLevel();
						}
					}
				}
				else
				{
					message = "You must find the key before you can battle the boss!";
				}
			}
			else //if place="//"
			{
				if (random <= 17)
				{
					//chooses randomly type 1 or type 2 enemy for level
					random = dist(gen);
					if (random <= 62)
					{
						playing = Combat(&al, type1[level - 1]);
					}
					else
					{
						playing = Combat(&al, type2[level - 1]);
					}
				}
			}
		}

		//check to see if player is dead or quit
		if (al.GetHealth() == 0 || (!playing && !bossBeaten && !quit))
		{
			GameOverScrn();
		}

		//cleans the game if you are no longer playing
		if (playing == false)
		{
			Clean(bosses, type1, type2);
		}

		//removes old enemies so that new enemies can be initialized at the beginning of the loop
		for (int i = 0; i < 3; i++)
		{
			delete type1[i];
			delete type2[i];
		}
	}
}
Beispiel #4
0
void Wallbreaker::onEvent(const sf::Event& event)
{
	switch (m_status)
	{
		case PLAYING:
			switch (event.type)
			{
				case sf::Event::KeyPressed:
					switch (event.key.code)
					{
						case sf::Keyboard::F2:
							Game::getInstance().takeScreenshot();
							break;
						case sf::Keyboard::Escape:
							setStatus(PAUSED);
							break;
						case sf::Keyboard::Space:
							if (m_paddle.isSticky())
								applyOnEachBall(&Ball::unstick);
							else if (m_paddle.hasLaser())
								addEntity(m_paddle.shoot());
							break;
#ifdef WALLBREAKER_DEBUG
						case sf::Keyboard::R: // Reload level
							m_remaining_bricks = m_level.reload();
							m_hud.setBrickCount(m_remaining_bricks);
							break;
						case sf::Keyboard::N: // Go to next level
							loadNextLevel();
							break;
						case sf::Keyboard::G: // Simulate LARGE_PADDLE
							m_paddle.grow();
							break;
						case sf::Keyboard::S: // Simulate SMALL_PADDLE
							m_paddle.shrink();
							break;
						case sf::Keyboard::Y: // Simulate STICKY_PADDLE
							m_paddle.activeSticky();
							break;
						case sf::Keyboard::L: // Simulate LASER_PADDLE
							m_paddle.activeLaser();
							break;
						case sf::Keyboard::T: // Simulate TRIPLE_BALL
							createBall();
							createBall();
							break;
						case sf::Keyboard::P: // Simulate POWER_BALL
							applyOnEachBall(&Ball::enablePowerBall);
							break;
						case sf::Keyboard::E: // Simulate SPEED_RESET
							applyOnEachBall(&Ball::resetSpeed);
							break;
#endif
						default:
							break;
					}
					break;

				case sf::Event::MouseButtonPressed:
					if (m_paddle.isSticky())
						applyOnEachBall(&Ball::unstick);
					else if (m_paddle.hasLaser())
						addEntity(m_paddle.shoot());
					break;

				case sf::Event::LostFocus:
					setStatus(PAUSED);
					break;

				default:
					break;
			}
			break;

		case PAUSED:
			switch (m_pause_menu.onEvent(event))
			{
				case 1: // Resume
					setStatus(PLAYING);
					break;
				case 2: // Go to options menu
					Game::getInstance().setCurrentScreen("OptionsMenu");
					break;
				case 3: // Clear game and back to main menu
					resetGame();
					Game::getInstance().restorePreviousScreen();
					break;
				default:
					// Resume
					if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
						setStatus(PLAYING);
					break;
			}
			break;

		case READY:
			if (event.type == sf::Event::MouseButtonPressed)
				setStatus(PLAYING);
			break;

		case GAME_OVER:
			switch (m_game_over_menu.onEvent(event))
			{
				case 1: // Continue (reload current level)
					resetGame(m_level.getCurrentLevel());
					break;
				case 2: // Clear game and back to main menu
					resetGame();
					Game::getInstance().restorePreviousScreen();
					break;
			}
			break;
	}
}
Beispiel #5
0
void Wallbreaker::updateEntities(float frametime)
{
	// For each entity
	for (EntityList::iterator it = m_entities.begin(); it != m_entities.end();)
	{
		Entity& entity = **it;
		if (entity.isAlive())
		{
			sf::Vector2f old_pos = entity.getPosition();
			entity.onUpdate(frametime);

			// Ensure entity doesn't go beyond the walls
			if (entity.getY() < 0)
			{
				entity.onCeilHit();
				entity.setY(0);
			}
			else if (entity.getPosition().x < 0)
			{
				entity.onWallHit();
				entity.setX(0);
			}
			else if (entity.getX() + entity.getWidth() > m_width)
			{
				entity.onWallHit();
				entity.setX(m_width - entity.getWidth());
			}
			// Kill entities if they go beyond the bottom line
			else if (entity.getY() > m_height)
			{
				entity.kill();
			}
			// Check if entity collides with paddle
			else if ((entity.getY() + entity.getHeight() > m_paddle.getY())
			      && (entity.getY() < m_paddle.getY())
			      && (entity.getX() + entity.getWidth() > m_paddle.getX())
			      && (entity.getX() < m_paddle.getX() + m_paddle.getWidth()))
			{
				entity.setY(m_height - m_paddle.getHeight() - entity.getHeight());
				entity.onPaddleHit(m_paddle);
			}
			// Check if entity is colliding with a brick
			else
			{
				// Get corners
				int left =   (int) entity.getX() / Brick::WIDTH;
				int top =    (int) entity.getY() / Brick::HEIGHT;
				int right =  (int) (entity.getX() + entity.getWidth())  / Brick::WIDTH;
				int bottom = (int) (entity.getY() + entity.getHeight()) / Brick::HEIGHT;

				if (checkBrick(entity, top, left, old_pos)
				 || checkBrick(entity, top, right, old_pos)
				 || checkBrick(entity, bottom, left, old_pos)
				 || checkBrick(entity, bottom, right, old_pos))
				{
					if (m_remaining_bricks == 0)
					{
						if (m_level.getCurrentLevel() == m_level.getLevelCount())
						{
							setStatus(GAME_OVER);
						}
						else
						{
							loadNextLevel();
							setStatus(READY);
						}
						break;
					}
				}
			}
			++it;
		}
		else
		{
			// Remove dead entity from entity list
			delete *it;
			it = m_entities.erase(it);
			if (Ball::getCount() == 0)
			{
				m_hud.setLiveCount(--m_player_lives);
				SoundSystem::playSound("life-lost.ogg");
				setStatus(m_player_lives == 0 ? GAME_OVER : READY);
				break;
			}
		}
	}
}
//------------------------------------------------------------------------------
void startMapRotation()
{
    loadNextLevel(NULL);
}
Beispiel #7
0
/**
 *	@method CGame::UpdateFrame()
 *	@desc   called every frame, calls the update methods of all other game managers
 */
void CGame::UpdateFrame(DWORD milliseconds)
{
	keyProcess();
	InputManagerC::GetInstance()->update(milliseconds);
	AngryBirdsMouse::getInstance()->update();

	if (CGame::mGameState == LEVEL)
	{
		PhysicsWorld::getInstance()->update(milliseconds);
		level->update(milliseconds);

		if (GetBirdCount() != 0)
			PlayerManager::getInstance()->update(milliseconds);
		BlockManager::getInstance()->update();
		PigManager::getInstance()->update(milliseconds);

		nextButton->update();
		previousButton->update();
		resetButton->update();
		if (nextButton->isButtonPressed())
		{
			levelNumber++;
			loadNextLevel();
		}
		if (previousButton->isButtonPressed())
		{
			levelNumber--;
			if (levelNumber < 0)
			{
				levelNumber = 0;
			}
			loadNextLevel();
		}
		if (resetButton->isButtonPressed())
		{
			loadNextLevel();
		}
	}


	if (CGame::mGameState == START_MENU)
	{
		playButton->update();
		if (playButton->isButtonPressed())
		{
			CGame::mGameState = LEVEL;

			Background::getInstance()->loadBackground(levelBackgroundSrc);

			level = new Level();
			level->init();

			TiXmlHandle docHandle(doc);
			PlayerManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("birds", 0).Element(), docHandle.FirstChildElement().ChildElement("catapult", 0).Element(), docHandle.FirstChildElement().ChildElement("birdpoof", 0).Element());
			BlockManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("blocks", 0).Element());
			PigManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("pigs", 0).Element(), docHandle.FirstChildElement().ChildElement("poof", 0).Element());

			PlayerManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("birds", 0).Element());
			BlockManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("blocks", 0).Element());
			PigManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("pigs", 0).Element());
		}

	}

}