Aug-05-2019, 01:29 AM
I have tinkered with this for too long every time I run the code it doesn't update the value of my variables that control score. any help is much appreciated.
import sys import pygame import os pygame.init() #window and scoring win_w = 600 win_h = 500 white= (255, 255, 255) bg = pygame.image.load("BG.png") win = pygame.display.set_mode((win_w,win_h)) pygame.display.set_caption("pong?") win.blit(pygame.image.load('BG.png'),(0, 0)) ##scoring font = pygame.font.SysFont("comicsansms", 30) score1 = 0 pygame.display.flip() score2 = 0 text1 = font.render(str(score1) , True, (255, 255, 255)) text2 = font.render(str(score2) , True, (255, 255, 255)) pygame.display.flip() #paddles xp1 = 575 yp1 = 200 xp2 = 10 yp2 = 200 #ball x1 = 305 y1 = 245 ball = [x1, y1] xvel = 1 yvel = 1 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() #keys and paddle movement keys = pygame.key.get_pressed() if keys[pygame.K_UP] and yp1 > 0 : yp1 -= 1.5 if keys[pygame.K_DOWN] and yp1 < 435: yp1 += 1.5 if keys[pygame.K_w] and yp2 > 0: yp2 -= 1.5 if keys[pygame.K_s] and yp2 < 435: yp2 += 1.5 #ball movement if x1 > 600: score1 += 1 x1 = 305 y1 = 245 xvel *= -1 yvel *= 1 if x1 < 0: score2 += 1 x1 = 305 y1 = 245 xvel *= -1 yvel *= 1 if y1 >= 490: yvel *= -1 if y1 <= 10: yvel *= -1 #paddle collison if x1 >= 560 and (y1 < yp1 +65 and y1 > yp1): x1 == 559 xvel *= -1 yvel *= 1 if x1 <= 25 and (y1 < yp2 +65 and y1 > yp2): x1 == 26 xvel *= -1 yvel *= 1 win.blit(pygame.image.load('BG.png'),(0, 0)) win.blit(text1, (20 - text1.get_width() // 2, 20 - text1.get_height() // 2)) win.blit(text2, (580 - text2.get_width() // 2, 20 - text2.get_height() // 2)) #score #fuck the score till later #paddles pygame.draw.rect(win, (255, 255, 255), (xp1, yp1, 15, 65)) pygame.draw.rect(win, (255, 255, 255), (xp2, yp2, 15, 65)) #ball pygame.draw.rect(win, (255, 255, 255), (x1, y1, 15, 15)) pygame.display.update() x1 += xvel y1 += yvel