This commit is contained in:
Adam Osiowy 2020-04-03 18:42:57 +02:00
commit 09df30d7da
2 changed files with 41 additions and 7 deletions

20
game.py
View File

@ -6,6 +6,7 @@
import pygame
import modele
import numpy as np
import random
# kolory
BLACK = (0, 0, 0)
@ -31,7 +32,7 @@ WINDOW_SIZE = [980, 980]
# Tworzenie planszy i kratek
plansza = np.array([[modele.Kratka(i, j) for i in range(ILOSC_KOLUMN)] for j in range(ILOSC_WIERSZY)])
all_sprites_list = pygame.sprite.Group()
# smieciarka
smieciarka = modele.Smieciarka(10, 10)
@ -63,12 +64,27 @@ kontener_szklo.setImage(pygame.image.load(
"resources/plansza/pojemnik_szklo.png"))
plansza[4, 4].setJestKontenerem(True)
# domy
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
# ustawienie wysypiska, rozmiar wysypiska 5x5
for i in range(5):
for j in range(5):
plansza[i, j].setJestWysypiskiem(True)
all_sprites_list = pygame.sprite.Group()
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
smieciarka)

View File

@ -29,14 +29,14 @@ class Smieciarka(pygame.sprite.Sprite):
HEIGHT)
def rand_move(self):
rand_int = random.randint(0, 20)
if (rand_int >= 0 and rand_int < 5):
rand_int = random.randint(0, 3)
if rand_int == 0:
self.w_lewo()
elif (rand_int >= 5 and rand_int < 10):
elif rand_int == 1:
self.w_prawo()
elif (rand_int >= 10 and rand_int < 15):
elif rand_int == 2:
self.w_gore()
elif (rand_int >= 15 and rand_int < 20):
elif rand_int == 3:
self.w_dol()
def w_lewo(self):
@ -79,6 +79,17 @@ class Smieciarka(pygame.sprite.Sprite):
self.rect.y = self.y * HEIGHT + self.y * MARGIN
class Dom(pygame.sprite.Sprite):
def __init__(self, x, y):
self.x = x
self.y = y
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.__class__
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y + MARGIN,
WIDTH, HEIGHT)
def setImage(self, image):
self.image = image
class Kontener(pygame.sprite.Sprite):
@ -98,6 +109,7 @@ class Kratka(pygame.sprite.Sprite):
def __init__(self, poz_x, poz_y):
self.pozX = poz_x
self.pozY = poz_y
self.jestDomem = False
self.jestKontenerem = False
self.jestWysypiskiem = False
self.jestPrzeszkoda = False
@ -111,6 +123,12 @@ class Kratka(pygame.sprite.Sprite):
def setImage(self, image):
self.image = image
def setJestDomem(self, bool):
self.jestDomem = bool
def setJestSmieciarka(self, bool):
self.jestSmieciarka = bool
def setJestPrzeszkoda(self, bool):
self.jestPrzeszkoda = bool