the game is gamin
This commit is contained in:
39
main.py
39
main.py
@@ -1,8 +1,13 @@
|
||||
# this allows us to use code from
|
||||
# the open-source pygame library
|
||||
# throughout this file
|
||||
import sys
|
||||
import pygame
|
||||
from constants import *
|
||||
from player import *
|
||||
from asteroid import *
|
||||
from asteroidfield import *
|
||||
from shot import *
|
||||
|
||||
def main():
|
||||
print("Starting Asteroids!")
|
||||
@@ -13,13 +18,47 @@ def main():
|
||||
#set screen resolution
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
dt = 0
|
||||
|
||||
#groups
|
||||
updatable = pygame.sprite.Group()
|
||||
drawable = pygame.sprite.Group()
|
||||
asteroids = pygame.sprite.Group()
|
||||
shots = pygame.sprite.Group()
|
||||
|
||||
Player.containers = (updatable, drawable)
|
||||
Asteroid.containers = (updatable, drawable, asteroids)
|
||||
AsteroidField.containers = (updatable)
|
||||
Shot.containers = (updatable, drawable, shots)
|
||||
|
||||
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
|
||||
asteroidfield = AsteroidField()
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return
|
||||
|
||||
updatable.update(dt)
|
||||
|
||||
for a in asteroids:
|
||||
if a.colission(player):
|
||||
print("Game Over!")
|
||||
sys.exit()
|
||||
for s in shots:
|
||||
if a.colission(s):
|
||||
a.split()
|
||||
s.kill()
|
||||
|
||||
screen.fill((0,0,0))
|
||||
|
||||
for d in drawable:
|
||||
d.draw(screen)
|
||||
|
||||
|
||||
pygame.display.flip()
|
||||
dt = clock.tick(60) / 1000
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user