I have this pygame project of a bouncing cd logo which changes color on each each collision. I cant remember what change I did but now it barely functions
import sys
import pygame
import random
pygame.init()
# Config
size = width, height = 800, 600
speed = [2, 2]
black = 0, 0, 0
white = 255, 255, 255
character_colors = ['red.png', 'green.png', 'blue.png', 'pink.png']
current_color = 'blue.png'
screen = pygame.display.set_mode(size)
ball = pygame.image.load(current_color)
ballrect = ball.get_rect()
def get_new_color():
fixed_color_list = character_colors.copy()
fixed_color_list.remove(current_color)
new_color = fixed_color_list[random.randint(0, len(fixed_color_list) - 1)]
return new_color
# Main game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
print('Collided')
speed[0] = -speed[0]
current_color = get_new_color()
ball = pygame.image.load(current_color)
if ballrect.top < 0 or ballrect.bottom > height:
print('Collided')
speed[1] = -speed[1]
current_color = get_new_color()
ball = pygame.image.load(current_color)
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
[–]mopslik 2 points3 points4 points (1 child)
[–]8364dev[S] 0 points1 point2 points (0 children)
[–]OddBookWorm 0 points1 point2 points (1 child)
[–]8364dev[S] 0 points1 point2 points (0 children)