import pygame
from sys import exit
pygame.init()
screen = pygame.display.set_mode((1000, 600))
running = True
ball_moving = True
ball_speed = 100
ballX = 500
ballY = 300
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit
exit()
while ball_moving:
ballX += ball_speed
ballY += ball_speed
if ballX == 1000:
ballX -= ball_speed
if ballY == 600:
ballY -= ball_speed
if ballX == 0:
ballX += ball_speed
if ballY == 0:
ballY += ball_speed
ball = pygame.draw.circle(screen, "White", center = (ballX, ballY), radius = 35, width = 35)
pygame.display.update()
The
while ball_moving:
ballX += ball_speed
ballY += ball_speed
if ballX == 1000:
ballX -= ball_speed
if ballY == 600:
ballY -= ball_speed
if ballX == 0:
ballX += ball_speed
if ballY == 0:
ballY += ball_speed
part wont run when I start the program. If I remove it, it works fine. I’m trying to make the ball object bounce around the screen.
I tried to remove the while loop and use others methods but the program just crashes.
New contributor
JK Gaming is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.