2019-03-19 10:08:38 +01:00
|
|
|
from pygame import *
|
2019-03-19 11:47:23 +01:00
|
|
|
import sys, random
|
2019-03-19 10:08:38 +01:00
|
|
|
from sprites.grass import Grass
|
2019-03-19 11:47:23 +01:00
|
|
|
from sprites.house import House
|
2019-03-19 18:29:18 +01:00
|
|
|
from sprites.landfill import Landfill
|
2019-03-20 11:20:10 +01:00
|
|
|
from sprites.garbage_collector import Garbage_collector
|
2019-03-19 11:47:23 +01:00
|
|
|
from pygame.locals import *
|
2019-03-19 18:04:43 +01:00
|
|
|
import utils
|
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
|
|
|
|
all_sprites = sprite.Group()
|
2019-03-19 10:08:38 +01:00
|
|
|
cells = []
|
|
|
|
FPS = 5
|
|
|
|
cell_size = 64
|
2019-03-19 11:47:23 +01:00
|
|
|
fps_clock = time.Clock()
|
|
|
|
|
|
|
|
#Tu będzie zmienna do wybrania przez użytkownika na start/ do zmiany w trakcie "gry"
|
2019-03-19 18:04:43 +01:00
|
|
|
home_amount = utils.set_home_amount()
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-19 18:29:18 +01:00
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
#Obszar przeznaczony na płyki
|
|
|
|
PLAY_WIDTH = (home_amount+1)*64
|
|
|
|
PLAY_HEIGHT = PLAY_WIDTH
|
2019-03-19 10:08:38 +01:00
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
#Całe okno gry (z przyszłym hud'em)
|
2019-03-19 17:21:54 +01:00
|
|
|
WINDOW_WIDTH = PLAY_WIDTH #+ 100
|
|
|
|
WINDOW_HEIGHT = PLAY_HEIGHT #+ 100
|
2019-03-19 11:47:23 +01:00
|
|
|
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
|
|
|
WHITE = (255, 255, 255)
|
|
|
|
display.set_caption('Śmieciarz WMI')
|
2019-03-19 10:08:38 +01:00
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
#Dodawanie pól typu Grass
|
|
|
|
for x in range(PLAY_HEIGHT//64):
|
2019-03-19 17:21:54 +01:00
|
|
|
cells.append([])
|
|
|
|
for y in range(PLAY_HEIGHT//64):
|
|
|
|
grass = Grass(x,y)
|
|
|
|
cells[x].append(grass)
|
2019-03-19 11:47:23 +01:00
|
|
|
|
|
|
|
#Losowanie domków i dodawanie je do mapy
|
2019-03-19 17:21:54 +01:00
|
|
|
home_len = home_amount
|
2019-03-20 11:20:10 +01:00
|
|
|
trash_count = 2
|
2019-03-19 17:21:54 +01:00
|
|
|
while( home_len > 0 ):
|
|
|
|
#Sprawdzenie, czy istnieje już domek na danej pozycji, jeżeli tak to losuj ponownie
|
2019-03-20 11:20:10 +01:00
|
|
|
x, y = utils.generate_rand_coordinates(PLAY_WIDTH, PLAY_HEIGHT)
|
2019-03-19 17:21:54 +01:00
|
|
|
if( type(cells[x][y]) == Grass ):
|
2019-03-19 18:10:04 +01:00
|
|
|
cells[x][y] = House(x,y, 10, 10, 10)
|
2019-03-19 17:21:54 +01:00
|
|
|
home_len = home_len - 1
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-20 11:20:10 +01:00
|
|
|
while(trash_count >= 0):
|
|
|
|
x, y = utils.generate_rand_coordinates(PLAY_WIDTH, PLAY_HEIGHT)
|
2019-03-19 19:11:25 +01:00
|
|
|
if( type(cells[x][y]) == Grass ):
|
2019-03-20 11:20:10 +01:00
|
|
|
cells[x][y] = Landfill(x, y, trash_count)
|
|
|
|
trash_count -= 1
|
2019-03-19 19:11:25 +01:00
|
|
|
|
2019-03-20 11:20:10 +01:00
|
|
|
while(True):
|
|
|
|
x, y = utils.generate_rand_coordinates(PLAY_WIDTH, PLAY_HEIGHT)
|
|
|
|
if type(cells[x][y]) is Grass:
|
|
|
|
cells[x][y] = Garbage_collector(x,y)
|
|
|
|
break
|
2019-03-19 19:11:25 +01:00
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
#Dodawanie wszystkich spritow do grupy spritow
|
|
|
|
for x in range(len(cells)):
|
2019-03-19 17:21:54 +01:00
|
|
|
for y in range(len(cells[x])):
|
|
|
|
all_sprites.add(cells[x][y])
|
2019-03-19 11:47:23 +01:00
|
|
|
|
|
|
|
#Sama gierka
|
|
|
|
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:
|
|
|
|
print('up')
|
|
|
|
if e.key == K_DOWN:
|
|
|
|
print('down')
|
|
|
|
if e.key == K_RIGHT:
|
|
|
|
print('right')
|
|
|
|
if e.key == K_LEFT:
|
|
|
|
print('left')
|
|
|
|
|
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-19 18:10:04 +01:00
|
|
|
#generowanie smieci
|
|
|
|
for house in all_sprites:
|
2019-03-19 18:34:10 +01:00
|
|
|
if( type(house) == House ):
|
2019-03-19 18:10:04 +01:00
|
|
|
house.generate_rubbish()
|
|
|
|
#house.check_rubbish_status()
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-19 17:21:54 +01:00
|
|
|
display.flip()
|
|
|
|
fps_clock.tick(FPS)
|