-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (43 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
54 lines (43 loc) · 1.42 KB
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
import pygame
import sys
from constants import *
from player import Player
from asteroid import Asteroid
from asteroidfield import AsteroidField
from shot import Shot
def main():
pygame.init()
updatable = pygame.sprite.Group()
drawable = pygame.sprite.Group()
asteroids = pygame.sprite.Group()
shots = pygame.sprite.Group()
Player.containers = (updatable, drawable)
Asteroid.containers = (asteroids, updatable, drawable)
AsteroidField.containers = (updatable)
Shot.containers = (shots, updatable, drawable)
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
asteroid_field = AsteroidField()
clk = pygame.time.Clock()
dt = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
screen.fill("black", rect=None, special_flags=0)
updatable.update(dt)
for asteroid in asteroids:
if asteroid.collision(player):
print("Game Over!")
sys.exit()
for shot in shots:
if asteroid.collision(shot):
asteroid.split()
shot.kill()
for draw in drawable:
draw.draw(screen)
pygame.display.flip()
# Limit the framerate to 60FPS
dt = clk.tick(60) / 1000
if __name__ == "__main__":
main()