94 lines
2.2 KiB
Python
94 lines
2.2 KiB
Python
from pygame import *
|
|
import sys, random
|
|
from sprites.grass import Grass
|
|
from sprites.house import House
|
|
from sprites.landfill import Landfill
|
|
from sprites.garbage_collector import Garbage_collector
|
|
from pygame.locals import *
|
|
import utils
|
|
|
|
|
|
all_sprites = sprite.Group()
|
|
cells = []
|
|
FPS = 5
|
|
cell_size = 64
|
|
fps_clock = time.Clock()
|
|
|
|
#Tu będzie zmienna do wybrania przez użytkownika na start/ do zmiany w trakcie "gry"
|
|
home_amount = utils.set_home_amount()
|
|
|
|
|
|
#Obszar przeznaczony na płyki
|
|
PLAY_WIDTH = (home_amount+1)*64
|
|
PLAY_HEIGHT = PLAY_WIDTH
|
|
|
|
#Całe okno gry (z przyszłym hud'em)
|
|
WINDOW_WIDTH = PLAY_WIDTH #+ 100
|
|
WINDOW_HEIGHT = PLAY_HEIGHT #+ 100
|
|
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
|
WHITE = (255, 255, 255)
|
|
display.set_caption('Śmieciarz WMI')
|
|
|
|
#Dodawanie pól typu Grass
|
|
for x in range(PLAY_HEIGHT//64):
|
|
cells.append([])
|
|
for y in range(PLAY_HEIGHT//64):
|
|
grass = Grass(x,y)
|
|
cells[x].append(grass)
|
|
|
|
#Losowanie domków i dodawanie je do mapy
|
|
home_len = home_amount
|
|
trash_count = 2
|
|
while( home_len > 0 ):
|
|
#Sprawdzenie, czy istnieje już domek na danej pozycji, jeżeli tak to losuj ponownie
|
|
x, y = utils.generate_rand_coordinates(PLAY_WIDTH, PLAY_HEIGHT)
|
|
if( type(cells[x][y]) == Grass ):
|
|
cells[x][y] = House(x,y, 10, 10, 10)
|
|
home_len = home_len - 1
|
|
|
|
while(trash_count >= 0):
|
|
x, y = utils.generate_rand_coordinates(PLAY_WIDTH, PLAY_HEIGHT)
|
|
if( type(cells[x][y]) == Grass ):
|
|
cells[x][y] = Landfill(x, y, trash_count)
|
|
trash_count -= 1
|
|
|
|
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
|
|
|
|
#Dodawanie wszystkich spritow do grupy spritow
|
|
for x in range(len(cells)):
|
|
for y in range(len(cells[x])):
|
|
all_sprites.add(cells[x][y])
|
|
|
|
#Sama gierka
|
|
while(1):
|
|
for e in event.get():
|
|
if e.type == QUIT:
|
|
quit()
|
|
sys.exit()
|
|
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')
|
|
|
|
|
|
all_sprites.update()
|
|
all_sprites.draw(GAMEWINDOW)
|
|
|
|
#generowanie smieci
|
|
for house in all_sprites:
|
|
if( type(house) == House ):
|
|
house.generate_rubbish()
|
|
#house.check_rubbish_status()
|
|
|
|
display.flip()
|
|
fps_clock.tick(FPS)
|