#include <SFML/Graphics.hpp>
#include <cstdlib>
int main()
{
sf::RenderWindow game(sf::VideoMode(1000, 700, 32), "Pong!");
//Images/Loading
sf::Image Ball;
sf::Image LeftPaddle;
sf::Image RightPaddle;
sf::Image Background;
sf::Image Gameover;
LeftPaddle.LoadFromFile("Leftpaddle.png");
RightPaddle.LoadFromFile("Rightpaddle.png");
Ball.LoadFromFile("PongBall.png");
Background.LoadFromFile("background.png");
Gameover.LoadFromFile("gameover.png");
//Sprites
sf::Sprite leftpaddle;
sf::Sprite rightpaddle;
sf::Sprite ball;
sf::Sprite background;
sf::Sprite gameover;
ball.SetImage(Ball);
leftpaddle.SetImage(LeftPaddle);
rightpaddle.SetImage(RightPaddle);
background.SetImage(Background);
gameover.SetImage(Gameover);
Ball.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
LeftPaddle.CreateMaskFromColor(sf::Color(255, 255, 255, 255));
RightPaddle.CreateMaskFromColor(sf::Color(255, 255, 255, 255));
ball.SetPosition(500, 350);
leftpaddle.SetPosition(0, 250);
rightpaddle.SetPosition(1000 - RightPaddle.GetWidth(), 250);
background.SetPosition(250, 200);
//Ball Movement
float move_x = -1.5;
float move_y = 0;
sf::Event close;
while (game.IsOpened())
{
game.GetEvent(close);
if (close.Type == sf::Event::Closed)
{
game.Close();
}
if (game.GetInput().IsKeyDown(sf::Key::Escape))
{
game.Close();
}
//Collision for everything
float ballX = ball.GetPosition().x;
float ballY = ball.GetPosition().y;
float leftPaddleX = leftpaddle.GetPosition().x;
float leftPaddleY = leftpaddle.GetPosition().y;
float rightPaddleX = rightpaddle.GetPosition().x;
float rightPaddleY = rightpaddle.GetPosition().y;
sf::IntRect ballcollision = ball.GetSubRect();
sf::IntRect leftPaddleCol = leftpaddle.GetSubRect();
sf::IntRect rightPaddleCol = rightpaddle.GetSubRect();
ballcollision.Offset(ballX, ballY);
leftPaddleCol.Offset(leftPaddleX, leftPaddleY);
rightPaddleCol.Offset(rightPaddleX, rightPaddleY);
//Ball Movement
ball.Move(move_x, move_y);
//Left Paddle Controls
if (game.GetInput().IsKeyDown(sf::Key::W))
{
leftpaddle.Move(0, -1);
}
if (game.GetInput().IsKeyDown(sf::Key::S))
{
leftpaddle.Move(0, 1);
}
//Right Paddle Controls
if (game.GetInput().IsKeyDown(sf::Key::Up))
{
rightpaddle.Move(0, -1);
}
if (game.GetInput().IsKeyDown(sf::Key::Down))
{
rightpaddle.Move(0, 1);
}
//Left Paddle Collision
if (leftPaddleCol.Top < 0)
{
leftpaddle.SetY(0);
}
if (leftPaddleCol.Bottom > 700)
{
leftpaddle.SetY(700 - LeftPaddle.GetHeight());
}
//Right Paddle Collision
if (rightPaddleCol.Top < 0)
{
rightpaddle.SetY(0);
}
if (rightPaddleCol.Bottom > 700)
{
rightpaddle.SetY(700 - RightPaddle.GetHeight());
}
//Ball Collision
if (ballcollision.Intersects(leftPaddleCol) && move_x < 0.0f)
{
move_x = -move_x;
move_y = move_y == 0.0f ? -1.5 : move_y;
}
if (ballcollision.Intersects(rightPaddleCol) && move_x > 0.0f)
{
move_x = -move_x;
move_y = move_y == 0.0f ? -1.5 : move_y;
}
if (ballcollision.Bottom > 700)
{
move_y = -1.5;
}
if (ballcollision.Top < 0)
{
move_y = 1.5;
}
if (ballcollision.Left < 0)
{
gameover.SetPosition(250, 200);
game.Draw(gameover);
game.Display();
sf::Sleep(3);
return EXIT_SUCCESS;
}
if (ballcollision.Right > 1000)
{
gameover.SetPosition(250, 200);
game.Draw(gameover);
game.Display();
sf::Sleep(3);
return EXIT_SUCCESS;
}
game.Clear();
game.Draw(background);
game.Draw(ball);
game.Draw(leftpaddle);
game.Draw(rightpaddle);
game.Display();
}
return EXIT_SUCCESS;
}
and here are the errors i get:
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\Release\Paki Pong.exe', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-system.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\msvcp90.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\msvcr90.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-window.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Users\Danielle\Documents\Visual Studio 2010\Projects\Paki Pong\sfml-graphics.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcp100.dll', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msvcr100.dll', Symbols loaded.
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Program Files (x86)\Common Files\Motive\McciContextHook_DSR.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\ink\tiptsf.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\atioglxx.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\atiadlxy.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\dinput.dll', Cannot find or open the PDB file
'Paki Pong.exe': Loaded 'C:\Windows\SysWOW64\hid.dll', Cannot find or open the PDB file
First-chance exception at 0x70760149 in Paki Pong.exe: 0xC0000005: Access violation reading location 0x64646170.
A buffer overrun has occurred in Paki Pong.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
For more details please see Help topic 'How to debug Buffer Overrun Issues'.
The program '[1216] Paki Pong.exe: Native' has exited with code 0 (0x0).