示例#1
0
/*
Construit une boite de dialogue pour la sauvegarde.
*/
void MainTool::buildTheWindow(sf::RenderWindow & window)
{
	Text title;
	title.setFont(font);
	title.setString("Entre le nom de la Map que vous voulez sauvegarder :");
	title.setCharacterSize(12);
	title.setColor(sf::Color::Black);
	title.setPosition(10, 10);
	window.draw(title);

	RectangleShape inputTextZone;
	inputTextZone.setFillColor(Color::White);
	inputTextZone.setOutlineThickness(1);
	inputTextZone.setOutlineColor(Color::Black);
	inputTextZone.setSize(Vector2f(380, 22));
	inputTextZone.setPosition(10, 32);
	window.draw(inputTextZone);

	Text ok;
	ok.setFont(font);
	ok.setString("Sauver");
	ok.setCharacterSize(12);
	ok.setColor(sf::Color::Black);
	FloatRect fro = ok.getLocalBounds();

	Text cancel;
	cancel.setFont(font);
	cancel.setString("Annuler");
	cancel.setCharacterSize(12);
	cancel.setColor(sf::Color::Black);
	FloatRect frc = cancel.getLocalBounds();

	ok.setPosition((400 - 50 - fro.width - frc.width) / 2, 70);
	cancel.setPosition((400 - 40 - fro.width - frc.width) / 2 + 30 + fro.width, 70);

	RectangleShape buttonOk;
	buttonOk.setFillColor(Color(200, 200, 200, 255));
	buttonOk.setOutlineThickness(1);
	buttonOk.setOutlineColor(Color::Black);
	buttonOk.setSize(Vector2f(fro.width + 10, fro.height + 10));
	buttonOk.setPosition(ok.getPosition().x - 5, ok.getPosition().y);
	window.draw(buttonOk);

	RectangleShape buttonCancel;
	buttonCancel.setFillColor(Color(200, 200, 200, 255));
	buttonCancel.setOutlineThickness(1);
	buttonCancel.setOutlineColor(Color::Black);
	buttonCancel.setSize(Vector2f(frc.width + 10, frc.height + 10));
	buttonCancel.setPosition(cancel.getPosition().x - 5, cancel.getPosition().y);
	window.draw(buttonCancel);

	window.draw(ok);
	window.draw(cancel);
}
示例#2
0
void Renderer::drawFilledRectangle(const Rectangle& t, Color color, optional<Color> outline) {
  addRenderElem([this, t, color, outline] {
      static RectangleShape r;
      r.setSize(Vector2f(t.getW(), t.getH()));
      r.setPosition(t.getPX(), t.getPY());
      r.setFillColor(color);
      if (outline) {
        r.setOutlineThickness(-2);
        r.setOutlineColor(*outline);
      } else
        r.setOutlineThickness(0);
      display.draw(r);
  });
}
示例#3
0
void PlayState::setBackground()
{
	
	for (int j = 0; j < Game::SCRN_WIDTH / Game::APPLE_SIZE; j++)
		for (int i = 0; i < Game::SCRN_HEIGHT / Game::APPLE_SIZE; i++)
		{
			RectangleShape square;
			square.setSize(Vector2f((float)Game::APPLE_SIZE, (float)Game::APPLE_SIZE));
			square.setFillColor(Color::Black);
			square.setOutlineThickness(-1.f);
			square.setOutlineColor(Color(55, 55, 55));
			square.setPosition(Vector2f(j*(float)Game::APPLE_SIZE, i*(float)Game::APPLE_SIZE));
			mapTiles.push_back(square);	
		}
	
}
示例#4
0
void drawShipInfo(RenderWindow& window, int shipIndex, string shipInfo) {
	Text name;
	Text info;

	name.setString(SHIPS[shipIndex]);
	info.setString(shipInfo);

	name.setFont(titleFont);
	info.setFont(infoFont);
	name.setCharacterSize(25);
	info.setCharacterSize(17);
	name.setColor(Color(255, 157, 61));
	info.setColor(Color(255, 199, 125));

	RectangleShape textBG;
	textBG.setFillColor(Color(22, 24, 37, 200));
	textBG.setOutlineColor(Color(76, 87, 128, 255));
	textBG.setOutlineThickness(1);

	// set up bounds for text box
	int titleTop;
	int infoTop;
	int infoBottom;
	int left;
	int right;

	titleTop = 419 - (name.getLocalBounds().height + info.getLocalBounds().height + 15) / 2;
	left = (name.getLocalBounds().width > info.getLocalBounds().width) ?
		511 - name.getLocalBounds().width / 2 :
		511 - info.getLocalBounds().width / 2;
	infoTop = 419 + name.getLocalBounds().height + 15 - (name.getLocalBounds().height + info.getLocalBounds().height + 15) / 2;
	infoBottom = info.getLocalBounds().height + infoTop;
	right = (name.getLocalBounds().width > info.getLocalBounds().width) ?
		left + name.getLocalBounds().width :
		left + info.getLocalBounds().width;

	// position and draw text box
	name.setPosition(Vector2f(left, titleTop));
	info.setPosition(Vector2f(left, infoTop));
	textBG.setSize(Vector2f(right - left + 20, infoBottom - titleTop + 20));
	textBG.setPosition(Vector2f(left - 10, titleTop - 3));

	window.draw(textBG);
	window.draw(name);
	window.draw(info);
}
示例#5
0
void drawAbilityInfo(RenderWindow& window, Player& player, int abilityIndex, bool available) {

	// set up text boxes
	Text name;
	Text info;
	Text cooldownInfo;

	cooldownInfo.setString(
		available ?
		"Available to use!" :
		"Can't use right now!"
		);

	name.setFont(titleFont);
	info.setFont(infoFont);
	cooldownInfo.setFont(infoFont);
	name.setCharacterSize(25);
	info.setCharacterSize(17);
	cooldownInfo.setCharacterSize(17);
	name.setColor(Color(0, 255, 114));
	info.setColor(Color(147, 255, 196));
	cooldownInfo.setColor(available ? Color(0, 255, 114) : Color::Red);

	RectangleShape textBG;
	textBG.setFillColor(Color(22, 21, 40, 200));
	textBG.setOutlineColor(Color(71, 66, 128, 255));
	textBG.setOutlineThickness(1);

	RectangleShape cooldownBG;
	cooldownBG.setFillColor(Color(22, 21, 40, 200));
	cooldownBG.setOutlineColor(Color(71, 66, 128, 255));
	cooldownBG.setOutlineThickness(1);

	// set bounds for text boxes
	int titleTop;
	int infoTop;
	int infoBottom;
	int left;
	int right;
	int cooldownLeft;
	int cooldownRight;
	int cooldownTop;
	int cooldownBottom;

	name.setString(player.abilities[abilityIndex].abilityName);
	info.setString(player.abilities[abilityIndex].abilityDescription);

	titleTop = 410 - (name.getLocalBounds().height + info.getLocalBounds().height + 15) / 2;
	left = (name.getLocalBounds().width > info.getLocalBounds().width) ?
		400 - name.getLocalBounds().width / 2 :
		400 - info.getLocalBounds().width / 2;
	infoTop = 410 + name.getLocalBounds().height + 15 - (name.getLocalBounds().height + info.getLocalBounds().height + 15) / 2;
	infoBottom = info.getLocalBounds().height + infoTop;
	right = (name.getLocalBounds().width > info.getLocalBounds().width) ?
		left + name.getLocalBounds().width :
		left + info.getLocalBounds().width;
	cooldownLeft = 400 - cooldownInfo.getLocalBounds().width / 2;
	cooldownRight = cooldownLeft + cooldownInfo.getLocalBounds().width;
	cooldownTop = infoBottom + 35;
	cooldownBottom = cooldownTop + cooldownInfo.getLocalBounds().height;

	// position and draw text boxes
	name.setPosition(Vector2f(left, titleTop));
	info.setPosition(Vector2f(left, infoTop));
	cooldownInfo.setPosition(Vector2f(cooldownLeft, cooldownTop));

	textBG.setSize(Vector2f(right - left + 20, infoBottom - titleTop + 20));
	textBG.setPosition(Vector2f(left - 10, titleTop - 3));
	cooldownBG.setPosition(Vector2f(cooldownLeft - 10, cooldownTop - 4));
	cooldownBG.setSize(Vector2f(cooldownRight - cooldownLeft + 20, cooldownBottom - cooldownTop + 20));

	window.draw(cooldownBG);
	window.draw(textBG);
	window.draw(name);
	window.draw(info);
	window.draw(cooldownInfo);
}
示例#6
0
文件: main.cpp 项目: ndt93/Break-Out
	void setup() {
		top.setPosition(0, 0);
		top.setSize(Vector2f(width, borderSize));

		left.setPosition(0, borderSize);
		left.setSize(Vector2f(borderSize, height + borderSize));

		right.setPosition(width - borderSize, borderSize);
		right.setSize(Vector2f(borderSize, height + borderSize));

		bottom.setPosition(0, height + 2*borderSize);
        bottom.setSize(Vector2f(width, borderSize));

		top.setFillColor(Color(100,100,100));
        top.setOutlineColor(Color::Black);
        top.setOutlineThickness(2);
 
        left.setFillColor(Color(100,100,100));
        left.setOutlineColor(Color::Black);
        left.setOutlineThickness(2);
 
        right.setFillColor(Color(100,100,100));
        right.setOutlineColor(Color::Black);
        right.setOutlineThickness(2);
 
        bottom.setFillColor(Color(100,100,100));
        bottom.setOutlineColor(Color::Black);
        bottom.setOutlineThickness(2);

		ball.setPosition(width/2, height - margin);
		ball.setSize(Vector2f(20, 20));
		ball.setFillColor(Color::Green);
		ball.setOutlineColor(Color::Red);
		ball.setOutlineThickness(2);

		player.setSize(Vector2f(90,borderSize));
        player.setPosition(width/2-45, height-margin-borderSize);
        player.setFillColor(Color(0, 122, 245));
        player.setOutlineColor(Color::Green);
        player.setOutlineThickness(3);

		title.setString("Break Out!");
        title.setFont(font);
        title.setCharacterSize(50);
        title.setPosition(width/2-title.getGlobalBounds().width/2,100);
        title.setColor(Color::Blue); 
     
        start.setString("Press any key to start");
        start.setFont(font);
        start.setCharacterSize(30);
        start.setPosition(width/2-start.getGlobalBounds().width/2,400);
        start.setColor(Color::Red);
 
        won.setString("You have won this game.\n\n Congratulations !");
        won.setFont(font);
        won.setCharacterSize(20);
        won.setPosition(width/2-won.getGlobalBounds().width/2,height/2-won.getGlobalBounds().height/2);
        won.setColor(Color::Green);
 
        lost.setString("You have lost this game, \n better luck next time!");
        lost.setFont(font);
        lost.setCharacterSize(20);
        lost.setPosition(width/2-lost.getGlobalBounds().width/2,height/2-lost.getGlobalBounds().height/2);
        lost.setColor(Color::Red);
 
        score.setString("0");
        score.setFont(font);
        score.setCharacterSize(30);
        score.setPosition(width/2 + score.getGlobalBounds().width/2, height-60);
        score.setColor(Color(0,0,100,50));
 
        lives.setString("5");
        lives.setFont(font);
        lives.setCharacterSize(50);
        lives.setPosition(width/2 - lives.getGlobalBounds().width/2, height-60);
        lives.setColor(Color(0,0,100,50));

		fps.setString("0");
        fps.setFont(font);
        fps.setCharacterSize(30);
        fps.setPosition(fps.getGlobalBounds().width/2,height-40);
        fps.setColor(Color(52,0,100,50));
         
        blip=Sound(soundBuffer1);        
        blam=Sound(soundBuffer2);    
        blap=Sound(soundBuffer3);    
        blop=Sound(soundBuffer4);
         
        resetGame();
        gameState=INTRO;
 
        grid.setDimensions(10,6);
        grid.left = borderSize +5;
        grid.top = borderSize + 5;
        grid.width = width - 12;
        grid.height = 250;
        grid.init();
	}
示例#7
0
std::string name_enter(RenderWindow &window){

    Font font;

    std::string str;
    String text;

    font.loadFromFile("arial.ttf");

    Text name, text_ent, too_many_letters;

    bool flag = false;
    float timer = 100;
    name.setFont(font);
    name.setCharacterSize(30);
    name.setColor(Color::Black);
    name.setPosition(500, 300);

    RectangleShape rect;
    rect.setFillColor(Color::Magenta);
    rect.setOutlineThickness(5);
    rect.setOutlineColor(Color::Black);
    rect.setSize(Vector2f(120, 40));
    rect.setPosition(500, 300);

    text_ent.setFont(font);
    text_ent.setString("Enter your name. Less then 8 letters please. When you will be ready, press \"spase\"");
    text_ent.setCharacterSize(30);
    text_ent.setColor(Color::Black);
    text_ent.setPosition(50, 200);

    too_many_letters.setFont(font);
    too_many_letters.setString("To many letters");
    too_many_letters.setCharacterSize(40);
    too_many_letters.setColor(Color::Red);
    too_many_letters.setPosition(730, 300);

    std::string s = "";

    while(window.isOpen()){

        sf::Event event;
        while (window.pollEvent(event)){
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::TextEntered){
                if(Keyboard::isKeyPressed(Keyboard::BackSpace) && s.size()!=0){
                    if (!s.empty())
                        s.pop_back();
                }
                else if (s.size() >= 7) {
                    flag = true;
                    timer = 100;
                }
                else if (event.text.unicode < 128 && s.size() < 7 && !flag) {
                    s.push_back((char)event.text.unicode);
                }
                if(Keyboard::isKeyPressed(Keyboard::Space) && s.size()!=0){
                    return s;
                }
            }
        }
        if(Keyboard::isKeyPressed(Keyboard::Escape))
            return "escape_code";

        window.clear(Color::Green);
        name.setString(s);
        window.draw(rect);
        if(flag){
            window.draw(too_many_letters);
            timer = timer * 0.7;
            if(timer < 10)
                flag = false;
        }
        window.draw(name);
        window.draw(text_ent);
        window.display();
    }
}