SZI2019SmieciarzWmi/game.py
Magdalena Wilczyńska a55be72342 Added statistics utils
2019-03-25 16:03:25 +01:00

66 lines
1.8 KiB
Python

from pygame import *
import sys
import random
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
from sprites.house import House
from pygame.locals import *
import utils
##INITIALIZE STATIC VARIABLES#########
FPS = 20
all_sprites = sprite.Group()
fps_clock = time.Clock()
######################################
##INITIALIZE DYNAMIC VARIABLES########
obstacles_coords = []
######################################
##GAMEWINDOW##########################
WINDOW_WIDTH = PLAY_WIDTH
WINDOW_HEIGHT = PLAY_HEIGHT
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
display.set_caption('Smieciarz WMI')
icon = image.load('images/icon.png')
display.set_icon(icon)
######################################
##
# Generate level
utils.generate_grass(all_sprites)
utils.generate_landfills(all_sprites, obstacles_coords)
utils.generate_houses(all_sprites, obstacles_coords)
utils.add_frame_as_obstacles(obstacles_coords)
gc = utils.generate_garbage_collector(all_sprites, obstacles_coords)
##
##GAME LOOP#######################################################################
while(1):
for e in event.get():
if e.type == QUIT:
quit()
sys.exit()
if e.type == KEYUP:
if e.key == K_UP:
gc.move('up', obstacles_coords)
if e.key == K_DOWN:
gc.move('down', obstacles_coords)
if e.key == K_RIGHT:
gc.move('right', obstacles_coords)
if e.key == K_LEFT:
gc.move('left', obstacles_coords)
all_sprites.update()
all_sprites.draw(GAMEWINDOW)
for item in all_sprites:
if(type(item) == House):
item.generate_rubbish()
utils.get_statistics(all_sprites)
display.flip()
fps_clock.tick(FPS)
##################################################################################