Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: first project  (Read 2791 times)

0 Members and 1 Guest are viewing this topic.

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
first project
« on: June 07, 2010, 09:41:27 pm »
This code compiles and executes as is.
However I wish to allow the user to select the color in the function.
Using either cin or scanf compiles but does not execute.
Help please?
Warren


Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

void NameColor();
int rd, gr, bl;

int main()
{
int j, radius = 25;
 
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1400, 900, 32), "Warren Graphics");

// Clear screen
App.Clear(sf::Color(128, 128, 128));

for(j = 1; j < 5; j++)
{
NameColor();

// Draw circle
App.Draw(sf::Shape::Circle(250,j*100+5,radius,sf::Color(rd,gr,bl)));

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

}

    // 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();

//Escape key exit
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();

        }
    }
    return EXIT_SUCCESS;
}

void NameColor()
{
int value;

// Get color from Random
value = sf::Randomizer::Random(1,6);

// Get color from key press
// scanf("%d",&value);
// cin >> value;

// Define color
if(value == 1)
{
rd = 0;
gr = 0;
bl = 255;
}
if(value == 2)
{
rd = 255;
gr = 0;
bl = 0;
}
    if(value == 3)
{
rd = 255;
gr = 255;
bl = 255;
}
    if(value == 4)
{
rd = 0;
gr = 255;
bl = 0;
}
if(value == 5)
{
rd = 255;
gr = 255;
bl = 0;
}
if(value == 6)
{
rd = 0;
gr = 0;
bl = 0;
}
}

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
first project
« Reply #1 on: June 07, 2010, 10:14:22 pm »
That's probably because you probably need the dos window focused to have cin work.

You need to use the sf keys with events.

Look at the documentation it's very easy for something simple like this.

 

anything