2025-07-04 15:54:54 +02:00
|
|
|
import pygame
|
|
|
|
|
import sys
|
|
|
|
|
|
2025-07-12 20:04:42 +02:00
|
|
|
from asteroid import Asteroid
|
|
|
|
|
from asteroidfield import AsteroidField
|
2025-07-04 15:54:54 +02:00
|
|
|
from constants import *
|
2025-07-04 20:58:34 +02:00
|
|
|
from player import Player
|
2025-07-04 15:54:54 +02:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
print("Starting Asteroids!")
|
|
|
|
|
print(f"Screen width: {SCREEN_WIDTH}")
|
|
|
|
|
print(f"Screen height: {SCREEN_HEIGHT}")
|
|
|
|
|
|
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
|
|
if pygame.get_init() == False:
|
|
|
|
|
pygame.quit()
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
|
|
|
|
2025-07-04 16:00:36 +02:00
|
|
|
time = pygame.time.Clock()
|
|
|
|
|
dt = 0
|
2025-07-04 15:54:54 +02:00
|
|
|
|
2025-07-11 19:34:07 +02:00
|
|
|
updatable = pygame.sprite.Group()
|
|
|
|
|
drawable = pygame.sprite.Group()
|
2025-07-12 20:04:42 +02:00
|
|
|
asteroids = pygame.sprite.Group()
|
2025-07-11 19:34:07 +02:00
|
|
|
|
2025-07-12 20:04:42 +02:00
|
|
|
Asteroid.containers = (asteroids, updatable, drawable)
|
|
|
|
|
AsteroidField.containers = (updatable)
|
2025-07-11 19:34:07 +02:00
|
|
|
Player.containers = (updatable, drawable)
|
|
|
|
|
|
|
|
|
|
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
|
2025-07-12 20:04:42 +02:00
|
|
|
asteroidField = AsteroidField()
|
2025-07-04 20:58:34 +02:00
|
|
|
|
2025-07-04 15:54:54 +02:00
|
|
|
while True:
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
pygame.Surface.fill(screen, (0,0,0))
|
2025-07-04 20:58:34 +02:00
|
|
|
|
2025-07-11 19:34:07 +02:00
|
|
|
updatable.update(dt)
|
2025-07-11 19:11:17 +02:00
|
|
|
|
2025-07-11 19:34:07 +02:00
|
|
|
for drawing in drawable:
|
|
|
|
|
drawing.draw(screen)
|
2025-07-04 20:58:34 +02:00
|
|
|
|
2025-07-04 16:00:36 +02:00
|
|
|
pygame.display.flip() #refresh screen
|
2025-07-04 15:54:54 +02:00
|
|
|
|
2025-07-04 16:00:36 +02:00
|
|
|
dt = time.tick(60) / 1000 #conveted to ms
|
2025-07-04 15:54:54 +02:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|