# this allows us to use code from # the open-source pygame library # throughout this file import sys import pygame from constants import * from player import * from asteroid import * from asteroidfield import * from shot import * def main(): print("Starting Asteroids!") print(f"Screen width: {SCREEN_WIDTH}") print(f"Screen height: {SCREEN_HEIGHT}") pygame.init() #set screen resolution screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) clock = pygame.time.Clock() dt = 0 #groups updatable = pygame.sprite.Group() drawable = pygame.sprite.Group() asteroids = pygame.sprite.Group() shots = pygame.sprite.Group() Player.containers = (updatable, drawable) Asteroid.containers = (updatable, drawable, asteroids) AsteroidField.containers = (updatable) Shot.containers = (updatable, drawable, shots) player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) asteroidfield = AsteroidField() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: return updatable.update(dt) for a in asteroids: if a.colission(player): print("Game Over!") sys.exit() for s in shots: if a.colission(s): a.split() s.kill() screen.fill((0,0,0)) for d in drawable: d.draw(screen) pygame.display.flip() dt = clock.tick(60) / 1000 if __name__ == "__main__": main()