-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (56 loc) · 1.97 KB
/
Copy pathmain.py
File metadata and controls
67 lines (56 loc) · 1.97 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
import sys
import pygame
from constants import SCREEN_HEIGHT, SCREEN_WIDTH, SCOREPLUS
from logger import log_state
from player import *
from asteroid import Asteroid
from asteroidfield import AsteroidField
from logger import log_event
from circleshape import *
from shot import Shot
def main():
pygame.init()
score = 0
my_clock = pygame.time.Clock()
dt = 0
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
AsteroidFields = pygame.sprite.Group()
asteroids = pygame.sprite.Group()
updatable = pygame.sprite.Group()
drawable = pygame.sprite.Group()
shots = pygame.sprite.Group()
Shot.containers = (shots, updatable, drawable)
AsteroidField.containers = (updatable)
Asteroid.containers = (asteroids, updatable, drawable)
Player.containers = (updatable, drawable)
field = AsteroidField()
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
font = pygame.font.SysFont(None, 40)
while True:
log_state()
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
screen.fill("black")
for thing in drawable:
thing.draw(screen)
updatable.update(dt)
for asteroid in asteroids:
if player.collides_with(asteroid) == True:
log_event("player_hit")
print("Game Over!")
print(f"your Score: {score}")
sys.exit()
for asteroid in asteroids:
for shot in shots:
if shot.collides_with(asteroid) == True:
log_event("asteroid_shot")
score += SCOREPLUS
shot.kill()
asteroid.split()
text = font.render(f"your score: {score}", True, (255, 255, 255))
screen.blit(text, (20, 20))
pygame.display.flip()
dt = my_clock.tick(60) / 1000
if __name__ == "__main__":
main()