2019-03-19 10:08:38 +01:00
|
|
|
from pygame import *
|
2019-03-19 11:47:23 +01:00
|
|
|
import sys, random
|
2019-03-20 23:33:22 +01:00
|
|
|
from config import PLAY_WIDTH,PLAY_HEIGHT,home_amount
|
2019-03-19 11:47:23 +01:00
|
|
|
from sprites.house import House
|
|
|
|
from pygame.locals import *
|
2019-03-19 18:04:43 +01:00
|
|
|
import utils
|
|
|
|
|
2019-03-20 22:36:40 +01:00
|
|
|
##INITIALIZE STATIC VARIABLES#########
|
|
|
|
FPS = 5
|
2019-03-19 11:47:23 +01:00
|
|
|
|
|
|
|
all_sprites = sprite.Group()
|
|
|
|
fps_clock = time.Clock()
|
2019-03-20 22:36:40 +01:00
|
|
|
######################################
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-20 22:36:40 +01:00
|
|
|
##INITIALIZE DYNAMIC VARIABLES########
|
|
|
|
obstacles_coords = []
|
|
|
|
######################################
|
|
|
|
|
|
|
|
##GAMEWINDOW##########################
|
2019-03-20 23:33:22 +01:00
|
|
|
WINDOW_WIDTH = PLAY_WIDTH
|
|
|
|
WINDOW_HEIGHT = PLAY_HEIGHT
|
2019-03-19 11:47:23 +01:00
|
|
|
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
2019-03-20 23:33:22 +01:00
|
|
|
display.set_caption('Smieciarz WMI')
|
2019-03-20 22:36:40 +01:00
|
|
|
######################################
|
2019-03-19 10:08:38 +01:00
|
|
|
|
2019-03-20 23:33:22 +01:00
|
|
|
##
|
|
|
|
#Generate level
|
|
|
|
utils.generate_grass( all_sprites )
|
|
|
|
utils.generate_houses( all_sprites, obstacles_coords )
|
|
|
|
utils.generate_landfills( all_sprites, obstacles_coords )
|
|
|
|
gc = utils.generate_garbage_collector( all_sprites, obstacles_coords )
|
|
|
|
##
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-20 22:36:40 +01:00
|
|
|
##GAME LOOP#######################################################################
|
2019-03-19 11:47:23 +01:00
|
|
|
while(1):
|
2019-03-19 17:21:54 +01:00
|
|
|
for e in event.get():
|
|
|
|
if e.type == QUIT:
|
|
|
|
quit()
|
|
|
|
sys.exit()
|
2019-03-20 11:20:10 +01:00
|
|
|
if e.type == KEYUP:
|
|
|
|
if e.key == K_UP:
|
2019-03-20 22:36:40 +01:00
|
|
|
gc.move('up', obstacles_coords)
|
2019-03-20 11:20:10 +01:00
|
|
|
if e.key == K_DOWN:
|
2019-03-20 22:36:40 +01:00
|
|
|
gc.move('down', obstacles_coords)
|
2019-03-20 11:20:10 +01:00
|
|
|
if e.key == K_RIGHT:
|
2019-03-20 22:36:40 +01:00
|
|
|
gc.move('right', obstacles_coords)
|
2019-03-20 11:20:10 +01:00
|
|
|
if e.key == K_LEFT:
|
2019-03-20 22:36:40 +01:00
|
|
|
gc.move('left', obstacles_coords)
|
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-19 17:21:54 +01:00
|
|
|
all_sprites.update()
|
|
|
|
all_sprites.draw(GAMEWINDOW)
|
2019-03-19 18:37:48 +01:00
|
|
|
|
2019-03-20 22:36:40 +01:00
|
|
|
for item in all_sprites:
|
|
|
|
if( type(item) == House ):
|
|
|
|
item.generate_rubbish()
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-19 17:21:54 +01:00
|
|
|
display.flip()
|
|
|
|
fps_clock.tick(FPS)
|
2019-03-20 22:36:40 +01:00
|
|
|
##################################################################################
|