-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (57 loc) · 1.89 KB
/
Copy pathmain.py
File metadata and controls
68 lines (57 loc) · 1.89 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# this allows us to use code from
# the open-source pygame library
# throughout this file
import pygame
import constants
from constants import *
from player import Player
from asteroidfield import AsteroidField
from asteroid import Asteroid
import sys
from shot import Shot
def main():
pygame.init()
print ("Starting Asteroids!")
print(f"Screen width: {constants.SCREEN_WIDTH}")
print(f"Screen height: {constants.SCREEN_HEIGHT}")
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
updatable = pygame.sprite.Group()
drawable = pygame.sprite.Group()
asteroids = pygame.sprite.Group()
shots = pygame.sprite.Group()
# Create a player object
# and add it to the updatable and drawable groups
# This allows us to use the player object
# in the updatable and drawable groups
# and update and draw it
# in the main loop
Player.containers = (updatable, drawable)
player_x = SCREEN_WIDTH / 2
player_y = SCREEN_HEIGHT / 2
player = Player(player_x, player_y)
AsteroidField.containers = (updatable,)
Asteroid.containers = (asteroids, updatable, drawable)
Shot.containers = (shots, updatable, drawable)
asteroid_field = AsteroidField()
pygame.time.Clock
dt = 0
while 1 == 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
screen.fill("black")
updatable.update(dt)
for each in asteroids:
if player.collide(each):
print("Game over!")
return
for shot in shots:
if each.collide(shot):
each.split()
shot.kill()## remove the shot
for each in drawable:
each.draw(screen)
pygame.display.flip()
dt = pygame.time.Clock().tick(60)/1000.0
if __name__ == "__main__":
main()