Created
January 5, 2012 16:08
-
-
Save mantognini/1565899 to your computer and use it in GitHub Desktop.
pong.cpp épuré pour faire ressortir le bug d'affichage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //////////////////////////////////////////////////////////// | |
| // Headers | |
| //////////////////////////////////////////////////////////// | |
| #include <SFML/Graphics.hpp> | |
| //////////////////////////////////////////////////////////// | |
| /// Entry point of application | |
| /// | |
| /// \return Application exit code | |
| /// | |
| //////////////////////////////////////////////////////////// | |
| int main() | |
| { | |
| // Define some constants | |
| const int gameWidth = 800; | |
| const int gameHeight = 600; | |
| // Create the window of the application | |
| sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong"); | |
| window.EnableVerticalSync(true); | |
| // Load the text font | |
| sf::Font font; | |
| if (!font.LoadFromFile("resources/sansation.ttf")) | |
| return EXIT_FAILURE; | |
| // Initialize the pause message | |
| sf::Text pauseMessage; | |
| pauseMessage.SetFont(font); | |
| pauseMessage.SetCharacterSize(40); | |
| pauseMessage.SetPosition(170.f, 150.f); | |
| pauseMessage.SetColor(sf::Color::White); | |
| // COMMENT NEXT LINE TO REMOVE "DISPLAY-BUG" | |
| pauseMessage.SetString("Welcome to SFML pong!\nPress space to start the game"); | |
| pauseMessage.SetString("You lost !\nPress space to restart or\nescape to exit"); | |
| while (window.IsOpened()) | |
| { | |
| // Handle events | |
| sf::Event event; | |
| while (window.PollEvent(event)) | |
| { | |
| // Window closed or escape key pressed: exit | |
| if ((event.Type == sf::Event::Closed) || | |
| ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))) | |
| { | |
| window.Close(); | |
| break; | |
| } | |
| } | |
| // Clear the window | |
| window.Clear(sf::Color(50, 200, 50)); | |
| // Draw the pause message | |
| window.Draw(pauseMessage); | |
| // Display things on screen | |
| window.Display(); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment