diff --git a/game.py b/game.py index 6190fb8..2d99881 100644 --- a/game.py +++ b/game.py @@ -1,6 +1,4 @@ -# TODO: sledzenie pozycji smieciarki -# TODO: pole na ktorym wypisywane beda informacje -# TODO: obsluga kolizji +# TODO: okienko z informacjami import pygame @@ -69,22 +67,19 @@ plansza[4, 4].setJestKontenerem(True) doms_array = ['resources/plansza/domy/dom1.png', 'resources/plansza/domy/dom2.png', 'resources/plansza/domy/dom3.png', 'resources/plansza/domy/dom4.png', 'resources/plansza/domy/dom5.png'] -temp = random.sample(range(5, 14)) -k = 0 -for i in range(0, 4): - dom = modele.Dom(temp[k], temp[k+1]) - dom.setImage(pygame.image.load(random.choice(doms_array))) - plansza[temp[k], temp[k+1]].setJestDomem(True) - all_sprites_list.add(dom) - k = k+2 +wspolrzedne_domow = modele.generujWspolrzedneDomow() +for i in range(len(wspolrzedne_domow)): + dom = modele.Dom(wspolrzedne_domow[i, 0], wspolrzedne_domow[i, 1]) + dom.setImage(pygame.image.load(random.choice(doms_array))) + plansza[wspolrzedne_domow[i, 0], wspolrzedne_domow[i, 1]].setJestDomem(True) + all_sprites_list.add(dom) # ustawienie wysypiska, rozmiar wysypiska 5x5 for i in range(5): for j in range(5): plansza[i, j].setJestWysypiskiem(True) - all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo, smieciarka) diff --git a/modele.py b/modele.py index 463bd69..309669a 100644 --- a/modele.py +++ b/modele.py @@ -1,6 +1,8 @@ import pygame import game import random +import numpy as np +import random # This sets the WIDTH and HEIGHT of each grid location WIDTH = 60 @@ -43,15 +45,13 @@ class Smieciarka(pygame.sprite.Sprite): if self.x > 0: if game.plansza[self.x - 1, self.y].jestPrzeszkoda is not True: self.x -= 1 - game.plansza[self.x,self.y].setKolor(BLUE) + game.plansza[self.x, self.y].setKolor(BLUE) self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN if self.ruch == 2: self.image = pygame.image.load( 'resources/plansza/smieciarka.png') self.ruch = 1 - - def w_prawo(self): if self.x < 14: if game.plansza[self.x + 1, self.y].jestPrzeszkoda is not True: @@ -62,7 +62,6 @@ class Smieciarka(pygame.sprite.Sprite): self.image = pygame.transform.flip(self.image, True, False) self.ruch = 2 - def w_gore(self): if self.y > 0: if game.plansza[self.x, self.y - 1].jestPrzeszkoda is not True: @@ -70,7 +69,6 @@ class Smieciarka(pygame.sprite.Sprite): game.plansza[self.x, self.y].setKolor(BLUE) self.rect.y = self.y * HEIGHT + self.y * MARGIN - def w_dol(self): if self.y < 14: if game.plansza[self.x, self.y + 1].jestPrzeszkoda is not True: @@ -140,3 +138,29 @@ class Kratka(pygame.sprite.Sprite): def setKolor(self, kolor): self.kolor = kolor + + +def generujWspolrzedneDomow(): + unikalne = False + wspolrzedne_domow = np.array([[0 for i in range(2)] for j in range(15)]) + while not unikalne: + for i in range(15): + wspolrzedne_domow[i, 0] = random.randrange(15) + if wspolrzedne_domow[i, 0] < 5: + wspolrzedne_domow[i, 1] = random.randrange(5, 15) + else: + wspolrzedne_domow[i, 1] = random.randrange(0, 15) + wspolrzedne_domow = np.unique(wspolrzedne_domow, axis=0) + + j = 0 + while True: + if j >= len(wspolrzedne_domow): + break + if np.sum(wspolrzedne_domow[j, 0] == wspolrzedne_domow[:, 0]) > 1: + wspolrzedne_domow = np.delete(wspolrzedne_domow, j, axis=0) + else: + j += 1 + + if len(wspolrzedne_domow) > 5: + unikalne = True + return wspolrzedne_domow diff --git a/resources/plansza/domy/dom1.png b/resources/plansza/domy/dom1.png index 4796bc7..9517a77 100644 Binary files a/resources/plansza/domy/dom1.png and b/resources/plansza/domy/dom1.png differ diff --git a/resources/plansza/domy/dom2.png b/resources/plansza/domy/dom2.png index 12a2ea7..03e6d94 100644 Binary files a/resources/plansza/domy/dom2.png and b/resources/plansza/domy/dom2.png differ diff --git a/resources/plansza/domy/dom3.png b/resources/plansza/domy/dom3.png index 55a6a71..fc61b9b 100644 Binary files a/resources/plansza/domy/dom3.png and b/resources/plansza/domy/dom3.png differ diff --git a/resources/plansza/domy/dom4.png b/resources/plansza/domy/dom4.png index ae11a8d..20d9a74 100644 Binary files a/resources/plansza/domy/dom4.png and b/resources/plansza/domy/dom4.png differ diff --git a/resources/plansza/domy/dom5.png b/resources/plansza/domy/dom5.png index d7cad15..c49ffd4 100644 Binary files a/resources/plansza/domy/dom5.png and b/resources/plansza/domy/dom5.png differ