[ create a new paste ] login | about

Link: http://codepad.org/JnBsV8mQ    [ raw code | output | fork ]

C++, pasted on Mar 26:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cstdlib>


int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 800, 32), "SFML Graphics");
    
    // Music
    sf::Music *bgsound = new sf::Music();
    bgsound->OpenFromFile("track.ogg");
 
 	App.UseVerticalSync(true);
 	   
    // GameScore
    unsigned short int score = 0;
    unsigned short int life = 3;

	// Game Bar
	sf::Shape bar = sf::Shape::Rectangle(0, 0, 100, 10, sf::Color(255, 255, 255) );
	bar.Move(360, 760);
	
	// Game Ball
	sf::Shape ball = sf::Shape::Circle(0, 0, 10, sf::Color(255, 255, 255));
	ball.Move(390, 600);

	float ballOffsetX = 5, ballOffsetY = -9;
	
	// Start Sound
	bgsound->SetLoop(true);
	bgsound->Play();
	

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
           	{
            	bgsound->Stop();
            	delete bgsound;
                App.Close();
        	}
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Left) && (bar.GetPosition().x > 10))  
        {
        	bar.Move(-400 * ElapsedTime, 0);
        }
        
        if (App.GetInput().IsKeyDown(sf::Key::Right) && (bar.GetPosition().x < 690)) 
        {
        	bar.Move( 400 * ElapsedTime, 0);
		}
		
		// Collision Detection
		
		// bar Collision
		
		if ((ball.GetPosition().x >= bar.GetPosition().x) && (ball.GetPosition().x <= (bar.GetPosition().x + 100)))
		{
			if ((ball.GetPosition().y >= bar.GetPosition().y) && (ball.GetPosition().y <= (bar.GetPosition().y + 10)))
			{
				ballOffsetY = ballOffsetY * (-1.f);
				score++;
			}
		}
		
		if ((ball.GetPosition().x >= 790) || ball.GetPosition().x <= 10)
		{
			ballOffsetX = ballOffsetX * (-1.f);
		}
		
		if (ball.GetPosition().y <= 10)
		{
			ballOffsetY = ballOffsetY * (-1.f); 
		}
		
		// DEBUG ONLY
		
		if (ball.GetPosition().y > 800)
		{
			ball.Move(0,-790);
			life--;
		}
		
		if (life <= 0)
		{
			break;
		}
		
		// Ball Movement
		ball.Move(ballOffsetX, ballOffsetY);
		
        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(bar);
        App.Draw(ball);

        // Display window contents on screen
        App.Display();
    }
    bgsound->Stop();
    
    const char* x = "teststring";

    sf::String scr1("Your Score:", sf::Font::GetDefaultFont(), 50);
    sf::String scr2(x, sf::Font::GetDefaultFont(), 60);
    scr1.SetColor(sf::Color(255,255,255));
    scr2.SetColor(sf::Color(255,255,255));
    scr1.Move(300, 400);
    scr2.Move(300, 500);
    
    while (1)
    {
    	App.Draw(scr1);
    	App.Draw(scr2);
    	App.Display();
    	        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
            {
            	bgsound->SetLoop(false);
            	bgsound->Stop();
            	delete bgsound;
                App.Close();
            }
        }
	}
	bgsound->Stop();
	delete bgsound;
	
    return EXIT_SUCCESS;
}


Output:
1
2
3
4
5
Line 28: error: SFML/Graphics.hpp: No such file or directory
Line 25: error: SFML/Audio.hpp: No such file or directory
In function 'int main()':
Line 9: error: 'sf' has not been declared
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: