so i was wondering if i could quickly spawn a bunch of different shapes in pygame and have them all move randomly and spawn at different places without needing to write a bunch of if's. Here's the code: import pygame import random import time
# Initializing Pygame
pygame.init()
# Initializing surface
surface = pygame.display.set_mode((5000,5000))
x = 300
y = 100
x2 = 150
y2 = 150
# Initialing Color
color2 = (0,255,0)
color = (255,0,0)
pygame.draw.rect(surface, color, pygame.Rect(30, 30, 60, 60))
# Drawing Rectangle
pygame.display.flip()
while True:
time.sleep(0.2)
var = random.randint(1,4)
var2 = random.randint(1,4)
if (var == 1):
x += 20
if (var == 2):
x -= 20
if (var == 3):
y += 20
if (var == 4):
y -= 20
if (var2 == 1):
x2 += 20
if (var2 == 2):
x2 -= 20
if (var2 == 3):
y2 += 20
if (var2 == 4):
y2 -= 20
surface.fill((0,0,0))
pygame.draw.rect(surface, color, pygame.Rect(x, y, 60, 60))
pygame.draw.rect(surface, color2, pygame.Rect(x2, y2, 60, 60))
if (x == x2 or y == y2 and color == (255,0,0)):
color2 = color
print("oof")
pygame.display.update()