diff --git a/game.py b/game.py index 60e654f..4303fc8 100644 --- a/game.py +++ b/game.py @@ -50,7 +50,7 @@ while( home_len > 0 ): y = random.randint(0, (PLAY_WIDTH//64)-1) if( type(cells[x][y]) == Grass ): - cells[x][y] = House(x,y) + cells[x][y] = House(x,y, 10, 10, 10) home_len = home_len - 1 #Dodawanie wszystkich spritow do grupy spritow @@ -67,6 +67,12 @@ while(1): 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) diff --git a/sprites/cell.py b/sprites/cell.py index fe78381..42d72de 100644 --- a/sprites/cell.py +++ b/sprites/cell.py @@ -8,4 +8,4 @@ class Cell(pygame.sprite.Sprite): pygame.sprite.Sprite.__init__(self) self.x = x self.y = y - self.rect = pygame.Rect(x*64,y*64, 64,64) + self.rect = pygame.Rect(x*64,y*64, 64, 64) diff --git a/sprites/house.py b/sprites/house.py index 3ec092b..ad7f6a0 100644 --- a/sprites/house.py +++ b/sprites/house.py @@ -1,8 +1,36 @@ import pygame -import sys +import sys, random from sprites.cell import Cell +PLASTIC = 0 #blue +GLASS = 1 #green +METAL = 2 #yellow + class House(Cell): - def __init__(self,x,y): - Cell.__init__(self,x,y) - self.image = pygame.image.load("images/house.png") + def __init__(self,x,y, max_plastic, max_glass, max_metal): + Cell.__init__(self,x,y) + self.image = pygame.image.load("images/house.png") + self.rubbish = [0,0,0] #plastic, glass, metal + + self.max_plastic = max_plastic + self.max_glass = max_glass + self.max_metal = max_metal + + def generate_rubbish(self): + if( random.randint(0, 5) == 1 ): #1/5 szansa na wyrzucenie śmiecia w klatce + thrash_type = random.randint(0,2) + self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1 + + if( self.rubbish[PLASTIC] > self.max_plastic ): + self.image = pygame.image.load("images/house_blue.png") + print("PLASTIC alert") + if( self.rubbish[GLASS] > self.max_glass ): + self.image = pygame.image.load("images/house_green.png") + print("GLASS alert") + if( self.rubbish[METAL] > self.max_metal ): + self.image = pygame.image.load("images/house_yellow.png") + print("METAL alert") + + def check_rubbish_status(self): + print( "plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]) ) + \ No newline at end of file diff --git a/to_do.txt b/to_do.txt index ad4de96..26ea986 100644 --- a/to_do.txt +++ b/to_do.txt @@ -1,5 +1,6 @@ +Przy losowaniu domku: Sprawdzić, czy pole które wylosowaliśmy jest typu Grass (bo nie można go postawić na wysypisku ani na innym domku) --Dodanie metody od zapełniania śmietników która updatuje się co klatkę (Jeżeli zapełnienie == 100 to zmienia się sprite i trzeba zabrać czy coś takiego) ++Dodanie metody od zapełniania śmietników która updatuje się co klatkę (Jeżeli zapełnienie == 100 to zmienia się sprite i trzeba zabrać czy coś takiego) -Dodanie hudu +Wpisywanie na początku gry liczby domków -Umieszczenie na mapie wysypisk(I dodanie ich klasy) +-W JAKI SPOSÓB MOŻNA PREZENTOWAĆ KILKA RÓŻNYCH ŚMIECI NA DOMKU?