Example #1
0
void EngineGraphic::Run(sf::RenderWindow &App, config &configuration)
{
    //CrĂ©er la fenĂȘtre
    MyImageManager.build(configuration);
    App.Create(VideoMode(LARGEUR_FENETRE+120,HAUTEUR_FENETRE,32),"SFML moteur 2D");
    App.SetFramerateLimit(60);
}
Example #2
0
void MainMenuHandler::run(sf::RenderWindow& window) {
	ImageCache mainMenuImages;
	const sf::Image& logoImage = mainMenuImages.get(Path::findDataPath("graphics/logo.png"));

	// Entering main menu, no game should be running.
	GameHandler::instance.reset();

	// Make view that is as close to 640x480 as possible and centered.
	view = window.GetDefaultView();
	view.Zoom(std::min(view.GetRect().GetWidth() / 640, view.GetRect().GetHeight() / 480));
	view.SetCenter(view.GetHalfSize());
	window.SetView(view);

	window.SetFramerateLimit(30);

	// Position at the top of the window.
	sf::Sprite logoSprite(logoImage);
	logoSprite.SetCenter(logoImage.GetWidth() / 2, 0);
	logoSprite.SetPosition(window.GetView().GetRect().GetWidth() / 2, 1);

	// Build the main menu GUI.
	GUI::Container gui;
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("New game", 200, 100, 240, 50, boost::bind(&MainMenuHandler::startGame, this))));
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("Exit", 250, 170, 140, 50, boost::bind(&sf::RenderWindow::Close, boost::ref(window)))));

	menuClosed = false;
	while (window.IsOpened() && !menuClosed) {
		sf::Event e;
		if (window.GetEvent(e)) {
			if (gui.handleEvent(e, window)) {
				continue;
			}
			if (e.Type == sf::Event::Closed || (e.Type == sf::Event::KeyPressed && e.Key.Code == sf::Key::Escape)) {
				window.Close();
				continue;
			}
		} else {
			window.Clear(sf::Color(0xcc, 0x66, 0x33));
			window.Draw(logoSprite);
			gui.draw(window);
			window.Display();
		}
	}
}
Example #3
0
int ScreenMenu::Run(sf::RenderWindow &App)
{
	//sf::Event Event;
	//sf::Image background;
	//background.LoadFromFile("Sprites\\backgroundMenu.png");
	//sf::Sprite backgroundSprite;
	//backgroundSprite.SetImage(background);

	//sf::String menuPlay("Commencer une nouvelle partie", myFont, 35);
	//menuPlay.SetPosition(150.f, 150.f);
	//sf::String menuCommandes("Aide", myFont, 35);
	//menuCommandes.SetPosition(360.f, 280.f);
	//sf::String menuQuit("Quitter", myFont, 35);
	//menuQuit.SetPosition(340.f, 410.f);

	//menuPlay.SetColor(sf::Color(0,255,0));
	//menuPlay.SetSize(37);

	////Draw (Initialisation

	//App.Clear();
	//App.Draw(backgroundSprite);
	//App.Draw(menuPlay);
	//App.Draw(menuCommandes);
	//App.Draw(menuQuit);
	//App.Display();

	int selected = 1;

	bool running = true;
	while(running)
	{
		while (App.GetEvent(Event))
		{
			//Clavier
			if (Event.Type == sf::Event::Closed)
			{
				return (SCREEN_EXIT);
			}
			if ((Event.Type == sf::Event::KeyPressed) && ((Event.Key.Code == sf::Key::Down) || (Event.Key.Code == sf::Key::Right)))
			{
				if(selected != 3)
					selected++;
				else
					selected = 1;
			}
			if ((Event.Type == sf::Event::KeyPressed) && ((Event.Key.Code == sf::Key::Up) || (Event.Key.Code == sf::Key::Left)))
			{
				if(selected != 1)
					selected--;
				else
					selected = 3;
			}

			//Joystick
			if((Event.Type == sf::Event::JoyMoved) && (Event.JoyMove.JoystickId == 0))
			{
				if((Event.JoyMove.Axis == sf::Joy::Axis::AxisX) || (Event.JoyMove.Axis == sf::Joy::Axis::AxisY))
				{
					if(Event.JoyMove.Position == 100)
					{
						if(selected != 3)
							selected++;
						else
							selected = 1;
					}
					if(Event.JoyMove.Position == -100)
					{
						if(selected != 1)
							selected--;
						else
							selected = 3;
					}
				}
			}

			if((Event.Type == sf::Event::JoyButtonPressed) && (Event.JoyMove.JoystickId == 0))
			{
				switch(selected)
				{
				case 1:
					return(SCREEN_SETUP);
					break;
				case 2:
					return(SCREEN_COMMAND);
					break;
				case 3:
					return(SCREEN_EXIT);
					break;
				}
			}



			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Return))
			{
				switch(selected)
				{
				case 1:
					return(SCREEN_SETUP);
					break;
				case 2:
					return(SCREEN_COMMAND);
					break;
				case 3:
					return(SCREEN_EXIT);
					break;
				}
			}

			//Update

			switch(selected)
			{
			case 1:
				menuPlay.SetColor(sf::Color(0,255,0));
				menuCommandes.SetColor(sf::Color(255,255,255));
				menuQuit.SetColor(sf::Color(255,255,255));
				menuPlay.SetSize(37);
				menuCommandes.SetSize(35);
				menuQuit.SetSize(35);
				break;
			case 2:
				menuPlay.SetColor(sf::Color(255,255,255));
				menuCommandes.SetColor(sf::Color(255,255,0));
				menuQuit.SetColor(sf::Color(255,255,255));
				menuPlay.SetSize(35);
				menuCommandes.SetSize(37);
				menuQuit.SetSize(35);
				break;
			case 3:
				menuPlay.SetColor(sf::Color(255,255,255));
				menuCommandes.SetColor(sf::Color(255,255,255));
				menuQuit.SetColor(sf::Color(255,0,0));
				menuPlay.SetSize(35);
				menuCommandes.SetSize(35);
				menuQuit.SetSize(37);
				break;
			}


		}

		Draw(App);
		App.SetFramerateLimit(FPS);

	}

}