4
« on: February 18, 2011, 04:11:58 am »
the following code closes before i can even use it. i have no clue what is wrong because the debug does not report any errors when running.
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
////////////////////////////////////////////////////////////
// Control Center of Functions
////////////////////////////////////////////////////////////
int Mouse_Check(int M_Y,int M_X);
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main rendering window
sf::Window App(sf::VideoMode(600, 650), "Spanish Game");
// Load the sprite image from a file
sf::Image Main_Box;
if (!Main_Box.LoadFromFile("Main_Box.bmp"))
return EXIT_FAILURE;
// Load the sprite image from a file
sf::Image Answer_Box;
if (!Answer_Box.LoadFromFile("Answer_Box.bmp"))
return EXIT_FAILURE;
// Load the sprite image from a file
sf::Image Roll_Over;
if (!Roll_Over.LoadFromFile("Roll_Over.bmp"))
return EXIT_FAILURE;
// Create the sprite
sf::Sprite Main(Main_Box);
sf::Sprite Answer_One(Answer_Box);
sf::Sprite Answer_Two(Answer_Box);
sf::Sprite Answer_Three(Answer_Box);
sf::Sprite Answer_Four(Answer_Box);
// Change its properties
Main.SetPosition(100.f, 0.f);
Answer_One.SetPosition(100.f, 200.f);
Answer_Two.SetPosition(300.f, 200.f);
Answer_Three.SetPosition(100.f, 350.f);
Answer_Four.SetPosition(300.f, 350.f);
// 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();
}
//Mouse Locations
const sf::Input& Input = App.GetInput();
int M_Y = App.GetInput().GetMouseY();
int M_X = App.GetInput().GetMouseX();
int Change = Mouse_Check(M_Y,M_X);
if(Change == 1)
{
sf::Sprite Answer_One(Roll_Over);
}
if(Change == 2)
{
sf::Sprite Answer_Two(Roll_Over);
}
if(Change == 3)
{
sf::Sprite Answer_Three(Roll_Over);
}
if(Change == 4)
{
sf::Sprite Answer_Three(Roll_Over);
}//replaces image for the roll over effect
// Clear the window
//App.Clear();
// Display things on screen
App.Display();
}
return EXIT_SUCCESS;
}
int Mouse_Check(int M_Y,int M_X)
{
int X = 0, Y = 0;
//used to check all positions to see if your mouse is over a location
for(X++; X<150;)
{
for(Y++; Y<200;)
{
Y += 200;
X += 100;
if((X == M_X)&&(Y==M_Y))
{
return 1;
}
X += 200;
if((X==M_X)&&(Y==M_Y))
{
return 2;
}
Y += 150;
X -= 200;
if((X==M_X)&&(Y==M_Y))
{
return 3;
}
X +=200;
if((X==M_X)&&(Y==M_Y))
{
return 4;
}
X-=300;
Y-=350;
}
}//end of X and Y checks
return 0;
}
does anyone know what is wrong?