// Headers
#include <SFML/Graphics.hpp>
int main()
{
// Create main window
sf::RenderWindow App(sf::VideoMode(640, 480), "Pong");
bool playing;
float Width, Height;
// Load image.
sf::Image BackgroundImage, BallImage, BoundaryImage, BatImage;
if (!BackgroundImage.LoadFromFile("Background.bmp") ||
!BallImage.LoadFromFile("Ball.bmp") ||
!BoundaryImage.LoadFromFile("Boundary.bmp") ||
!BatImage.LoadFromFile("Bat.bmp"))
{
return EXIT_FAILURE;
}
// Create the sprites of the background, the paddles and the ball
sf::Sprite Background(BackgroundImage);
sf::Sprite LeftPaddle(BatImage);
sf::Sprite RightPaddle(BatImage);
sf::Sprite Ball(BallImage);
sf::Sprite BoundaryTop(BoundaryImage);
sf::Sprite BoundaryBot(BoundaryImage);
// 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();
}
if (Spawn == True)
{
// Spawn
Background.SetPosition(0.f, 0.f);
Ball.SetPosition(400.f, 300.f);
LeftPaddle.SetPosition(10.f, 300.f);
RightPaddle.SetPosition(760.f, 300.f);
BoundaryTop.SetPosition(10.f, 1.f);
BoundaryBot.SetPosition(10.f, 789.f)
}
if (playing)
{
// Draw Objects
App.Draw(Background);
App.Draw(LeftPaddle);
App.Draw(RightPaddle);
App.Draw(Ball);
App.Draw(BoundaryTop);
App.Draw(BoundaryBot);
// Display Objects on Screen
App.Display();
}
return EXIT_SUCCESS;
}
}
Please I'm so confused with what code should go where and i what loops.
I want it to go: open game, spawn objects, press spacebar, game starts, if a player scores, +1 to score, when a players score reaches 10 game ends. Once player has scored respawn again.
Simon