Apr-22-2025, 05:52 PM
why isn't it running



import pygame import random window = pygame.display.set_mode((800, 600)) keys = pygame.key.get_pressed() class Ship: def __init__(self): self.instance = pygame.Surface((50, 70)) self.rect = self.instance.get_rect(center=(400, 500)) self.instance.fill('red') def frame(self): if keys[pygame.K_a]: self.rect.x -= 3 if keys[pygame.K_d]: self.rect.x += 3 for rock in rocks: if rock.rect.colliderect(self.rect): gameover() del self window.blit(self.instance, self.rect) class Star: def __init__(self): self.instance = pygame.Surface((10, 10)) self.rect = self.instance.get_rect(center=random.randint(0, 790), 0) self.instance.fill('white') def frame(self): self.rect.y += 2 if self.rect.y > 600: del self window.blit(self.instance, self.rect) class Rock: def __init__(self): self.instance = pygame.Surface((30, 30)) self.rect = self.instance.get_rect(center=(random.randint(0, 770), 0)) self.instance.fill('gray') def frame(self): self.rect.y += 3 if self.rect.y > 600: del self window.blit(self.instance, self.rect) stars = [] rocks = [] rocket = Ship() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() window.fill('black') for rock in rocks: if rock.rect.y > 600: del rock for star in stars: if star.rect.y > 600: del star for rock in rocks: rock.frame() for star in stars: star.frame() rocket.frame() if random.randint(1, 25) == 1: stars.append(Star()) if random.randint(1, 300) == 1: rocks.append(Rock()) pygame.display.flip() pygame.time.Clock().tick(120)