200 lines
6.0 KiB
Python
200 lines
6.0 KiB
Python
import pygame
|
|
import game
|
|
import random
|
|
import numpy as np
|
|
import random
|
|
import os
|
|
import shutil
|
|
|
|
# This sets the WIDTH and HEIGHT of each grid location
|
|
WIDTH = 60
|
|
HEIGHT = 60
|
|
|
|
# This sets the margin between each cell
|
|
MARGIN = 5
|
|
|
|
# kolory
|
|
BLACK = (0, 0, 0)
|
|
WHITE = (255, 255, 255)
|
|
GREEN = (0, 255, 0)
|
|
RED = (255, 0, 0)
|
|
BLUE = (0, 0, 255)
|
|
GREY = (128, 128, 128)
|
|
|
|
|
|
class Smieciarka(pygame.sprite.Sprite):
|
|
def __init__(self, x, y):
|
|
self.x = x
|
|
self.y = y
|
|
self.image = pygame.image.load('resources/plansza/smieciarka.png')
|
|
self.ruch = 0
|
|
self.plastik = []
|
|
self.szklo = []
|
|
self.papier = []
|
|
self.metal = []
|
|
self.pozostale = []
|
|
pygame.sprite.Sprite.__init__(self)
|
|
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH,
|
|
HEIGHT)
|
|
|
|
def rand_move(self):
|
|
rand_int = random.randint(0, 3)
|
|
if rand_int == 0:
|
|
self.w_lewo()
|
|
elif rand_int == 1:
|
|
self.w_prawo()
|
|
elif rand_int == 2:
|
|
self.w_gore()
|
|
elif rand_int == 3:
|
|
self.w_dol()
|
|
|
|
def w_lewo(self):
|
|
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
|
|
|
|
def dodajPlastik(self, smiec):
|
|
self.plastik.append(smiec)
|
|
|
|
def dodajSzklo(self, smiec):
|
|
self.szklo.append(smiec)
|
|
|
|
def dodajPapier(self, smiec):
|
|
self.papier.append(smiec)
|
|
|
|
def dodajMetal(self, smiec):
|
|
self.metal.append(smiec)
|
|
|
|
|
|
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)
|
|
self.smieci = []
|
|
|
|
def setImage(self, image):
|
|
self.image = image
|
|
|
|
def dodajSmiec(self, smiec):
|
|
self.smieci.append(smiec)
|
|
|
|
def usunSmiec(self, smiec):
|
|
self.smieci.remove(smiec)
|
|
|
|
|
|
class Kontener(pygame.sprite.Sprite):
|
|
def __init__(self, x, y, typ):
|
|
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)
|
|
self.smieci = []
|
|
self.typ = typ
|
|
os.makedirs("resources/smieci w kontenerach/" + self.typ)
|
|
|
|
def dodajSmiec(self, smiec):
|
|
self.smieci.append(smiec)
|
|
shutil.copy(smiec, "resources/smieci w kontenerach/" + self.typ)
|
|
|
|
def setImage(self, image):
|
|
self.image = image
|
|
|
|
|
|
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
|
|
self.kolor = GREY
|
|
pygame.sprite.Sprite.__init__(self)
|
|
self.image = pygame.image.__class__
|
|
self.rect = pygame.Rect(self.pozX * WIDTH + MARGIN * self.pozX + MARGIN,
|
|
self.pozY * HEIGHT + MARGIN * self.pozY + MARGIN,
|
|
WIDTH, HEIGHT)
|
|
|
|
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
|
|
|
|
def setJestKontenerem(self, bool):
|
|
self.jestKontenerem = bool
|
|
|
|
def setJestWysypiskiem(self, bool):
|
|
self.jestWysypiskiem = bool
|
|
|
|
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
|