1
General discussions / Thanks
« on: November 04, 2010, 01:13:20 pm »
22222 messages on the english forum ! thanx Laurent for the SFML !
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Graphics.hpp>
#include <list>
// Set the program's constants
const float Width = 1200;
const float Height = 800;
const sf::Color BackgroundColor(120, 120, 120);
// Create our shape list
std::list<sf::Shape> myCircles;
// A function to generate a random circle
void RandomizeCircle(std::list<sf::Shape>& shapeList, float width, float height)
{
// Get some random values to our future circle
float s = sf::Randomizer::Random(10, 50); // size
float x = sf::Randomizer::Random( s, width-s); // pos x
float y = sf::Randomizer::Random( s, height-s); // pos y
float r = sf::Randomizer::Random( 0, 255); // color R
float v = sf::Randomizer::Random( 0, 255); // color V
float b = sf::Randomizer::Random( 0, 255); // color B
// Create and add the new circle to the list
shapeList.push_back(sf::Shape::Circle(x, y, s, sf::Color(r, v, b)));
}
int main()
{
// Create main window
sf::RenderWindow App(sf::VideoMode(Width, Height), "SFML Graphics");
// Save the planet, don't waste CPU resources for nothing
App.SetFramerateLimit(60);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Push up key : generate a circle
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Up)
RandomizeCircle(myCircles, Width, Height);
}
// Clear the screen
App.Clear(BackgroundColor);
// Draw the shape list
for( std::list<sf::Shape>::const_iterator it = myCircles.begin(); it != myCircles.end(); ++it )
App.Draw(*it);
// Finally, display the on screen
App.Display();
}
return EXIT_SUCCESS;
}