* sample pong is compilable
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1356 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
3fa986f94e
commit
879649fa08
@ -36,10 +36,10 @@ void main()
|
||||
|
||||
|
||||
// Initialize the end text
|
||||
String End = new String(""c);
|
||||
Text End = new Text(""c);
|
||||
Font font = new Font("Data/cheeseburger.ttf");
|
||||
End.setFont(font);
|
||||
End.setSize(60.f);
|
||||
End.setCharacterSize(60);
|
||||
End.move(150.f, 200.f);
|
||||
End.setColor(Color(50, 50, 250));
|
||||
|
||||
@ -48,9 +48,9 @@ void main()
|
||||
Sprite RightPaddle = new Sprite(PaddleImage);
|
||||
Sprite Ball = new Sprite(BallImage);
|
||||
|
||||
LeftPaddle.move(10, (app.getView().getRect().getHeight() - LeftPaddle.getSize().y) / 2);
|
||||
RightPaddle.move(app.getView().getRect().getWidth() - RightPaddle.getSize().x - 10, (app.getView().getRect().getHeight() - RightPaddle.getSize().y) / 2);
|
||||
Ball.move((app.getView().getRect().getWidth() - Ball.getSize().x) / 2, (app.getView().getRect().getHeight() - Ball.getSize().y) / 2);
|
||||
LeftPaddle.move(10, (app.getView().getHeight() - LeftPaddle.getSize().y) / 2);
|
||||
RightPaddle.move(app.getView().getWidth() - RightPaddle.getSize().x - 10, (app.getView().getHeight() - RightPaddle.getSize().y) / 2);
|
||||
Ball.move((app.getView().getWidth() - Ball.getSize().x) / 2, (app.getView().getHeight() - Ball.getSize().y) / 2);
|
||||
|
||||
// Define the paddles properties
|
||||
Clock AITimer = new Clock();
|
||||
@ -78,8 +78,8 @@ void main()
|
||||
while (app.getEvent(evt))
|
||||
{
|
||||
// Window closed or escape key pressed : exit
|
||||
if ((evt.Type == Event.EventType.CLOSED) ||
|
||||
((evt.Type == Event.EventType.KEYPRESSED) && (evt.Key.Code == KeyCode.ESCAPE)))
|
||||
if ((evt.Type == EventType.Closed) ||
|
||||
((evt.Type == EventType.KeyPressed) && (evt.Key.Code == KeyCode.Escape)))
|
||||
{
|
||||
app.close();
|
||||
break;
|
||||
@ -89,14 +89,14 @@ void main()
|
||||
if (IsPlaying)
|
||||
{
|
||||
// Move the player's paddle
|
||||
if (i.isKeyDown(KeyCode.UP) && (LeftPaddle.getPosition().y > 5.f))
|
||||
if (i.isKeyDown(KeyCode.Up) && (LeftPaddle.getPosition().y > 5.f))
|
||||
LeftPaddle.move(0.f, -LeftPaddleSpeed * app.getFrameTime());
|
||||
if (i.isKeyDown(KeyCode.DOWN) && (LeftPaddle.getPosition().y < app.getView().getRect().getHeight() - LeftPaddle.getSize().y - 5.f))
|
||||
if (i.isKeyDown(KeyCode.Down) && (LeftPaddle.getPosition().y < app.getView().getHeight() - LeftPaddle.getSize().y - 5.f))
|
||||
LeftPaddle.move(0.f, LeftPaddleSpeed * app.getFrameTime());
|
||||
|
||||
// Move the computer's paddle
|
||||
if (((RightPaddleSpeed < 0.f) && (RightPaddle.getPosition().y > 5.f)) ||
|
||||
((RightPaddleSpeed > 0.f) && (RightPaddle.getPosition().y < app.getView().getRect().getHeight() - RightPaddle.getSize().y - 5.f)))
|
||||
((RightPaddleSpeed > 0.f) && (RightPaddle.getPosition().y < app.getView().getHeight() - RightPaddle.getSize().y - 5.f)))
|
||||
{
|
||||
RightPaddle.move(0.f, RightPaddleSpeed * app.getFrameTime());
|
||||
}
|
||||
@ -121,13 +121,13 @@ void main()
|
||||
if (Ball.getPosition().x < 0.f)
|
||||
{
|
||||
IsPlaying = false;
|
||||
End.setText("You lost !\n(press escape to exit)"c);
|
||||
End.setString("You lost !\n(press escape to exit)"c);
|
||||
}
|
||||
|
||||
if (Ball.getPosition().x + Ball.getSize().x > app.getView().getRect().getWidth())
|
||||
if (Ball.getPosition().x + Ball.getSize().x > app.getView().getWidth())
|
||||
{
|
||||
IsPlaying = false;
|
||||
End.setText("You won !\n(press escape to exit)"c);
|
||||
End.setString("You won !\n(press escape to exit)"c);
|
||||
}
|
||||
|
||||
if (Ball.getPosition().y < 0.f)
|
||||
@ -137,11 +137,11 @@ void main()
|
||||
Ball.setY(0.1f);
|
||||
}
|
||||
|
||||
if (Ball.getPosition().y + Ball.getSize().y > app.getView().getRect().getHeight())
|
||||
if (Ball.getPosition().y + Ball.getSize().y > app.getView().getHeight())
|
||||
{
|
||||
BallSound.play();
|
||||
BallAngle = -BallAngle;
|
||||
Ball.setY(app.getView().getRect().getHeight() - Ball.getSize().y - 0.1f);
|
||||
Ball.setY(app.getView().getHeight() - Ball.getSize().y - 0.1f);
|
||||
}
|
||||
// Check the collisions between the ball and the paddles
|
||||
// Left Paddle
|
||||
|
Loading…
Reference in New Issue
Block a user