Skip to content
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

Fixed velocity and sound for python 3.9 #3

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
22 changes: 14 additions & 8 deletions Game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import turtle as t
import os
import time
from playsound import playsound #playsound==1.2.2

# Score varibales

Expand Down Expand Up @@ -39,18 +41,18 @@
# Creating a pong ball for the game

ball = t.Turtle()
ball.speed(0)
ball.speed()
ball.shape('circle')
ball.color('yellow')
ball.penup()
ball.goto(0,0)
ball_dx = 1.5 # Setting up the pixels for the ball movement.
ball_dy = 1.5
ball_dy = -1.5

# Creating a pen for updating the Score

pen = t.Turtle()
pen.speed(0)
pen.speed()
pen.color('skyblue')
pen.penup()
pen.hideturtle()
Expand Down Expand Up @@ -99,9 +101,12 @@ def paddle_right_down():

# Main Game Loop


while True:
win.update() # This methods is mandatory to run any game

time.sleep(1 / 60)

# Moving the ball
ball.setx(ball.xcor() + ball_dx)
ball.sety(ball.ycor() + ball_dy)
Expand All @@ -124,7 +129,7 @@ def paddle_right_down():
player_a_score = player_a_score + 1
pen.clear()
pen.write("Player A: {} Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal"))
os.system("afplay wallhit.wav&")
playsound("wallhit.wav")



Expand All @@ -134,17 +139,18 @@ def paddle_right_down():
player_b_score = player_b_score + 1
pen.clear()
pen.write("Player A: {} Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal"))
os.system("afplay wallhit.wav&")
playsound("wallhit.wav")


# Handling the collisions with paddles.

if(ball.xcor() > 340) and (ball.xcor() < 350) and (ball.ycor() < paddle_right.ycor() + 40 and ball.ycor() > paddle_right.ycor() - 40):
ball.setx(340)
ball_dx = ball_dx * -1
os.system("afplay paddle.wav&")

playsound("paddle.wav")
if(ball.xcor() < -340) and (ball.xcor() > -350) and (ball.ycor() < paddle_left.ycor() + 40 and ball.ycor() > paddle_left.ycor() - 40):
ball.setx(-340)
ball_dx = ball_dx * -1
os.system("afplay paddle.wav&")
playsound("paddle.wav")