コード例 #1
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_loss()
{
	if (_gameState != Uninitialized)
		return;

	game_victory = 0;
	_mainWindow.create(sf::VideoMode(1024, 768, 32), "Anne McLaughlin Demo");
	_view.reset(sf::FloatRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
	_view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));

	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->coins = 0;
	player->lives = 0;
	player->grounded = true;


	reset_mystery_blocks();


	_gameState = Game::ShowingSplashLoss;

	while (!isExiting())
	{
		gameLoop();
	}
	_mainWindow.close();
}
コード例 #2
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_victory(void)
{
	if (_gameState != Uninitialized)
		return;

	game_victory = 0;
	_mainWindow.create(sf::VideoMode(1024, 768, 32), "Anne McLaughlin Demo");
	_view.reset(sf::FloatRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
	_view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));

	PlayerCharacter * player = (PlayerCharacter *) _gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->coins = 0;
	player->lives = 0;
	player->grounded = true;


	reset_mystery_blocks();

	/*Background * bg = new Background();
	level_width = bg->getSprite().getGlobalBounds().width;
	level_height = bg->getSprite().getGlobalBounds().height;

	createFloor();

	_gameObjectManager.add("Background", bg);

	createLevelBlocks();

	rigidBodyCoords = findRigidBodies();*/

	_gameState = Game::ShowingSplashVictory;

	while (!isExiting())
	{
		gameLoop();
	}
	_mainWindow.close();
}
コード例 #3
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_again()
{
	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->grounded = true;
}
コード例 #4
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::handleSurfaces()
{
	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.get("PlayerCharacter");
	RigidSurface_Brick * v_block = (RigidSurface_Brick *)_gameObjectManager.get("block_victory");

	if (player->getSprite().getGlobalBounds().intersects(v_block->getSprite().getGlobalBounds()))
	{
		game_victory = 1;
	}

	if (display_coin)
	{
		coin_animation_frames--;
		if (coin_animation_frames <= 0)
		{
			display_coin = false;
			Coin * coin = (Coin *) _gameObjectManager.getByTypeSingle("Coin");
			coin->isVisible = false;
			coin_animation_frames = 150;
		}
	}

	for (int i = 0; i < rigidBodyCoords.size(); ++i)
	{
		if (player->getSprite().getGlobalBounds().intersects(rigidBodyCoords[i]->getSprite().getGlobalBounds()))
		{
			if (rigidBodyCoords[i]->getType() == "RigidSurface_Mystery")
			{
				RigidSurface_Mystery * block = (RigidSurface_Mystery *) rigidBodyCoords[i];
				if (block->times_hit < 3)
				{
					display_coin = true;
					Coin * new_coin = new Coin();
					initObject(new_coin,
						sf::Vector2f(rigidBodyCoords[i]->getSprite().getGlobalBounds().left, rigidBodyCoords[i]->getSprite().getGlobalBounds().top - 100)
						, "coin" + std::to_string(player->coins));
					player->coins++;
					block->times_hit++;
					std::cout << "Coins: "  << player->coins << std::endl;
					std::cout << "Lives: " << player->lives << std::endl;
					if (player->coins % 10 == 0)
					{
						player->lives++;
					}
				}
				else
				{
					//block is dead
				}

				player->velocity.x = -player->velocity.x;
				if (player->velocity.y < 0)
				{
					player->velocity.y = -2* player->velocity.y;
				}

				if (player->velocity.y > 0)
				{
					player->setPosition(player->getPosition().x, player->getPosition().y - 1);
					player->grounded = true;
				}
			}

			else
			{
				if (player->velocity.y > 0)
				{
					player->setPosition(player->getPosition().x, player->getPosition().y - 1);
					//player->velocity.x = -player->velocity.x;
					//TO-DO: Distinguish between bumping horizontally and landing vertically on blocks.
					//TO-DO: Make kitty stop floating
					player->grounded = true;
				}
				else
				{
					player->velocity.x = -player->velocity.x;
				}
				
			}
		}
	}
}