SZI2019SmieciarzWmi/game.py

80 lines
1.9 KiB
Python
Raw Normal View History

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-19 11:47:23 +01:00
from pygame.locals import *
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"
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)
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):
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
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, 10, 10, 10)
home_len = home_len - 1
2019-03-19 11:47:23 +01:00
for trash_type in range(3):
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] = Landfill(x, y, trash_type)
2019-03-19 11:47:23 +01:00
#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])
2019-03-19 11:47:23 +01:00
#Sama gierka
while(1):
for e in event.get():
if e.type == QUIT:
quit()
sys.exit()
2019-03-19 11:47:23 +01:00
all_sprites.update()
all_sprites.draw(GAMEWINDOW)
2019-03-19 18:37:48 +01:00
#generowanie smieci
for house in all_sprites:
2019-03-19 18:34:10 +01:00
if( type(house) == House ):
house.generate_rubbish()
#house.check_rubbish_status()
2019-03-19 11:47:23 +01:00
display.flip()
fps_clock.tick(FPS)