-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (47 loc) · 1.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pygame
from constants import SCREEN_WIDTH, SCREEN_HEIGHT
from asteroid import Asteroid
from player import Player
from asteroidfield import AsteroidField
from shot import Shot
def main():
print("Starting asteroids!")
print(f"Screen width: {SCREEN_WIDTH}")
print(f"Screen height: {SCREEN_HEIGHT}")
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
dt = 0
updatable = pygame.sprite.Group()
drawable = pygame.sprite.Group()
asteroids = pygame.sprite.Group()
shots = pygame.sprite.Group()
Shot.containers = (updatable,drawable,shots)
Player.containers = (updatable,drawable) # pyright: ignore
Asteroid.containers = (asteroids,updatable,drawable) #pyright: ignore
player = Player(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
AsteroidField.containers =(updatable) #pyright: ignore
asteroidfield = AsteroidField()
updatable.add(asteroids)
while True:
screen.fill(color="black")
for item in updatable:
item.update(dt)
for ast in asteroids:
if ast.collision(player):
print("Game over!")
return
for shot in shots:
if ast.collision(shot):
shot.kill()
ast.split()
break
for item in drawable:
item.draw(screen)
pygame.display.flip()
dt = clock.tick(60) / 1000
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if __name__ == "__main__":
main()