-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (61 loc) · 2.02 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
67
68
69
70
71
72
73
74
75
76
77
78
import pygame
import sys
from constants import *
from player import Player
from asteroid import Asteroid
from asteroidfield import AsteroidField
from shot import Shot
'''
To-do
Add a scoring system
Implement multiple lives and respawning
Add an explosion effect for the asteroids
Add acceleration to the player movement
Make the objects wrap around the screen instead of disappearing
Add a background image
Create different weapon types
Make the asteroids lumpy instead of perfectly round
Make the ship have a triangular hit box instead of a circular one
Add a shield power-up
Add a speed power-up
Add bombs that can be dropped
'''
def main():
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
updatable = pygame.sprite.Group()
drawable = pygame.sprite.Group()
asteroids = pygame.sprite.Group()
shots = pygame.sprite.Group()
Asteroid.containers = (asteroids, updatable, drawable)
AsteroidField.containers = updatable
asteroid_field = AsteroidField()
Asteroid.containers = (asteroids, updatable, drawable)
Shot.containers = (shots, updatable, drawable)
Player.containers = (updatable, drawable)
player = Player(x=SCREEN_WIDTH/2, y=SCREEN_HEIGHT/2)
dt = 0
while True:
#Kills the process when the window is closed
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
for obj in updatable:
obj.update(dt)
for asteroid in asteroids:
if asteroid.collides_with(player):
print("Game over!")
sys.exit()
for shot in shots:
if asteroid.collides_with(shot):
shot.kill()
asteroid.split()
screen.fill("black")
for obj in drawable:
obj.draw(screen)
pygame.display.flip()
# limit fps
dt = clock.tick(60) / 1000
if __name__ == "__main__":
main()