-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (49 loc) · 1.66 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
65
66
import sys
import pygame as game
from constants import SCREEN
from objects.player import Player
from objects.bullet import Bullet
from objects.asteroid import Asteroid
from objects.asteroidfield import AsteroidField
def main():
game.init()
screen = game.display.set_mode((SCREEN['WIDTH'], SCREEN['HEIGHT']))
clock = game.time.Clock()
survive = 0
startTime = clock.get_time()
updatable = game.sprite.Group()
drawable = game.sprite.Group()
asteroids = game.sprite.Group()
Asteroid.containers = (asteroids, updatable, drawable)
AsteroidField.containers = updatable
asteroidField = AsteroidField()
bullets = game.sprite.Group()
Bullet.containers = (bullets, updatable, drawable)
Player.containers = (updatable, drawable)
player = Player(SCREEN['WIDTH'] / 2, SCREEN['HEIGHT'] / 2)
dt = 0
while True:
for event in game.event.get():
if event.type == game.QUIT:
return
for obj in updatable:
obj.update(dt)
for asteroid in asteroids:
if asteroid.collides_with(player):
print("Game over!")
sys.exit()
for asteroid in asteroids:
for bullet in bullets:
if asteroid.collides_with(bullet):
asteroid.split()
bullet.kill()
screen.fill("black")
for obj in drawable:
obj.draw(screen)
game.display.flip()
dt = clock.tick(60) / 1000
'''if survive < clock.get_time() - startTime:
survive = clock.get_time() - startTime
print(survive)'''
if __name__ == "__main__":
main()