1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <SFML/Graphics.hpp>
int main(){
int Menu = 1;
sf::RenderWindow Window(sf::VideoMode(800,600), "Menu");
sf::RectangleShape box;
box.setFillColor(sf::Color::Transparent);
box.setOutlineColor(sf::Color::White);
box.setOutlineThickness(2);
sf::Font font;
if(!font.loadFromFile("font.ttf")){
return EXIT_FAILURE;
}
sf::Text text;
text.setFont(font);
text.setCharacterSize(80);
text.setColor(sf::Color::White);
while(Window.isOpen()){
sf::Event event;
while(Window.pollEvent(event)){
if(event.type == sf::Event::Closed){
Window.close();
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && Menu != 3){
Menu++;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && Menu != 1){
Menu--;
}
}
}
Window.clear(sf::Color(80,80,80,255));
for(int i = 0;i != 4;i++){
switch(i){
case 1:
text.setString("Play");
text.setPosition(sf::Vector2f(50, 20));
Window.draw(text);
break;
case 2:
text.setString("Options");
text.setPosition(sf::Vector2f(50, 120));
Window.draw(text);
break;
case 3:
text.setString("Quit");
text.setPosition(sf::Vector2f(50, 220));
Window.draw(text);
break;
}
}
switch(Menu){
case 1:
box.setSize(sf::Vector2f(300,100));
box.setPosition(sf::Vector2f(40, 10));
Window.draw(box);
break;
case 2:
box.setSize(sf::Vector2f(100,100));
box.setPosition(sf::Vector2f(40, 10));
Window.draw(box);
break;
case 3:
box.setSize(sf::Vector2f(100,200));
box.setPosition(sf::Vector2f(40, 10));
Window.draw(box);
break;
default:
break;
}
Window.display();
return 0;
}
|