-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (45 loc) · 1.53 KB
/
Copy pathmain.py
File metadata and controls
47 lines (45 loc) · 1.53 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
import pygame
import sys
from constants import *
from player import *
from asteroid import *
from asteroidfield import *
from bullet import *
def main():
pygame.init()
print("Starting Asteroids!")
dt = 0
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)
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, shots)
timing = pygame.time.Clock()
asteroidfield = AsteroidField()
# print(f"Screen width: {SCREEN_WIDTH}")
# print(f"Screen height: {SCREEN_HEIGHT}")
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
updatable.update(dt)
for asteroid in asteroids:
if player.collisions(asteroid) == True:
sys.exit("Game over!")
for bullet in shots:
if bullet.collisions(asteroid) == True:
bullet.kill()
asteroid.split(asteroids)
screen.fill("black")
for i in drawable:
i.draw(screen)
ticked = timing.tick(60)
dt = ticked / 1000
pygame.display.flip() # call this last, ALWAYS
if __name__ == "__main__":
main()