Baldassare Castiglione
Neo Member
Hey gaf, I'm looking for some help with a pong assignment I am working on for school. I'm new to programming, so this code might be a little ugly, and my problem may be a little simple.
I'm using python 3 here, but I'm having trouble with my function for tracking the score for each player. Currently, it only displays 1 point for each player after a player 'scores', but after that it stops adding new points. So it'll say 1-1, but it won't change values after that. Before I started using user defined functions for this program I didn't have this problem. But I can't quite tell why I'm having this issue now.
Hopefully this wall of text isn't too large. If it is I (or a mod) can remove my post. Thanks in advance guys.
I'm using python 3 here, but I'm having trouble with my function for tracking the score for each player. Currently, it only displays 1 point for each player after a player 'scores', but after that it stops adding new points. So it'll say 1-1, but it won't change values after that. Before I started using user defined functions for this program I didn't have this problem. But I can't quite tell why I'm having this issue now.
Code:
def main() :
# Initialize pygame
pygame.init()
mainClock = pygame.time.Clock()
gameOver = False
#Window
windowWidth = 800
windowHeight = 600
window = pygame.display.set_mode((windowWidth,windowHeight),0,32)
pygame.display.set_caption('Pong')
#Score
score1 = 0
score2 = 0
#Paddles
White = (255,255,255)
PaddleWidth = 10
PaddleLength = 50
Left1 = 50
Top1 = 275
Right1= 740
Top2 = 275
p1 = {'rect':pygame.Rect(Left1, Top1, PaddleWidth, PaddleLength), 'color': White}
p2 = {'rect':pygame.Rect(Right1, Top2, PaddleWidth, PaddleLength), 'color': White}
#Ball
Black = (0,0,0)
center = [400, 300]
radius = 8
speed = [5,5]
Ball = pygame.draw.circle(window, White, center, radius, 0)
pygame.display.update()
while True:
# Handle events
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# Handle additional events
ballMove(center,speed,radius,p1,p2,windowHeight,windowWidth,window,White,Black,Left1,Top1,Right1,Top2,PaddleWidth,PaddleLength,mainClock)
scoreFun(score1,score2,center,radius,White,Black,windowWidth,window)
pygame.display.update()
mainClock.tick(30)
def scoreFun(score1,score2,center,radius,White,Black,windowWidth,window):
fontSize = 96
font = pygame.font.SysFont('', fontSize, True)
if center[0] - radius <= 0 :
score1 = score1 + 1
strscore1 = str(score1)
textSurface = font.render(strscore1, True, White, Black)
window.blit(textSurface, (750, 0))
pygame.display.update()
if center[0] + radius >= windowWidth :
score2 = score2 + 1
strscore2 = str(score2)
textSurface = font.render(strscore2, True, White, Black)
window.blit(textSurface, (0, 0))
pygame.display.update()
pygame.display.update()
main()
Hopefully this wall of text isn't too large. If it is I (or a mod) can remove my post. Thanks in advance guys.