73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
from pygame import *
|
|
import sys, random
|
|
from sprites.grass import Grass
|
|
from sprites.house import House
|
|
from sprites.landfill import Landfill
|
|
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)
|
|
|
|
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
|
|
while( home_len > 0 ):
|
|
#Sprawdzenie, czy istnieje już domek na danej pozycji, jeżeli tak to losuj ponownie
|
|
|
|
x = random.randint(0, (PLAY_WIDTH//64)-1)
|
|
y = random.randint(0, (PLAY_WIDTH//64)-1)
|
|
|
|
if( type(cells[x][y]) == Grass ):
|
|
cells[x][y] = House(x,y)
|
|
home_len = home_len - 1
|
|
|
|
#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()
|
|
|
|
all_sprites.update()
|
|
all_sprites.draw(GAMEWINDOW)
|
|
|
|
display.flip()
|
|
fps_clock.tick(FPS)
|