I'm working on a project to make an animation in pygame. The assignment is this:
Add 2 other balls to the screen (3 in total) that will all be different colors, different sizes and start in different directions. They will all bounce around continuously.
Hint: you will need to create all new variables for each ball
i.e. x2,y2, dx2, dy2
and you will need to check each ball individually for hitting a wall and update the vertical and horizontal position of each ball individually.Level 4 Challenge: when the balls hit the wall and the colors change to make each color randomly change.
Here is my code so far, I am using Python 3.7 on a Mac. The code so far has the first ball bouncing and staying the same color. I can't figure out how to make two more balls and have them change color each time they hit a wall. If someone could please help I literally cannot figure this out.
import pygame
import sys
pygame.init()
screensize = (800,600)
screen = pygame.display.set_mode(screensize,0)
pygame.display.set_caption("Animation Test")
WHITE = (255,255,255)
GREEN = (0,255,0)
BLUE = (0,0,255)
RED = (255,0,0)
screen.fill(WHITE)
pygame.display.update()
x = 100
y = 200
dx = 2
dy = 2
go = True
while go:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
go = False
screen.fill(WHITE)
x = x + dx
y = y + dy
Colour = BLUE
if (x>=775):
dx = -dx
elif (x>=775):
dx = -dx
Colour = RED