merged
This commit is contained in:
commit
09df30d7da
20
game.py
20
game.py
@ -6,6 +6,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import modele
|
import modele
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import random
|
||||||
|
|
||||||
# kolory
|
# kolory
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
@ -31,7 +32,7 @@ WINDOW_SIZE = [980, 980]
|
|||||||
|
|
||||||
# Tworzenie planszy i kratek
|
# Tworzenie planszy i kratek
|
||||||
plansza = np.array([[modele.Kratka(i, j) 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)])
|
||||||
|
all_sprites_list = pygame.sprite.Group()
|
||||||
|
|
||||||
# smieciarka
|
# smieciarka
|
||||||
smieciarka = modele.Smieciarka(10, 10)
|
smieciarka = modele.Smieciarka(10, 10)
|
||||||
@ -63,12 +64,27 @@ kontener_szklo.setImage(pygame.image.load(
|
|||||||
"resources/plansza/pojemnik_szklo.png"))
|
"resources/plansza/pojemnik_szklo.png"))
|
||||||
plansza[4, 4].setJestKontenerem(True)
|
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
|
# ustawienie wysypiska, rozmiar wysypiska 5x5
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
for j in range(5):
|
for j in range(5):
|
||||||
plansza[i, j].setJestWysypiskiem(True)
|
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,
|
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
||||||
smieciarka)
|
smieciarka)
|
||||||
|
|
||||||
|
28
modele.py
28
modele.py
@ -29,14 +29,14 @@ class Smieciarka(pygame.sprite.Sprite):
|
|||||||
HEIGHT)
|
HEIGHT)
|
||||||
|
|
||||||
def rand_move(self):
|
def rand_move(self):
|
||||||
rand_int = random.randint(0, 20)
|
rand_int = random.randint(0, 3)
|
||||||
if (rand_int >= 0 and rand_int < 5):
|
if rand_int == 0:
|
||||||
self.w_lewo()
|
self.w_lewo()
|
||||||
elif (rand_int >= 5 and rand_int < 10):
|
elif rand_int == 1:
|
||||||
self.w_prawo()
|
self.w_prawo()
|
||||||
elif (rand_int >= 10 and rand_int < 15):
|
elif rand_int == 2:
|
||||||
self.w_gore()
|
self.w_gore()
|
||||||
elif (rand_int >= 15 and rand_int < 20):
|
elif rand_int == 3:
|
||||||
self.w_dol()
|
self.w_dol()
|
||||||
|
|
||||||
def w_lewo(self):
|
def w_lewo(self):
|
||||||
@ -79,6 +79,17 @@ class Smieciarka(pygame.sprite.Sprite):
|
|||||||
self.rect.y = self.y * HEIGHT + self.y * MARGIN
|
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):
|
class Kontener(pygame.sprite.Sprite):
|
||||||
@ -98,6 +109,7 @@ class Kratka(pygame.sprite.Sprite):
|
|||||||
def __init__(self, poz_x, poz_y):
|
def __init__(self, poz_x, poz_y):
|
||||||
self.pozX = poz_x
|
self.pozX = poz_x
|
||||||
self.pozY = poz_y
|
self.pozY = poz_y
|
||||||
|
self.jestDomem = False
|
||||||
self.jestKontenerem = False
|
self.jestKontenerem = False
|
||||||
self.jestWysypiskiem = False
|
self.jestWysypiskiem = False
|
||||||
self.jestPrzeszkoda = False
|
self.jestPrzeszkoda = False
|
||||||
@ -111,6 +123,12 @@ class Kratka(pygame.sprite.Sprite):
|
|||||||
def setImage(self, image):
|
def setImage(self, image):
|
||||||
self.image = image
|
self.image = image
|
||||||
|
|
||||||
|
def setJestDomem(self, bool):
|
||||||
|
self.jestDomem = bool
|
||||||
|
|
||||||
|
def setJestSmieciarka(self, bool):
|
||||||
|
self.jestSmieciarka = bool
|
||||||
|
|
||||||
def setJestPrzeszkoda(self, bool):
|
def setJestPrzeszkoda(self, bool):
|
||||||
self.jestPrzeszkoda = bool
|
self.jestPrzeszkoda = bool
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user