161 lines
4.8 KiB
Python
161 lines
4.8 KiB
Python
# TODO: sledzenie pozycji smieciarki
|
|
# TODO: pole na ktorym wypisywane beda informacje
|
|
# TODO: obsluga kolizji
|
|
|
|
|
|
import pygame
|
|
import modele
|
|
import numpy as np
|
|
import random
|
|
|
|
# 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)
|
|
|
|
# wysokosc i szerokosc kazdej kratki
|
|
WIDTH = 60
|
|
HEIGHT = 60
|
|
|
|
# margines pomiedzy kratkami
|
|
MARGIN = 5
|
|
|
|
# rozmiar kratki
|
|
ILOSC_WIERSZY = 15
|
|
ILOSC_KOLUMN = 15
|
|
|
|
# rozmiar okna
|
|
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)
|
|
plansza[10, 10].setJestSmieciarka(True)
|
|
|
|
# kontenery
|
|
kontener_plastik = modele.Kontener(0, 0)
|
|
kontener_plastik.setImage(pygame.image.load(
|
|
"resources/plansza/pojemnik_plastik.png"))
|
|
plansza[0, 0].setJestKontenerem(True)
|
|
|
|
kontener_metal = modele.Kontener(0, 4)
|
|
kontener_metal.setImage(pygame.image.load(
|
|
"resources/plansza/pojemnik_metal.png"))
|
|
plansza[0, 4].setJestKontenerem(True)
|
|
|
|
kontener_organiczne = modele.Kontener(2, 2)
|
|
kontener_organiczne.setImage(pygame.image.load(
|
|
"resources/plansza/pojemnik_organiczne.png"))
|
|
plansza[2, 2].setJestKontenerem(True)
|
|
|
|
kontener_papier = modele.Kontener(4, 0)
|
|
kontener_papier.setImage(pygame.image.load(
|
|
"resources/plansza/pojemnik_papier.png"))
|
|
plansza[4, 0].setJestKontenerem(True)
|
|
|
|
kontener_szklo = modele.Kontener(4, 4)
|
|
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.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
|
smieciarka)
|
|
|
|
|
|
def game():
|
|
pygame.init()
|
|
|
|
# Set the HEIGHT and WIDTH of the screen
|
|
obraz = pygame.display.set_mode(WINDOW_SIZE)
|
|
|
|
# Set title of screen
|
|
pygame.display.set_caption("Inteligentna śmieciarka")
|
|
|
|
# Loop until the user clicks the close button.
|
|
done = False
|
|
|
|
# Used to manage how fast the screen updates
|
|
clock = pygame.time.Clock()
|
|
|
|
# -------- Main Program Loop -----------
|
|
while not done:
|
|
|
|
# obsluga zdarzen typu nacisniecie klawisza lub przycisku myszy
|
|
for event in pygame.event.get(): # User did something
|
|
if event.type == pygame.QUIT: # If user clicked close
|
|
done = True # Flag that we are done so we exit this loop
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
# User clicks the mouse. Get the position
|
|
pozycja_myszki = pygame.mouse.get_pos()
|
|
|
|
# Change the x/y screen coordinates to grid coordinates
|
|
kolumna = pozycja_myszki[0] // (WIDTH + MARGIN)
|
|
wiersz = pozycja_myszki[1] // (HEIGHT + MARGIN)
|
|
|
|
print("Click ", pozycja_myszki,
|
|
"Grid coordinates: ", wiersz, kolumna)
|
|
# plansza[wiersz, kolumna].setKolor(BLUE)
|
|
|
|
elif event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_LEFT:
|
|
smieciarka.w_lewo()
|
|
if event.key == pygame.K_RIGHT:
|
|
smieciarka.w_prawo()
|
|
if event.key == pygame.K_UP:
|
|
smieciarka.w_gore()
|
|
if event.key == pygame.K_DOWN:
|
|
smieciarka.w_dol()
|
|
|
|
# Limit to 60 frames per second
|
|
smieciarka.rand_move()
|
|
clock.tick(5)
|
|
|
|
# czarny kolor w tle
|
|
obraz.fill(BLACK)
|
|
|
|
# rysowanie planszy #
|
|
for i in range(ILOSC_WIERSZY):
|
|
for j in range(ILOSC_KOLUMN):
|
|
pygame.draw.rect(obraz,
|
|
plansza[i, j].kolor,
|
|
[(MARGIN + WIDTH) * plansza[i, j].pozY + MARGIN,
|
|
(MARGIN + HEIGHT) *
|
|
plansza[i, j].pozX + MARGIN,
|
|
WIDTH,
|
|
HEIGHT])
|
|
|
|
obraz.blit(pygame.image.load(
|
|
"resources/plansza/wysypisko.jpg"), (5, 5))
|
|
all_sprites_list.draw(obraz)
|
|
|
|
# Go ahead and update the screen with what we've drawn.
|
|
pygame.display.flip()
|
|
|
|
pygame.quit()
|