dodawanie domkow bez obslugi bledow

This commit is contained in:
Bowske 2020-04-03 17:39:57 +02:00
parent 5708e1fe21
commit c2ff8e4c4b
2 changed files with 33 additions and 1 deletions

17
game.py
View File

@ -6,6 +6,7 @@
import pygame
import modele
import numpy as np
import random
# kolory
BLACK = (0, 0, 0)
@ -32,6 +33,7 @@ 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)])
all_sprites_list = pygame.sprite.Group()
# smieciarka
smieciarka = modele.Smieciarka(10, 10)
@ -63,12 +65,25 @@ 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']
for i in range(0, 5):
temp = [random.randint(5, 14), random.randint(5, 14)]
print(temp)
dom = modele.Dom(temp[0], temp[1])
dom.setImage(pygame.image.load(random.choice(doms_array)))
plansza[temp[0], temp[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 = pygame.sprite.Group()
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
smieciarka)

View File

@ -67,6 +67,19 @@ 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):
def __init__(self, x, y):
self.x = x
@ -84,6 +97,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
@ -97,6 +111,9 @@ 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