zmiany w tworzeniu planszy
This commit is contained in:
parent
99bece6599
commit
d1da896b63
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
venv/
|
||||
.vscode/
|
||||
.ideagit
|
||||
.idea
|
||||
.idea
|
||||
__pycache__
|
Binary file not shown.
Binary file not shown.
61
game.py
61
game.py
@ -24,46 +24,42 @@ ILOSC_KOLUMN = 15
|
||||
# rozmiar okna
|
||||
WINDOW_SIZE = [980, 980]
|
||||
|
||||
# TWORZENIE OBIEKTOW
|
||||
|
||||
|
||||
# Tworzenie planszy i kratek
|
||||
plansza = np.array([[modele.Kratka(j, i, 0) for i in range(ILOSC_KOLUMN)] for j in range(ILOSC_WIERSZY)])
|
||||
|
||||
# smieciarka
|
||||
smieciarka = modele.Smieciarka(10, 10)
|
||||
plansza[10, 10] = smieciarka
|
||||
|
||||
# kontenery
|
||||
kontener_plastik = modele.Kontener(0, 0)
|
||||
kontener_plastik.setImage(pygame.image.load("resources/pojemnik_plastik.png"))
|
||||
plansza[0, 0] = kontener_plastik
|
||||
|
||||
kontener_metal = modele.Kontener(0, 4)
|
||||
kontener_metal.setImage(pygame.image.load("resources/pojemnik_metal.png"))
|
||||
plansza[0, 4] = kontener_metal
|
||||
|
||||
kontener_organiczne = modele.Kontener(2, 2)
|
||||
kontener_organiczne.setImage(pygame.image.load("resources/pojemnik_organiczne.png"))
|
||||
plansza[2, 2] = kontener_organiczne
|
||||
|
||||
kontener_papier = modele.Kontener(4, 0)
|
||||
kontener_papier.setImage(pygame.image.load("resources/pojemnik_papier.png"))
|
||||
plansza[4, 0] = kontener_papier
|
||||
|
||||
kontener_szklo = modele.Kontener(4, 4)
|
||||
kontener_szklo.setImage(pygame.image.load("resources/pojemnik_szklo.png"))
|
||||
plansza[4, 4] = kontener_szklo
|
||||
|
||||
kratka_list = pygame.sprite.Group()
|
||||
kontener_list = pygame.sprite.Group()
|
||||
smieciarka_list = pygame.sprite.Group()
|
||||
all_sprites_list = pygame.sprite.Group()
|
||||
|
||||
# kratka_list
|
||||
kontener_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo)
|
||||
smieciarka_list.add(smieciarka)
|
||||
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
||||
smieciarka)
|
||||
|
||||
|
||||
def game():
|
||||
|
||||
pygame.init()
|
||||
|
||||
plansza = np.array([[0 for i in range(ILOSC_KOLUMN)] for j in range(ILOSC_WIERSZY)])
|
||||
plansza[0][0] = 1
|
||||
|
||||
# Set the HEIGHT and WIDTH of the screen
|
||||
obraz = pygame.display.set_mode(WINDOW_SIZE)
|
||||
|
||||
@ -78,18 +74,19 @@ def game():
|
||||
|
||||
# -------- 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
|
||||
pos = pygame.mouse.get_pos()
|
||||
pozycja_myszki = pygame.mouse.get_pos()
|
||||
|
||||
# Change the x/y screen coordinates to grid coordinates
|
||||
column = pos[0] // (WIDTH + MARGIN)
|
||||
row = pos[1] // (HEIGHT + MARGIN)
|
||||
# Set that location to one
|
||||
plansza[row][column] = 1
|
||||
print("Click ", pos, "Grid coordinates: ", row, column)
|
||||
kolumna = pozycja_myszki[0] // (WIDTH + MARGIN)
|
||||
wiersz = pozycja_myszki[1] // (HEIGHT + MARGIN)
|
||||
|
||||
print("Click ", pozycja_myszki, "Grid coordinates: ", wiersz, kolumna)
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_LEFT:
|
||||
smieciarka.w_lewo()
|
||||
@ -103,19 +100,17 @@ def game():
|
||||
# Set the screen background
|
||||
obraz.fill(BLACK)
|
||||
|
||||
# Draw the grid
|
||||
for row in range(15):
|
||||
for column in range(15):
|
||||
color = GREY
|
||||
# if grid[row][column] == 1:
|
||||
# color = BLUE
|
||||
pygame.draw.rect(obraz,
|
||||
color,
|
||||
[(MARGIN + WIDTH) * column + MARGIN,
|
||||
(MARGIN + HEIGHT) * row + MARGIN,
|
||||
WIDTH,
|
||||
HEIGHT])
|
||||
obraz.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
||||
# rysowanie planszy
|
||||
# for wiersz in range(ILOSC_WIERSZY):
|
||||
# for kolumna in range(ILOSC_KOLUMN):
|
||||
# kolor = GREY
|
||||
# pygame.draw.rect(obraz,
|
||||
# kolor,
|
||||
# [(MARGIN + WIDTH) * kolumna + MARGIN,
|
||||
# (MARGIN + HEIGHT) * wiersz + MARGIN,
|
||||
# WIDTH,
|
||||
# HEIGHT])
|
||||
#obraz.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
||||
all_sprites_list.draw(obraz)
|
||||
|
||||
# Limit to 60 frames per second
|
||||
|
@ -58,9 +58,11 @@ class Kontener(pygame.sprite.Sprite):
|
||||
|
||||
|
||||
class Kratka(pygame.sprite.Sprite):
|
||||
def __init__(self, poz_x, poz_y):
|
||||
def __init__(self, poz_x, poz_y, nr_obiektu):
|
||||
self.pozX = poz_x
|
||||
self.pozY = poz_y
|
||||
# 0 - nieprzypisany; 1 - smieciarka; 2 - kontener; 3 - wysypisko
|
||||
self.rodzaj_przypisanego_obiektu = nr_obiektu
|
||||
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,
|
||||
@ -68,3 +70,6 @@ class Kratka(pygame.sprite.Sprite):
|
||||
|
||||
def setImage(self, image):
|
||||
self.image = image
|
||||
|
||||
def setRodzajObiektu(self,rodzaj):
|
||||
self.rodzaj_przypisanego_obiektu = rodzaj
|
Loading…
Reference in New Issue
Block a user