SZI2019SmieciarzWmi/game.py

86 lines
2.5 KiB
Python
Raw Normal View History

2019-03-19 10:08:38 +01:00
from pygame import *
import sys
import random
2019-03-25 16:10:51 +01:00
from config import PLAY_WIDTH, PLAY_HEIGHT, HUD_HEIGHT, home_amount
2019-03-19 11:47:23 +01:00
from sprites.house import House
2019-03-25 16:10:51 +01:00
from sprites.hud import Hud
2019-03-19 11:47:23 +01:00
from pygame.locals import *
import utils
2019-03-27 08:37:51 +01:00
import csv
import datetime
##INITIALIZE STATIC VARIABLES#########
2019-03-25 16:03:25 +01:00
FPS = 20
2019-03-19 11:47:23 +01:00
all_sprites = sprite.Group()
fps_clock = time.Clock()
2019-03-25 14:11:25 +01:00
######################################
2019-03-19 11:47:23 +01:00
2019-03-25 16:00:01 +01:00
interactables = {
"homes": [],
"landfills": []
}
##GAMEWINDOW##########################
WINDOW_WIDTH = PLAY_WIDTH
2019-03-27 10:20:22 +01:00
WINDOW_HEIGHT = PLAY_HEIGHT #+ HUD_HEIGHT
2019-03-19 11:47:23 +01:00
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
2019-03-25 16:10:51 +01:00
hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW)
display.set_caption('Smieciarz WMI')
2019-03-25 14:45:47 +01:00
icon = image.load('images/icon.png')
display.set_icon(icon)
######################################
2019-03-19 10:08:38 +01:00
##
# Generate level
utils.generate_grass(all_sprites)
2019-03-25 16:00:01 +01:00
utils.generate_landfills(all_sprites, interactables)
utils.generate_houses(all_sprites, interactables)
gc = utils.generate_garbage_collector(all_sprites, interactables)
##
2019-03-19 11:47:23 +01:00
2019-03-27 08:37:51 +01:00
##COUNTER FOR HUB BRAKE IN CONSOLE#####
hud_break = 0
2019-03-27 08:37:51 +01:00
#######################################
##INIT CSV FILE########################
2019-03-27 10:20:22 +01:00
csv_name, houses_csv_name = utils.init_csv()
2019-03-27 08:37:51 +01:00
#######################################
##GAME LOOP#######################################################################
2019-03-19 11:47:23 +01:00
while(1):
for e in event.get():
if e.type == QUIT:
quit()
sys.exit()
if e.type == KEYUP:
if e.key == K_UP:
2019-03-25 16:00:01 +01:00
gc.move('up', interactables["homes"] + interactables["landfills"])
if e.key == K_DOWN:
2019-03-25 16:00:01 +01:00
gc.move('down', interactables["homes"] + interactables["landfills"])
if e.key == K_RIGHT:
2019-03-25 16:00:01 +01:00
gc.move('right', interactables["homes"] + interactables["landfills"])
if e.key == K_LEFT:
2019-03-25 16:00:01 +01:00
gc.move('left', interactables["homes"] + interactables["landfills"])
if e.key == K_SPACE:
gc.select_object(all_sprites)
all_sprites.update()
all_sprites.draw(GAMEWINDOW)
for item in all_sprites:
if(type(item) == House):
item.generate_rubbish()
2019-03-27 08:37:51 +01:00
##LIMIT LOGS TO 1 LOG EVERY 2s#####
hud_break = (hud_break + 1) % (FPS*2)
if(hud_break == 0):
2019-03-27 08:37:51 +01:00
###################################
2019-03-27 10:20:22 +01:00
hud.get_statistics(all_sprites, csv_name, houses_csv_name)
display.flip()
fps_clock.tick(FPS)
2019-03-21 01:13:36 +01:00
##################################################################################