Skip to content

Update pong.py #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/pong/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
ball_sound_buffer = sf.SoundBuffer.from_file("data/ball.wav")
ball_sound = sf.Sound(ball_sound_buffer)

# define paddles colors
left_paddle_color = sf.Color(100, 100, 200)
right_paddle_color = sf.Color(200, 100, 100)

# create the left paddle
left_paddle = sf.RectangleShape()
left_paddle.size = paddle_size - (3, 3)
left_paddle.outline_thickness = 3
left_paddle.outline_color = sf.Color.BLACK
left_paddle.fill_color = sf.Color(100, 100, 200)
left_paddle.fill_color = left_paddle_color
left_paddle.origin = paddle_size / 2

# create the right paddle
right_paddle = sf.RectangleShape()
right_paddle.size = paddle_size - (3, 3)
right_paddle.outline_thickness = 3
right_paddle.outline_color = sf.Color.BLACK
right_paddle.fill_color = sf.Color(200, 100, 100)
right_paddle.fill_color = right_paddle_color
right_paddle.origin = paddle_size / 2

# create the ball
Expand Down Expand Up @@ -85,6 +89,7 @@
left_paddle.position = (10 + paddle_size.x / 2, game_size.y / 2)
right_paddle.position = (game_size.x - 10 - paddle_size.x / 2, game_size.y / 2)
ball.position = game_size / 2
ball.fill_color = sf.Color.WHITE

# reset the ball angle
while True:
Expand Down Expand Up @@ -148,6 +153,7 @@
else:
ball_angle = pi - ball_angle - (randint(0, 32767) % 20) * pi / 180

ball.fill_color = left_paddle_color
ball_sound.play()
ball.position = (left_paddle.position.x + ball_radius + paddle_size.x / 2 + 0.1, ball.position.y)

Expand All @@ -158,6 +164,7 @@
else:
ball_angle = pi - ball_angle - (randint(0, 32767) % 20) * pi / 180

ball.fill_color = right_paddle_color
ball_sound.play()
ball.position = (right_paddle.position.x - ball_radius - paddle_size.x / 2 - 0.1, ball.position.y)

Expand Down