Example #1
0
void MainMenu::initMap(sf::RenderWindow &window, TextureManager &textureManager)
{
	//hardcoded positions

	backgroundSprite.setTexture(*textureManager.getResource("Config/Content/Images/Menus/Backgrounds/MainMenuBackground.png"));

	sf::RectangleShape playButton;
	playButton.setSize(sf::Vector2f(143.0f, 72.0f));
	playButton.setTexture(textureManager.getResource("Config/Content/Images/Menus/Buttons/playButton.png"));
	playButton.setPosition(window.getSize().x / 2 - playButton.getSize().x / 2, 210);

	sf::RectangleShape creditsButton;
	creditsButton.setSize(sf::Vector2f(213.0f, 72.0f));
	creditsButton.setTexture(textureManager.getResource("Config/Content/Images/Menus/Buttons/creditsButton.png"));
	creditsButton.setPosition(window.getSize().x / 2 - creditsButton.getSize().x / 2, 295);

	sf::RectangleShape highScoresButton;
	highScoresButton.setSize(sf::Vector2f(338.0f,72.0f));
	highScoresButton.setTexture(textureManager.getResource("Config/Content/Images/Menus/Buttons/highScoreButton.png"));
	highScoresButton.setPosition(window.getSize().x / 2 - highScoresButton.getSize().x / 2, 380);

	sf::RectangleShape exitButton;
	exitButton.setSize(sf::Vector2f(134.0f,72.0f));
	exitButton.setTexture(textureManager.getResource("Config/Content/Images/Menus/Buttons/exitButton.png"));
	exitButton.setPosition(window.getSize().x / 2 - exitButton.getSize().x / 2, 465);

	menuItems[PLAY] = playButton;
	menuItems[CREDITS] = creditsButton;
	menuItems[HIGHSCORES] = highScoresButton;
	menuItems[EXIT] = exitButton;
}
Example #2
0
Aircraft::Aircraft(Type type, const TextureManager& textures, const FontManager& fonts)
: Entity(Table[type].hitpoints)
, mType(type)
, mSprite(textures.getResource(Table[type].texture), Table[type].textureRect)
, mExplosion(textures.getResource(Textures::Id::Explosion))
, mFireCommand()
, mMissileCommand()
, mFireCountdown(sf::Time::Zero)
, bFiring(false)
, bLaunchingMissile(false)
, bShowExplosion(true)
, bSpawnedPickup(false)
, bPlayedExplosionSound(false)
// , bMarkedForRemoval(false)
, mFireRateLevel(1)
, mSpreadLevel(1)
, mMissileAmmo(24)
, mDropPickupCommand()
, mTravelledDistance(0.f)
, mDirectionIndex(0)
// , mHealthDisplay(nullptr)
, mMissileDisplay(nullptr)
{
  // sf::FloatRect bounds = mSprite.getLocalBounds();

  mExplosion.setFrameSize(sf::Vector2i(256, 256));
  mExplosion.setFrameCount(16);
  mExplosion.setDuration(sf::seconds(1));

  mSprite.setOrigin(mSprite.getLocalBounds().width / 2.f, mSprite.getLocalBounds().height / 2.f);
  mExplosion.setOrigin(mExplosion.getLocalBounds().width / 2.f, mExplosion.getLocalBounds().height / 2.f);

  mFireCommand.category = Category::SceneAirLayer;
  mFireCommand.action = [this, &textures] (SceneNode& node, sf::Time) { createBullets(node, textures); };

  mMissileCommand.category = Category::SceneAirLayer;
  mMissileCommand.action = [this, &textures] (SceneNode& node, sf::Time) // FIX
    { createProjectile(node, Projectile::Missile, 0.f, 0.5f, textures); };

  mDropPickupCommand.category = Category::SceneAirLayer;
  mDropPickupCommand.action = [this, &textures] (SceneNode& node, sf::Time) { createPickup(node, textures); };

  std::unique_ptr<TextNode> healthDisplay(new TextNode("", fonts));
  mHealthDisplay = healthDisplay.get();
  attachChild(std::move(healthDisplay));

  if (getCategory() == Category::PlayerAircraft) {
    std::unique_ptr<TextNode> missileDisplay(new TextNode("", fonts));
    missileDisplay->setPosition(0, 70);
    mMissileDisplay = missileDisplay.get();
    attachChild(std::move(missileDisplay));
  }

  updateTexts();
}
Example #3
0
void CreditsMenu::initMap(sf::RenderWindow &window, TextureManager &textureManager)
{
	//hardcoded positions

	backgroundSprite.setTexture(*textureManager.getResource("Config/Content/Images/Menus/creditsScreen.png"));

	sf::RectangleShape backButton;
	backButton.setSize(sf::Vector2f(120.0f, 50.0f));
	backButton.setTexture(textureManager.getResource("Config/Content/Images/Menus/backButton.png"));
	backButton.setPosition(window.getSize().x / 2 - backButton.getSize().x / 2, 520);

	menuItems[BACK] = backButton;
}
Example #4
0
void World::Load(const std::string filepath, sf::RenderWindow &window, TextureManager &textureManager, FontManager &fontManager)
{
	isGameOver = -1;

	//open up the file
	std::filebuf fb;
	fb.open(filepath, std::ios::in);

	//try to parse it
	Json::Value root;
	Json::Reader reader;
	bool parseSuccessful = reader.parse(std::istream(&fb), root);
	if(!parseSuccessful)
	{
		std::cerr << "Unsuccessful parse" << filepath << std::endl;
		std::cerr << reader.getFormattedErrorMessages() << std::endl;
		return;
	}
	//now we have it parsed we can close it
	fb.close();

	//set the background
	std::string backgroundFilepath = root.get("background", "").asString();
	if(!backgroundFilepath.empty())
	{
		worldSprite.setTexture(*textureManager.getResource(backgroundFilepath));
		worldSprite.setScale((float)window.getSize().x / worldSprite.getTexture()->getSize().x, (float)window.getSize().y / worldSprite.getTexture()->getSize().y);
	}

	//hardcoded values
	winTexture = *textureManager.getResource("Config/Content/Images/Menus/Backgrounds/WinBackground.png");
	loseTexture = *textureManager.getResource("Config/Content/Images/Menus/Backgrounds/LoseBackground.png");

	//build the walls
	Json::Value walls = root["walls"];
	for(unsigned int i = 0; i < walls.size(); i++)
	{
		Json::Value wall = walls[i];
		std::string filepath = wall["name"].asString();
		sf::Vector2f position(wall["position"]["x"].asFloat(), wall["position"]["y"].asFloat());
		EntityBuilder::getInstance()->buildEntity(filepath, position);
	}

	//build the player
	EntityBuilder::getInstance()->buildPlayer("Config/Entities/Characters/Player.json", sf::Vector2f(400, 300));
	
	//set level mode, normal or survival
	mode = (Mode) root.get("mode", NORMAL).asInt();

	//build hud
	Json::Value hudValue = root.get("hud", NULL);
	const sf::Texture *healthBarPtr = textureManager.getResource(hudValue.get("healthBar", NULL).asString());
	const sf::Texture *healthBarBackgroundPtr = textureManager.getResource(hudValue.get("healthBarBackground", NULL).asString());
	hud.init(*healthBarPtr, *healthBarBackgroundPtr, entityManager.getVector(PLAYER), fontManager, mode);
	
	//load the enemy waves, mode is important
	enemySpawnManager.load(root, &entityManager, mode);

	playerLoseClock.pause();
	playerLoseClock.restart();
}