Exemplo n.º 1
0
void showCredits(sf::RenderWindow& app)
{
  Credits credit(app);

  //Credits loop
  while (app.IsOpened()) {

    //Process events
    sf::Event Event;

    //Window closed
    while (app.GetEvent(Event)) 
    {
      if(Event.Type == sf::Event::Closed)
        app.Close();

      //Escape key pressed
      if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))	
        app.Close();
    }

    if (credit.showCredits())
    {
      app.Clear();
      credit.update();
      app.Display();
      continue;
    }
    else
    {
      break;
    }
  }
}
Exemplo n.º 2
0
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{

  //Load menu image from file
  sf::Image image;
  image.LoadFromFile("images/mainmenu.png");
  sf::Sprite sprite(image);

  //Setup clickable regions

  //Play menu item coordinates
  MenuItem playButton;
  playButton.rect.Top= 145;
  playButton.rect.Bottom = 380;
  playButton.rect.Left = 0;
  playButton.rect.Right = 1023;
  playButton.action = Play;

  //Exit menu item coordinates
  MenuItem exitButton;
  exitButton.rect.Left = 0;
  exitButton.rect.Right = 1023;
  exitButton.rect.Top = 383;
  exitButton.rect.Bottom = 560;
  exitButton.action = Exit;
 
  _menuItems.push_back(playButton);
  _menuItems.push_back(exitButton);
 
  window.Draw(sprite);
  window.Display();

  return GetMenuResponse(window);
}
Exemplo n.º 3
0
void SplashScreen::Show(sf::RenderWindow & renderWindow)
{
	sf::Image image;
	if(image.LoadFromFile("images/SplashScreen.png") != true)
	{
		return;
	}

	sf::Sprite sprite(image);

	renderWindow.Draw(sprite);
	renderWindow.Display();

	sf::Event event;
	while(true)
	{
		while(renderWindow.GetEvent(event))
		{
			if (event.Type == sf::Event::KeyPressed ||
				event.Type == sf::Event::MouseButtonPressed ||
				event.Type == sf::Event::Closed)
			{
				return;
			}
		}
	}
} // End Show
Exemplo n.º 4
0
void draw(){
  _window.Clear();
  
  {
    sf::Rect<float> frect = sf::Rect<float>(0,0,window_width,window_height);
    _camera.SetFromRect(frect);
  }
  
  _window.Draw(_backgroundSprite);
  
  
  // draw the range shade
  _rangeSprite.SetPosition(current_pose.x + window_width/2, window_height/2 - current_pose.y);
  _window.Draw(_rangeSprite);
  
  // draw the landmarks
  for(unsigned int i=0; i<landmarks.size(); i++){
    _landmarkSprite.SetPosition(landmarks[i].x + window_width/2, window_height/2 - landmarks[i].y);
    _window.Draw(_landmarkSprite);
  }

  // draw the robot
  _robotSprite.SetPosition(current_pose.x + window_width/2, window_height/2 - current_pose.y);
  _robotSprite.SetRotation(current_pose.theta * 180 / M_PI);
  _window.Draw(_robotSprite);
  
  // draw the "other" robot
  _fakeRobotSprite.SetPosition(fake_current_pose.x + window_width/2, window_height/2 - fake_current_pose.y);
  _fakeRobotSprite.SetRotation(fake_current_pose.theta * 180 / M_PI);
  _window.Draw(_fakeRobotSprite);
  
  // display everything
  _window.Display();
}
Exemplo n.º 5
0
void drawSplashScreen(sf::RenderWindow & renderWindow)
{	
  //renderWindow.Draw(sprite::splash);


    sf::String welcome;
    toSFString("You are a chicken. \n The french are advancing and \nwant to fry you with lasers.\n\n Space to shoot, Z to fire shotgun",
	       sf::Vector2f(200, 500),
	       &welcome,
	       sf::Color(255, 0, 0));

    renderWindow.Draw(welcome);
    renderWindow.Display();


    sf::Event event;
    bool running = true;
    while (running)
    {
	while(renderWindow.GetEvent(event))
	{
	    if(event.Type == sf::Event::KeyPressed 
	       || event.Type == sf::Event::MouseButtonPressed
	       || event.Type == sf::Event::Closed )
	    {
		return;
	    }
    
	}
    }
}
Exemplo n.º 6
0
void SplashScreen::Show(sf::RenderWindow& renderWindow) {
	sf::Image image;
	if(image.LoadFromFile("C:\\Users\\Alex\\Documents\\Visual Studio 2010\\Projects\\PANG\\Debug\\images\\SplashScreen.png") != true)
		return;
	sf::Sprite sprite(image);

	renderWindow.Draw(sprite);
	renderWindow.Display();

	sf::Event event;
	sf::Clock clock;
	clock.Reset();
	/*while(true) 
	{
		renderWindow.GetEvent(event);
		if(event.Type == sf::Event::KeyPressed
			|| event.Type == sf::Event::MouseButtonPressed
			|| event.Type == sf::Event::Closed)			
		{
			return;
		}
	} */
	while (true) {
		if (clock.GetElapsedTime() >= 2.0f)
			return;
	}
}
Exemplo n.º 7
0
void CreditState::Draw(sf::RenderWindow &Window)
{
	Window.Clear(sf::Color(250, 50, 150));

	Window.Draw(mSprite);

	Window.Display();
}
Exemplo n.º 8
0
void ScreenMenu::Draw(sf::RenderWindow &App)
{
	App.Clear();
	App.Draw(backgroundSprite);
	App.Draw(menuPlay);
	App.Draw(menuCommandes);
	App.Draw(menuQuit);
	App.Display();
}
Exemplo n.º 9
0
void Visual::drawGraphics(sf::RenderWindow& mainWindow, World& world)
{
	//mainWindow.Clear(sf::Color(50, 50, 50, 255)); //clear screen
	mainWindow.Clear(sf::Color::Black);

	drawWorld(mainWindow, world);
	textDisplay(mainWindow);

    mainWindow.Display(); //draw screen
}
Exemplo n.º 10
0
Arquivo: Main.cpp Projeto: mly/BMW
int main(int argc, char** argv) {

    initOpenGL();
    loadAssets();
	handleInput();
	renderFrame();
    while (window.IsOpened()) {       
		window.Display();
    }
		
    return 0;
}
Exemplo n.º 11
0
void IntroState::Draw(sf::RenderWindow &Window)
{
	Window.Clear();

	Window.Draw(mBgSprite);
	if( i < 20 )
		i = 0;
	else
		i -= 10;

	Window.Draw(sf::Shape::Rectangle(0, 0, WINWIDTH, WINHEIGHT, sf::Color(0,0,0,i)));

	Window.Display();
}
Exemplo n.º 12
0
int Splash::Run(sf::RenderWindow &win, sf::VideoMode &vMode)
{
	Event events;
	while(win.IsOpened())
	{
		while(win.GetEvent(events))
		{
			if(events.Type == Event::Closed)
				win.Close();
			if(win.GetInput().IsKeyDown(Key::Space)) return 2;
		}
		if(m_scripter.RunScript(&m_splashBgImg, &m_splashBgSp) == 2) return 2;
		win.Clear();
		win.Draw(m_splashBgSp);
		win.Display();
	}
	return -1;
}
Exemplo n.º 13
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();
		}
	}
}
Exemplo n.º 14
0
void MenuState::Draw(sf::RenderWindow &Window)
{
	Window.Clear(sf::Color(50, 50, 150));

	Window.Draw(mBgSprite);

	// now, we draw our menu.
	for( int i = 0 ; i < mMenu.getMenuSize(); i++ )
	{
		if( i == mMenu.getSelectedItem() )
			mMenu.isSelected(i);
		else
			mMenu.isNotSelected(i);

		Window.Draw( mMenu.draw(i) );
	}

	Window.Display();
}
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{

	//Load menu image from file
	sf::Image image;
	image.LoadFromFile("images/MainScreen.png");
	sf::Sprite sprite(image);

	//Setup clickable regions

	//Play menu item coordinates
	MenuItem playButton1;
	playButton1.rect.Top= 35;
	playButton1.rect.Bottom =103;
	playButton1.rect.Left = 35;
	playButton1.rect.Right = 367;
	playButton1.action = Play1;

	MenuItem playButton2;
	playButton2.rect.Top= 130;
	playButton2.rect.Bottom = 198;
	playButton2.rect.Left = 35;
	playButton2.rect.Right = 367;
	playButton2.action = Play2;

	//Exit menu item coordinates
	MenuItem helpButton;
	helpButton.rect.Top = 213;
	helpButton.rect.Bottom = 282;
	helpButton.rect.Left = 35;
	helpButton.rect.Right = 367;
	helpButton.action = Help;

	_menuItems.push_back(playButton1);
	_menuItems.push_back(playButton2);
	_menuItems.push_back(helpButton);

	window.Draw(sprite);
	window.Display();

	return GetMenuResponse(window);
}
Exemplo n.º 16
0
void SplashScreen::Show(sf::RenderWindow & renderWindow)
{
    renderWindow.Clear();
	renderWindow.Draw(mySprBack);
	renderWindow.Display();
    
	sf::Event event;
	//on sort pour faire plus vite
	while(false)
	{
		while(renderWindow.PollEvent(event))
		{
			if(event.Type == sf::Event::KeyPressed 
               || event.Type == sf::Event::MouseButtonPressed
               || event.Type == sf::Event::Closed 
			   || event.Type == sf::Event::JoystickButtonPressed)
			{
				return;
			}
		}
	}
}
Exemplo n.º 17
0
void SplashScreen::Show(sf::RenderWindow& renderWindow)
{
	sf::Image image;
	sf::Color bgColor = sf::Color(40,40,40);
	
	//Replace this?
	if (image.LoadFromFile("test.png") != true)
		return;
	
	sf::Sprite sprite(image);
	cerr<<renderWindow.GetWidth()/2<<" "<< renderWindow.GetHeight()/2<<endl;
	sprite.SetCenter(184/2,184/2);
	sprite.SetPosition(renderWindow.GetWidth()/2 , renderWindow.GetHeight()/2);
	
	renderWindow.Clear(bgColor);
	renderWindow.Draw(sprite);
	renderWindow.Display();
	
	sf::Event event;
	sf::Clock clock;
	
	while(clock.GetElapsedTime()<3)
	{
		while(renderWindow.GetEvent(event))
		{
			if (   event.Type == sf::Event::KeyPressed 
				|| event.Type == sf::Event::MouseButtonPressed
				|| event.Type == sf::Event::Closed) 
			{
				renderWindow.Clear(bgColor);
				return;
			}
		}
	}
	renderWindow.Clear(bgColor);
	return;
}
Exemplo n.º 18
0
void GameScreen::draw (sf::RenderWindow &app)
{
	app.Clear();
	app.SetView(ConfigOptions::getView()); //switching to custom view for easy resizing of the screen

	app.Draw(m_background);
	m_highlighter.draw(app);
	if(m_selectedPiece != NULL_SQUARE)
		app.Draw(m_selectionSprite);
	if(m_selectedTarget != NULL_SQUARE)
		app.Draw(m_targettingSprite);
	app.Draw(m_cursor);
	for(std::map<PiecePtr, PieceSprite>::iterator it = m_pieces.begin(); it != m_pieces.end(); ++it)
		app.Draw(it->second);
	if(!isOver())
	{
		if(m_game.getActivePlayer() == GOLD)
			app.Draw(m_goldTurnIndicator);
		else //SILVER
			app.Draw(m_silverTurnIndicator);
		if(m_game.hasStarted())
		{
			app.Draw(m_movesBackgroundSprite);
			app.Draw(m_nbMovesSprite);
		}
		else //game has not started
		{
			m_placementUI.draw(app, m_game.canEndPlacement());
		}
		m_turnSign.draw(app);
	}
	else //the game is over
		app.Draw(m_victorySign);

	app.SetView(app.GetDefaultView()); //switching back to default view
	app.Display();
}
void SplashScreen::Show(sf::RenderWindow& window)
{
  window.Clear(sf::Color(0,0,0));

	sf::Image image;
	if(image.LoadFromFile("assets/paint-wars.png") !=true)
	{
		return;
	}
	sf::Sprite sprite(image);
	window.Draw(sprite);
	

	sf::String inst = sf::String("Press any key or click the mouse to continue.");
	inst.SetPosition(
    Game::SCREEN_WIDTH / 2 - 300,
    Game::SCREEN_HEIGHT / 2 
  );
  window.Draw(inst);

  window.Display();

  sf::Event event;
  while(true)
  {
    while(window.GetEvent(event))
    {
      if(event.Type == sf::Event::KeyPressed ||
         event.Type == sf::Event::MouseButtonPressed ||
         event.Type == sf::Event::Closed)
      {
        return;
      }
    }
  }
}
Exemplo n.º 20
0
/// This function handles all of the game's drawing
/// If possible, do ALL drawing code in here, not
/// outside of it.
/// ARGUMENTS:
///     *Surface => Reference of the context to draw on
void renderScene(sf::RenderWindow& surface)
{
    surface.Clear();
    surface.Display();
}
Exemplo n.º 21
0
int main()
{
    // Create the main rendering window
    App.Create(sf::VideoMode(640,480,32), "SFML Graphics");
	UIState uistate;
	uistate.renderer = &App;

	InitEntities();
	PhysicsSub physSub(&App, &entitysystem); 
	RenderingSystem renderSys(&App, &entitysystem);
	ControllerSystem controller(&App, &entitysystem);
	ProjectileSystem projSys(&App, &entitysystem);

	bool inventory = false;
	int invX; 
	int invY;

	std::vector<Entity*> players; 
	entitysystem.getEntities<CompPlayer>(players);
	Entity* player = players[0];

    // Start game loop
	while (App.IsOpen())
    {
        // Process events
        sf::Event Event;
		while (App.PollEvent(Event))
        {
			uistate.uiEvents(Event);
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
			if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Right)
			{
				inventory = !inventory;
				if(inventory)
					invX = sf::Mouse::GetPosition(App).x;
					invY = sf::Mouse::GetPosition(App).y; 
			}
			if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
				makeProjectile();
		}

		controller.Tick(Clock.GetElapsedTime().AsSeconds());
		physSub.Tick(Clock.GetElapsedTime().AsSeconds());
		projSys.Tick(Clock.GetElapsedTime().AsSeconds());

        // Clear the screen with red color
		App.Clear(sf::Color::Black);

		uistate.imgui_prepare();
		if(widget::button(uistate, GEN_ID, sf::Vector2f(100, 30), sf::Vector2f(520, 10), "button", 24))
			entitysystem.deleteEntity(player);
		if(inventory)
			if(widget::button(uistate, GEN_ID, sf::Vector2f(100, 30), sf::Vector2f(invX, invY), "inventory", 20))
				player = makePlayer();

		uistate.imgui_finish();

		renderSys.Tick(Clock.GetElapsedTime().AsSeconds());

        // Display window contents on screen
        App.Display();

		Clock.Restart();
    }

    return EXIT_SUCCESS;
}
Exemplo n.º 22
0
int MainMenu::Run(sf::RenderWindow & App)
{
	
	

	while(m_Running)
	{
		App.Clear();
		App.Draw(m_Background);

		while(App.GetEvent(m_Event))
		{
			if(m_Event.Type == sf::Event::Closed)
			{
				m_Running = false;
				return (-1);
			}
			
			if(m_Event.Type == sf::Event::MouseButtonPressed && m_SinglePlayerRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
			{
				// GO TO GAME
				return 4;
			}

			if(m_Event.Type == sf::Event::MouseButtonPressed && m_MultiPlayerRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
			{
				// GO TO JOINLOBBY
				return 3;
			}

			if(m_Event.Type == sf::Event::MouseButtonPressed && m_OptionsRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
			{
				// GO TO OPTIONS
				return 2;
			}

			if(m_Event.Type == sf::Event::MouseButtonPressed && m_ExitGameRect.Contains(m_Event.MouseButton.X, m_Event.MouseButton.Y) )
			{
				// EXIT GAME
				m_Running = false;
				return (-1);
			}
		}

		ShowMainMenuLabels(App);

std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(sf::Font::GetDefaultFont());
tdebug.SetSize(20);
tdebug.SetColor(sf::Color(255,0,0,255));
bufor << "BufforSize= " << gResMng.Get_MapSize();
tdebug.SetText(bufor.str());
App.Draw(tdebug);			
		

		
		App.Display();
		sf::Sleep(0.01f);
	} // end of while(Running)
	


	return (-1);
}
Exemplo n.º 23
0
vector<Start_Items*> Start_Items::SetHair(sf::RenderWindow& App, sf::Sprite* menu)
{
	vector<Start_Items*> parts;
	int ids=0;
	if (initalizeItems(ids,parts,menu) == 1) NULL;
	else EXIT_FAILURE;
	
	//cout << parts[0]->name << endl;
	
	sf::Image img_spr;
	img_spr.LoadFromFile("sprites/fig2t.png");
	sf::Sprite spr(img_spr);
	spr.SetPosition(200,210);
	spr.Scale(1.5,1.5);
	
	sf::Image i;
	i.LoadFromFile("items/hair/next_button.jpg");
	sf::Sprite next(i);
	next.SetPosition(691,491);
	
	vector<Start_Items*> eq2;
	vector<Start_Items*> all;
	sf::String hair_str;
	
	hair_str.SetPosition(100,500);
	
	while (App.IsOpened())
	{
		App.Clear();
		sf::Event Event;
		while (App.GetEvent(Event))
		{
			if (Event.Type == sf::Event::Closed)
				App.Close();
			if (Event.Type == sf::Event::MouseButtonPressed)
			{
				if (eq2.size() >=1 && !((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) && 
				(Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555))) eq2.clear();
				for (int x=0; x<parts.size(); x++)
				{
					if ((Event.MouseButton.X >= parts[x]->hair.GetPosition().x && Event.MouseButton.X <= parts[x]->hair.GetPosition().x+26*(parts[x]->hair.GetScale().x)) && 
					(Event.MouseButton.Y >= parts[x]->hair.GetPosition().y  && Event.MouseButton.Y <= parts[x]->hair.GetPosition().y+40*(parts[x]->hair.GetScale().y)))
					eq2.push_back(parts[x]);
				}
				if ((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) && (Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555)) 
				{
					ids+=1;
					all.push_back(eq2[0]);
					if (initalizeItems(ids,parts,menu) == 2) return all;
				}
				
				
			}
		}
		//cout << ids << endl;
		App.Draw(*(menu));
		
		spr.SetSubRect(sf::IntRect(0,0,32,48));
		App.Draw(spr);
		if (ids>0)
		{
			for (int x=0; x<all.size(); x++)
			{
				all[x]->hair.Scale(1,1);
				all[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
				all[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
				App.Draw(all[x]->hair);
			}
		}
		for (int x=0; x<eq2.size(); x++) 
		{
			eq2[x]->hair.Scale(1,1);
			eq2[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
			eq2[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
			hair_str.SetText("You have selected: "+eq2[x]->name);
			App.Draw(eq2[x]->hair);
			App.Draw(hair_str);
		}
		for (int x=0; x<parts.size(); x++)
		{
			int wid=400+(50*(x+1));
			int hei=200;
			if (wid>=601) 
			{
				hei=280;
				wid=400+(50*(x-3));
			}
			parts[x]->hair.SetSubRect(sf::IntRect(0,0,32,47));
			if (parts[x]->hair.GetScale().x != 1.5) parts[x]->hair.Scale(1.5,1.5);
			parts[x]->hair.SetPosition(wid,hei);
			App.Draw(parts[x]->hair);
		}
		App.Draw(next);
		App.Display();
	}
}
Exemplo n.º 24
0
void UserTron::ShowAskForInput(sf::RenderWindow& RW)
{
	RW.Draw( m_InsertInputText );
	RW.Display();
}
Exemplo n.º 25
0
/**
 * Méthode principale de l'écran
 *
 * @Param sf::RenderWindow &fenetre
 * @Param Personnage &perso1
 * @Param Personnage &perso2
 * @Param Affichage &affichage
 * @Param Carte &carteJeu
 * @Son &son
 *
 * @Return int
 */
int EcranMenuMulti::run(sf::RenderWindow &fenetre, Personnage &perso1, Personnage &perso2, Affichage &affichage, Carte &carteJeu, Son &son)
{
	sf::Event monEvent;
	bool running = true;
	int i = 0;
	int j = 0;
	int k = 0;
	int l = 0;

    //Chargement de l'image de fond du menu multijoueur
    if (!ImageMulti.LoadFromFile("tilesets/MenuMulti.png"))
		std::cout << "Erreur chargement image du menu multi" << std::endl;

    //Chargement du tile pour le choix des personnages
    if (!ImagePerso.LoadFromFile("tilesets/Tile_perso.jpg"))
		std::cout << "Erreur chargement image du menu multi (tile perso)" << std::endl;

    //Chargement du tile pour le choix de la map
    if (!ImageMap.LoadFromFile("tilesets/Tile_Map.png"))
		std::cout << "Erreur chargement image du menu multi (tile map)" << std::endl;

    //Chargement de l'image flèche droite
    if (!ImageFlecheDroite.LoadFromFile("tilesets/FlecheDroite.png"))
		std::cout << "Erreur chargement image du menu multi (fleche droite) '" << std::endl;

    //Chargement de l'image flèche droite
    if (!ImageFlecheGauche.LoadFromFile("tilesets/FlecheGauche.png"))
		std::cout << "Erreur chargement image du menu multi (fleche gauche)" << std::endl;

    //Chargement de l'image pour le nombre de manches gagnantes
    if (!ImageNombreManches.LoadFromFile("tilesets/Tile_NombreManches.png"))
		std::cout << "Erreur chargement image du menu multi (tile nombre de manches)" << std::endl;


    //Chargement des images dans les sprites
    SpriteMulti.SetImage(ImageMulti);
    SpriteFlecheDroite1.SetImage(ImageFlecheDroite);
    SpriteFlecheDroite2.SetImage(ImageFlecheDroite);
    SpriteFlecheDroite3.SetImage(ImageFlecheDroite);
    SpriteFlecheDroite4.SetImage(ImageFlecheDroite);

    //Position des différents sprites
    SpriteFlecheDroite1.SetPosition(230, 450);
    SpriteFlecheDroite2.SetPosition(230, 620);
    SpriteFlecheDroite3.SetPosition(630, 390);
    SpriteFlecheDroite4.SetPosition(590, 587);

    SpriteFlecheGauche1.SetImage(ImageFlecheGauche);
    SpriteFlecheGauche2.SetImage(ImageFlecheGauche);
    SpriteFlecheGauche3.SetImage(ImageFlecheGauche);
    SpriteFlecheGauche4.SetImage(ImageFlecheGauche);
    SpriteFlecheGauche5.SetImage(ImageFlecheGauche);
    SpriteFlecheGauche1.SetPosition(50, 450);
    SpriteFlecheGauche2.SetPosition(50, 620);
    SpriteFlecheGauche3.SetPosition(420, 390);
    SpriteFlecheGauche4.SetPosition(5, 695);
    SpriteFlecheGauche5.SetPosition(455, 587);

    SpritePerso1.SetImage(ImagePerso);
    SpritePerso1.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
    SpritePerso2.SetImage(ImagePerso);
    SpritePerso2.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
    SpriteMap.SetImage(ImageMap);
    SpriteMap.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEMAP, TAILLEIMAGEMAP));
    SpriteNombreManches.SetImage(ImageNombreManches);
    SpriteNombreManches.SetSubRect(sf::IntRect(0, 0, TAILLEIMAGEMANCHES, TAILLEIMAGEMANCHES));
    SpritePerso1.SetPosition(115, 425);
    SpritePerso2.SetPosition(115, 595);
    SpriteMap.SetPosition(485, 350);
    SpriteNombreManches.SetPosition(520, 585);


    while(running)
	{
	    //Tant que la fenêtre contient des évènements
        while(fenetre.GetEvent(monEvent))
		{
			if (monEvent.Type == sf::Event::Closed)
				return (ECRAN_QUITTER); // On quitte le jeu

            if((monEvent.Type == sf::Event::MouseButtonPressed) && (monEvent.MouseButton.Button == sf::Mouse::Left))
            {
                //Cas ou on clique sur la fleche précédant
                if(monEvent.MouseButton.X > SpriteFlecheGauche4.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheGauche4.GetPosition().x + TAILLEFLECHE)
                {
                    if(monEvent.MouseButton.Y > SpriteFlecheGauche4.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheGauche4.GetPosition().y + TAILLEFLECHE)
                    {
                        //On affiche le Menu Principal
                        return (ECRAN_MENU_PRINCIPAL);
                    }
                }
                if(monEvent.MouseButton.X > SpriteFlecheGauche1.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheGauche1.GetPosition().x + TAILLEFLECHE)
                {
                    //Cas ou on clique sur la fleche précédant pour le choix du Perso 1
                    if(monEvent.MouseButton.Y > SpriteFlecheGauche1.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheGauche1.GetPosition().y + TAILLEFLECHE)
                    {
                        i = i - TAILLEIMAGEPERSO;
                        if(i < 0)
                        {
                            i = TAILLETILEPERSO - TAILLEIMAGEPERSO;
                        }

                        SpritePerso1.SetSubRect(sf::IntRect(i, 0, i + TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
                    }
                    //Cas ou on clique sur la fleche précédant pour le choix du Perso 2
                    if(monEvent.MouseButton.Y > SpriteFlecheGauche2.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheGauche2.GetPosition().y + TAILLEFLECHE)
                    {
                        j = j - TAILLEIMAGEPERSO;
                        if(j < 0)
                        {
                            j = TAILLETILEPERSO - TAILLEIMAGEPERSO;
                        }
                        SpritePerso2.SetSubRect(sf::IntRect(j, 0, j + TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
                    }
                }

                if(monEvent.MouseButton.X > SpriteFlecheDroite1.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheDroite1.GetPosition().x + TAILLEFLECHE)
                {
                    //Cas ou on clique sur la fleche suivant pour le choix du Perso 1
                    if(monEvent.MouseButton.Y > SpriteFlecheDroite1.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheDroite1.GetPosition().y + TAILLEFLECHE)
                    {
                        i = i + TAILLEIMAGEPERSO;
                        if(i >= TAILLETILEPERSO)
                        {
                            i = 0;
                        }
                        SpritePerso1.SetSubRect(sf::IntRect(i, 0, i + TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
                    }
                    //Cas ou on clique sur la fleche suivant pour le choix du Perso 2
                    if(monEvent.MouseButton.Y > SpriteFlecheDroite2.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheDroite2.GetPosition().y + TAILLEFLECHE)
                    {
                        j = j + TAILLEIMAGEPERSO;
                        if(j >= TAILLETILEPERSO)
                        {
                            j = 0;
                        }
                        SpritePerso2.SetSubRect(sf::IntRect(j, 0, j + TAILLEIMAGEPERSO, TAILLEIMAGEPERSO));
                    }
                }

                if(monEvent.MouseButton.Y > SpriteFlecheDroite3.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheDroite3.GetPosition().y + TAILLEFLECHE)
                {
                    //Cas ou on clique sur la fleche précédant pour le choix de la map
                    if(monEvent.MouseButton.X > SpriteFlecheGauche3.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheGauche3.GetPosition().x + TAILLEFLECHE)
                    {
                        k = k - TAILLEIMAGEMAP;
                        if(k < 0)
                        {
                            k = TAILLETILEMAP - TAILLEIMAGEMAP;
                        }
                        SpriteMap.SetSubRect(sf::IntRect(k, 0, k + TAILLEIMAGEMAP, TAILLEIMAGEMAP));
                    }
                    //Cas ou on clique sur la fleche suivant pour le choix de la map
                    if(monEvent.MouseButton.X > SpriteFlecheDroite3.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheDroite3.GetPosition().x + TAILLEFLECHE)
                    {
                        k = k + TAILLEIMAGEMAP;
                        if(k >= TAILLETILEMAP)
                        {
                            k = 0;
                        }
                        SpriteMap.SetSubRect(sf::IntRect(k, 0, k + TAILLEIMAGEMAP, TAILLEIMAGEMAP));
                    }
                }


                if(monEvent.MouseButton.Y > SpriteFlecheDroite4.GetPosition().y && monEvent.MouseButton.Y < SpriteFlecheDroite4.GetPosition().y + TAILLEFLECHE)
                {
                    //Cas ou on clique sur la fleche précédant pour le choix du nombre de manches gagnantes
                    if(monEvent.MouseButton.X > SpriteFlecheGauche5.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheGauche5.GetPosition().x + TAILLEFLECHE)
                    {
                        l = l - TAILLEIMAGEMANCHES;
                        if(l < 0)
                        {
                            l = TAILLETILEMANCHES - TAILLEIMAGEMANCHES;
                        }
                        SpriteNombreManches.SetSubRect(sf::IntRect(l, 0, l + TAILLEIMAGEMANCHES, TAILLEIMAGEMANCHES));
                    }

                    //Cas ou on clique sur la fleche suivant pour le choix du nombre de manches gagnantes
                    if(monEvent.MouseButton.X > SpriteFlecheDroite4.GetPosition().x && monEvent.MouseButton.X < SpriteFlecheDroite4.GetPosition().x + TAILLEFLECHE)
                    {
                        l = l + TAILLEIMAGEMANCHES;
                        if(l >= TAILLETILEMANCHES)
                        {
                            l = 0;
                        }
                        SpriteNombreManches.SetSubRect(sf::IntRect(l, 0, l + TAILLEIMAGEMANCHES, TAILLEIMAGEMANCHES));
                    }
                }

                //Cas ou on clique sur Commencer
                if(monEvent.MouseButton.X > 530 && monEvent.MouseButton.X < 710)
                {
                    if(monEvent.MouseButton.Y > 660 && monEvent.MouseButton.Y < 710)
                        {
                            //Switch sur i pour savoir quel perso a choisi le joueur 1
                            switch(i)
                            {
                                case 0*TAILLEIMAGEPERSO:
                                joueur1 = "zelda";
                                break;

                                case 1*TAILLEIMAGEPERSO:
                                joueur1 = "mario";
                                break;

                            }

                            //Switch sur j pour savoir quel perso a choisi le joueur 2
                            switch(j)
                            {
                                case 0*TAILLEIMAGEPERSO:
                                joueur2 = "zelda";
                                break;

                                case 1*TAILLEIMAGEPERSO:
                                joueur2 = "mario";
                                break;

                            }

                            //Switch sur k pour savoir quel map ont choisi les joueurs
                            switch(k)
                            {
                                case 0*TAILLEIMAGEMAP:
                                map = "zelda";
                                break;

                                case 1*TAILLEIMAGEMAP:
                                map = "mario";
                                break;

                            }

                            //On initialise le nombre de parties gagnantes
							perso1.setNombreDeManchesGagnantes((int)(l / TAILLEIMAGEMANCHES) + 1);
							perso2.setNombreDeManchesGagnantes((int)(l / TAILLEIMAGEMANCHES) + 1);

							perso1.setThemePersonnage(joueur1);
                            perso2.setThemePersonnage(joueur2);
                            affichage.setThemeCarte(map);
                            return (ECRAN_JEU); // On rentre dans l'écran du jeu
                        }
                }
            }
		}

		fenetre.Clear();
		fenetre.Draw(SpriteMulti);

		fenetre.Draw(SpriteFlecheDroite1);
		fenetre.Draw(SpriteFlecheDroite2);
		fenetre.Draw(SpriteFlecheDroite3);
		fenetre.Draw(SpriteFlecheDroite4);
		fenetre.Draw(SpriteFlecheGauche1);
		fenetre.Draw(SpriteFlecheGauche2);
		fenetre.Draw(SpriteFlecheGauche3);
		fenetre.Draw(SpriteFlecheGauche4);
		fenetre.Draw(SpriteFlecheGauche5);

		fenetre.Draw(SpritePerso1);
		fenetre.Draw(SpritePerso2);
		fenetre.Draw(SpriteMap);
		fenetre.Draw(SpriteNombreManches);
		fenetre.Display();
	}
	return (ECRAN_QUITTER);
}
Exemplo n.º 26
0
int Screen_Select::Run (sf::RenderWindow &App, Model* _model, Controleur* _controleur)
{
    sf::Event Event;
    bool Running = true;
    sf::Image Image;
    sf::Sprite Sprite;
    int alpha = 0;
    sf::Font Font;
	sf::String Menu0;
    sf::String Menu1;
    sf::String Menu2;
    sf::String Menu3;
    sf::String Menu4;
    int menu = 2;
	std::string ip = "";
	
	sf::SoundBuffer Buffer;
	if (!Buffer.LoadFromFile("../../Images/theme.wav"))
	{
		std::cout << "Musique pas trouvée" << std::endl;
	}
	
	sf::Sound Sound;
	Sound.SetBuffer(Buffer); // Buffer est un sfSoundBuffer
	
    if (!Image.LoadFromFile("../../Images/bf2.jpg"))
    {
        std::cerr << "Error loading bf2.jpg" << std::endl;
        return (-1);
    }
	
	Sprite.SetScale((App.GetView().GetRect().GetWidth() / 500), (App.GetView().GetRect().GetHeight() / 375));
    Sprite.SetImage(Image);
	Sprite.SetPosition(-1,-1);
	
	if (!Font.LoadFromFile("../../Images/GUNPLA3D.ttf"))
    {
        std::cerr << "Error loading font" << std::endl;
    }
	
    Menu0.SetFont(Font);
    Menu0.SetSize(25);
    Menu0.SetText("Pour jouer en Client, tapez l'ip en remplacant les . de l'adresse par des ;");
    Menu0.SetX(30);
    Menu0.SetY(App.GetView().GetRect().GetHeight() / 2 - 120);
    Menu1.SetFont(Font);
    Menu1.SetSize(25);
    Menu1.SetText("Client");
    Menu1.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu1.SetY(App.GetView().GetRect().GetHeight() / 2 - 42);
    Menu2.SetFont(Font);
    Menu2.SetSize(25);
    Menu2.SetText("Serveur");
    Menu2.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu2.SetY(App.GetView().GetRect().GetHeight() / 2);
    Menu3.SetFont(Font);
    Menu3.SetSize(25);
    Menu3.SetText("Retour");
    Menu3.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu3.SetY(App.GetView().GetRect().GetHeight() / 2 + 100);
	Menu4.SetFont(Font);
    Menu4.SetSize(25);
    Menu4.SetText(ip);
    Menu4.SetX(App.GetView().GetRect().GetWidth() / 2 - 30);
    Menu4.SetY(App.GetView().GetRect().GetHeight() / 2 + 50);
	
	App.Clear();
	
    if (playing)
    {
        alpha = alpha_max;
    }
	
	Sound.Play();
	Sound.SetLoop(true);
	
    while (Running)
    {
		
        //Verifying events
        while (App.GetEvent(Event))
        {
            // Window closed
            if (Event.Type == sf::Event::Closed)
            {
                return (-1);
            }
            //Key pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Up:
						if(menu == 1)
							menu++;
						if(menu == 0)
							menu++;
                        break;
                    case sf::Key::Down:
						if(menu == 1)
							menu--;
						if(menu == 2)
							menu--;
                        break;
					case sf::Key::Num0 :
						ip = ip + "O";
						break;
					case sf::Key::Num1 :
						ip = ip + "1";
						break;
					case sf::Key::Num2 :
						ip = ip + "2";
						break;
					case sf::Key::Num3 :
						ip = ip + "3";
						break;
					case sf::Key::Num4 :
						ip = ip + "4";
						break;
					case sf::Key::Num5 :
						ip = ip + "5";
						break;
					case sf::Key::Num6 :
						ip = ip + "6";
						break;
					case sf::Key::Num7 :
						ip = ip + "7";
						break;
					case sf::Key::Num8 :
						ip = ip + "8";
						break;
					case sf::Key::Num9 :
						ip = ip + "9";
						break;
					case sf::Key::SemiColon :
						ip = ip + ".";
						break;
					case sf::Key::Back :
						if(ip.size() > 0)
							ip.erase(ip.end()-1);
						break;
                    case sf::Key::Return:
						Sound.Stop();
                        if (menu == 2)
                        {
							Screen_Multi2* s4 = new Screen_Multi2(ip);
							return (s4->Run(App,_model,_controleur));
                        }
						if (menu == 1)
						{
							//Serveur
							return 3;
						}
                        else
                        {
                            return 0;
                        }
                        break;
                    default :
                        break;
                }
            }
        }
        //When getting at alpha_max, we stop modifying the sprite
        if (alpha<alpha_max)
        {
            alpha++;
        }
        Sprite.SetColor(sf::Color(255, 255, 255, alpha/alpha_div));
        if (menu == 2)
        {
            Menu1.SetColor(sf::Color(255, 0, 0, 255));
            Menu2.SetColor(sf::Color(0, 0, 0, 255));
            Menu3.SetColor(sf::Color(0, 0, 0, 255));
        }
		else if (menu == 1)
        {
            Menu1.SetColor(sf::Color(0, 0, 0, 255));
            Menu2.SetColor(sf::Color(255, 0, 0, 255));
            Menu3.SetColor(sf::Color(0, 0, 0, 255));
        }
        else
        {
            Menu1.SetColor(sf::Color(0, 0, 0, 255));
            Menu2.SetColor(sf::Color(0, 0, 0, 255));
            Menu3.SetColor(sf::Color(255, 0, 0, 255));
        }
		
        //Drawing
        App.Draw(Sprite);
		Menu4.SetText(ip);
		App.Draw(Menu0);
		App.Draw(Menu3);
		App.Draw(Menu4); 
		App.Draw(Menu1);
		App.Draw(Menu2);
		
        App.Display();
    }
	
    //Never reaching this point normally, but just in case, exit the application
    return (-1);
}
Exemplo n.º 27
0
int JoinGameLobby::Run(sf::RenderWindow & App)
{
	m_running = true;

	if(!m_Inited)
		Init();

	while(m_running)
	{
		App.Clear();
		App.Draw(m_Background);

		while(App.GetEvent(m_Event))
		{
			if(m_Event.Type == sf::Event::Closed)
			{
				m_running = false;
				return (-1);
			}
			// BACK TO MAIN MENU
			if(m_Event.Type == sf::Event::KeyPressed && m_Event.Key.Code == sf::Key::Escape)
			{
				m_running = false;
				return 1;
			}
			// CHECK PLAYERS ON SERVER
			if(m_Event.Type == sf::Event::KeyPressed && m_Event.Key.Code == sf::Key::F1)
			{
				SendPlayersRequest();
			}
			// JOIN TO GAME
			if(m_Event.Type == sf::Event::KeyPressed && m_Event.Key.Code == sf::Key::F5)
			{
				SendNewPlayerJoin();
			}

			m_serverIPBox->HandleEvent(m_Event);

		} // end of events while loop

#pragma region debuginfo
std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(sf::Font::GetDefaultFont());
tdebug.SetSize(20);
tdebug.SetColor(sf::Color(255,0,0,255));
bufor << "Port= " << GMGI->m_SocketUDP.GetPort() << "\nPing= " << m_ServerPing;
bufor << "\n" << "Players Count= " << m_PlayerCount;
tdebug.SetText(bufor.str());
App.Draw(tdebug);	
#pragma endregion

		// if server accept my connection. Go to OnlineGame
		if(m_StartGame)
			return 5;


		RecivePackets();

		// draw textbox for server ip
		m_serverIPBox->Show(App);

		// check ping every 5sec
		if(m_pingclock.GetElapsedTime() >= 5.f)
		{
			SendPingRequest();
			m_pingclock.Reset();
		}

		

		App.Display();
		sf::Sleep(0.01f);
	} // end of while loop

	return (-1);
}
Exemplo n.º 28
0
/**
 * Méthode principale de l'écran
 *
 * @Param sf::RenderWindow &fenetre
 * @Param Personnage &perso1
 * @Param Personnage &perso2
 * @Param Affichage &affichage
 * @Param Carte &carteJeu
 * @Son &son
 *
 * @Return int
 */
int EcranMancheFinie::run(sf::RenderWindow &fenetre, Personnage &perso1, Personnage &perso2, Affichage &affichage, Carte &carteJeu, Son &son)
{
	sf::Event monEvent;
	bool running = true;

	// On joue le son de victoire
	son.playWin();

	// Boucle du menu principal
	while(running)
	{
		while(fenetre.GetEvent(monEvent))
		{
		    if (monEvent.Type == sf::Event::Closed)
		    {
		        //On stoppe la musique
                son.stopMusic();
				return (ECRAN_MENU_PRINCIPAL); // On quitte le jeu
		    }

			if ((monEvent.Type == sf::Event::KeyPressed) && (monEvent.Key.Code == sf::Key::Return))
            {
				// On relance le jeu à nouveau
				return (ECRAN_JEU);
			}
			if ((monEvent.Type == sf::Event::KeyPressed) && (monEvent.Key.Code == sf::Key::Escape))
            {
                son.stopMusic();
				// On relance le jeu à nouveau
				return (ECRAN_MENU_PRINCIPAL);
			}

		}
		// On affiche le contenu de l'écran
        fenetre.Clear();
        affichage.displayFond(fenetre);
        affichage.displayMap(fenetre);

		// On affiches les sprites de fin de manche
		if(perso1.isVivant() && !perso2.isVivant())
		{
			affichage.displayFinManche(fenetre, "1", 100, 250);
		}
		else if(perso2.isVivant() && !perso1.isVivant())
		{
			affichage.displayFinManche(fenetre, "2", 100, 250);
		}
		else if(!perso1.isVivant() && !perso2.isVivant())
		{
		    affichage.displayFinMancheEgal(fenetre, 100, 250);
        }

		affichage.displayPersoFini(&perso1, fenetre);
		affichage.displayPersoFini(&perso2, fenetre);

		// On affiche les scores
		affichage.displayScore(fenetre,perso1,90);
        affichage.displayScore(fenetre,perso2,400);
        // On affiche le contenu de la fenetre
		affichage.displayAvatar(fenetre);
		fenetre.Display();
	}
	// Normalement on atteint jamais cet endroit, si jamais ça arrive on quitte le jeu.
	return (ECRAN_QUITTER);
}
Exemplo n.º 29
0
//function
bool AccessOptions::runAccess(sf::RenderWindow &Menu, World& myWorld, Player& myPlayer)
{
    //extern World myWorld;
    //creating an image and using events
    sf::Event Event;

    sf::Image image;
    if(!image.LoadFromFile("images/accessMenu2.png"))
    return false;

    //create a sprite
    sf::Sprite sprite;
    sprite.SetImage(image);

    int xoffset = 50;
    int yoffset = 25;

    sprite.SetPosition(xoffset,yoffset);

    //list of Buttons on screen
    Button newGame = Button(305,73,Position(100+xoffset,42+yoffset));
    Button saveGame = Button(193,72,Position(165+xoffset,150+yoffset));
    Button resumeGame = Button(233,74,Position(144+xoffset,269+yoffset));
    Button exitGame = Button(139,87,Position(195+xoffset,380+yoffset));

    while(Menu.IsOpened())
    {
        //loop for event handling
        if(Menu.GetEvent(Event))
        {
            if(Event.Type==sf::Event::Closed)
            Menu.Close();

            Position click = Position(Event.MouseButton.X, Event.MouseButton.Y);
            //determining what button is pressed & task to follow
            if(Event.Type==sf::Event::MouseButtonPressed && newGame.clickedOn(click))
                {
                    sf::RenderWindow App;
                    startNewGame(Menu, App);
                }
            if(Event.Type==sf::Event::MouseButtonPressed && saveGame.clickedOn(click))
                {
                    saveSector(myWorld,myPlayer);
                }
            if(Event.Type==sf::Event::MouseButtonPressed && resumeGame.clickedOn(click))
                {
                    return true;
                }
            if(Event.Type==sf::Event::MouseButtonPressed &&exitGame.clickedOn(click))
                {
                    //also closes all other windows and system
                    return false;
                }
            }
        //clear window
        //Menu.Clear();

        //draw sprite
        Menu.Draw(sprite);
        //display
        Menu.Display();
    }
    return true;
}