From ab6ad4f2f851f3b2e2dfda9b72cb4fab235688e8 Mon Sep 17 00:00:00 2001 From: Adam Osiowy Date: Fri, 3 Apr 2020 18:27:14 +0200 Subject: [PATCH] naprawione indexowanie --- game.py | 10 +++++----- modele.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/game.py b/game.py index 3b35aa9..cc5f6f6 100644 --- a/game.py +++ b/game.py @@ -30,12 +30,13 @@ ILOSC_KOLUMN = 15 WINDOW_SIZE = [980, 980] # Tworzenie planszy i kratek -plansza = np.array([[modele.Kratka(j, i) for i in range(ILOSC_KOLUMN)] - for j in range(ILOSC_WIERSZY)]) +plansza = np.array([[modele.Kratka(i, j) for i in range(ILOSC_KOLUMN)] for j in range(ILOSC_WIERSZY)]) + # smieciarka smieciarka = modele.Smieciarka(10, 10) plansza[10, 10].setJestSmieciarka(True) +plansza[10, 10].setKolor(BLUE) # kontenery kontener_plastik = modele.Kontener(0, 0) @@ -118,8 +119,7 @@ def game(): smieciarka.w_dol() # Limit to 60 frames per second - smieciarka.rand_move() - clock.tick(5) + clock.tick(1) # czarny kolor w tle obraz.fill(BLACK) @@ -138,7 +138,7 @@ def game(): obraz.blit(pygame.image.load( "resources/plansza/wysypisko.jpg"), (5, 5)) all_sprites_list.draw(obraz) - + smieciarka.rand_move() # Go ahead and update the screen with what we've drawn. pygame.display.flip() diff --git a/modele.py b/modele.py index add60e7..98d0d7d 100644 --- a/modele.py +++ b/modele.py @@ -43,34 +43,44 @@ 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) 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: self.x += 1 + game.plansza[self.x, self.y].setKolor(BLUE) self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN if self.ruch == 1: 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: self.y -= 1 + 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: self.y += 1 + game.plansza[self.x, self.y].setKolor(BLUE) self.rect.y = self.y * HEIGHT + self.y * MARGIN + + class Kontener(pygame.sprite.Sprite): def __init__(self, x, y): self.x = x