Exemplo n.º 1
0
Arquivo: main.cpp Projeto: Aroltd/rts
int main() {
	//sf::RenderWindow rw(sf::VideoMode::getDesktopMode(), "test", sf::Style::Fullscreen);
	sf::RenderWindow rw(sf::VideoMode(800, 800), "test");
	rw.setFramerateLimit(60);

	rts::Map gameMap(32);

	long mclk = 0;
	sf::Clock uclk;

	while(rw.isOpen()) {
        sf::Event event;
        while (rw.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                rw.close();
			if (event.type == sf::Event::Resized)
				rw.setSize(sf::Vector2u(event.size.width,event.size.height));
        }
		
		rw.clear();
		
		if(true) {
			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
				gameMap.changeView(0,-4);

			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
				gameMap.changeView(0,4);

			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
				gameMap.changeView(-4,0);

			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
				gameMap.changeView(4,0);
		}

		sf::RectangleShape test(sf::Vector2f(400,400));
		test.setFillColor(sf::Color(0,0,0,0));
		test.setOutlineColor(sf::Color(255,255,255));
		test.setOutlineThickness(4);
		test.setPosition(200,200);

		gameMap.Render(&rw,200);
		rw.draw(test);

		rw.display();
	}
}
Exemplo n.º 2
0
void MapViewer::LoadFromFile( const std::string& filename, Map& map)
{
	int width, height, current;


    std::ifstream input(filename);

	input>>width ;//width
	input>>height;//height
	std::vector<std::vector<uint32_t>>gameMap(width);

	//map.SetXCount(width);
	//map.SetYCount(height);


	for(int i = 0;i < height; i++)//height
	{
		std::vector<uint32_t> vect(width);
		for(int j = 0; j < width; j++)//width
		{
			input>>current;
			if(current>=0 && current<=9)
			{
				vect.push_back(current);
			}
		/*	else
			{
				vect.push_back(0);
			}*/
		}
		gameMap.push_back(vect);
	}
	input.close();

//	map.SetMap(gameMap);

}
Exemplo n.º 3
0
int main()
{
	// window
	sf::RenderWindow window(sf::VideoMode((int) (780 * 1.5), (int) (565 * 1.5)), "Hexagon Fort", (sf::Style::Close | sf::Style::Titlebar));
	window.setFramerateLimit(30);
	window.setMouseCursorVisible(false);

	// cursor
	sf::Texture cursorTexture;
	if (!cursorTexture.loadFromFile("images/mouse_pointer.png")) {
		return -1; // failed to load mouse pointer image
	}
	sf::Sprite cursor(cursorTexture);
	cursor.setScale(0.175f, 0.175f);

	// Setup game manager and map
	if (!GameManager::loadNecessaryFiles()) {
		return -1; // failed to load files so terminate application
	}
	GameManager manager(window);
	int gameState = 0; // 0 = start screen, 1 = in-game, 2 = pause, 3 = gameover
	int winner = -1; // -1 = no winner, 0 = red team won, 1 = blue team won
	sf::Sprite gameMap(GameManager::gameMapTexture);
	gameMap.setScale(1.5f, 1.5f);

	// background music
	sf::Music backgroundMusic;
	if (!backgroundMusic.openFromFile("sounds/Failing_Defense.ogg")) {
		return -1; // could not find the Failing_Defense music
	}
	backgroundMusic.setLoop(true);
	backgroundMusic.setVolume(25);
	backgroundMusic.play();

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}

		if (window.isOpen()) {
			if (gameState == 0) {
				if (manager.isOnStartButton((sf::Vector2f) sf::Mouse::getPosition(window)) && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
					//manager = GameManager(window); do not need to do this as we already initialized GameManager object
					gameState = 1; // go to in game
					winner = -1; // no winner
					GameManager::areTimersViable = true;
				}
			}
			else if (gameState == 1) {
				manager.runGameManager(window, 20, 0.75f);
				if (manager.getBlueTeamHealth() <= 0) {
					gameState = 3; // go to game over!
					winner = 0; // red won
					GameManager::areTimersViable = false;
				}
				else if (manager.getRedTeamHealth() <= 0) {
					gameState = 3; // go to game over!
					winner = 1; // blue won
					GameManager::areTimersViable = false;
				}
				else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
					gameState = 2; // go to pause game
					backgroundMusic.pause();
					GameManager::areTimersViable = false;
				}
			}
			else if (gameState == 2) {
				if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && sf::IntRect(window.getPosition(), (sf::Vector2i) window.getSize()).contains(sf::Mouse::getPosition(window)) || sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
					gameState = 1; // go to in game (continue game)
					backgroundMusic.play();
					GameManager::areTimersViable = true;
				}
			}
			else if (gameState == 3) {
				if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && sf::IntRect(window.getPosition(), (sf::Vector2i) window.getSize()).contains(sf::Mouse::getPosition(window)) || sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
					manager = GameManager(window);
					gameState = 1; // go to in game (restart game)
					winner = -1; // no winner
					GameManager::areTimersViable = true;
				}
			}
		}

		window.clear();

		window.draw(gameMap); // background map texture
		manager.draw(window, gameState, winner);

		if (window.isOpen()) {
			cursor.setPosition((sf::Vector2f)sf::Mouse::getPosition(window));
			window.draw(cursor);
		}

		window.display();
	}

	return 0;
}