zmiany w tworzeniu planszy
This commit is contained in:
parent
99bece6599
commit
d1da896b63
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ venv/
|
|||||||
.vscode/
|
.vscode/
|
||||||
.ideagit
|
.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
|
# rozmiar okna
|
||||||
WINDOW_SIZE = [980, 980]
|
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)
|
smieciarka = modele.Smieciarka(10, 10)
|
||||||
|
plansza[10, 10] = smieciarka
|
||||||
|
|
||||||
|
# kontenery
|
||||||
kontener_plastik = modele.Kontener(0, 0)
|
kontener_plastik = modele.Kontener(0, 0)
|
||||||
kontener_plastik.setImage(pygame.image.load("resources/pojemnik_plastik.png"))
|
kontener_plastik.setImage(pygame.image.load("resources/pojemnik_plastik.png"))
|
||||||
|
plansza[0, 0] = kontener_plastik
|
||||||
|
|
||||||
kontener_metal = modele.Kontener(0, 4)
|
kontener_metal = modele.Kontener(0, 4)
|
||||||
kontener_metal.setImage(pygame.image.load("resources/pojemnik_metal.png"))
|
kontener_metal.setImage(pygame.image.load("resources/pojemnik_metal.png"))
|
||||||
|
plansza[0, 4] = kontener_metal
|
||||||
|
|
||||||
kontener_organiczne = modele.Kontener(2, 2)
|
kontener_organiczne = modele.Kontener(2, 2)
|
||||||
kontener_organiczne.setImage(pygame.image.load("resources/pojemnik_organiczne.png"))
|
kontener_organiczne.setImage(pygame.image.load("resources/pojemnik_organiczne.png"))
|
||||||
|
plansza[2, 2] = kontener_organiczne
|
||||||
|
|
||||||
kontener_papier = modele.Kontener(4, 0)
|
kontener_papier = modele.Kontener(4, 0)
|
||||||
kontener_papier.setImage(pygame.image.load("resources/pojemnik_papier.png"))
|
kontener_papier.setImage(pygame.image.load("resources/pojemnik_papier.png"))
|
||||||
|
plansza[4, 0] = kontener_papier
|
||||||
|
|
||||||
kontener_szklo = modele.Kontener(4, 4)
|
kontener_szklo = modele.Kontener(4, 4)
|
||||||
kontener_szklo.setImage(pygame.image.load("resources/pojemnik_szklo.png"))
|
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()
|
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,
|
all_sprites_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
||||||
smieciarka)
|
smieciarka)
|
||||||
|
|
||||||
|
|
||||||
def game():
|
def game():
|
||||||
|
|
||||||
pygame.init()
|
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
|
# Set the HEIGHT and WIDTH of the screen
|
||||||
obraz = pygame.display.set_mode(WINDOW_SIZE)
|
obraz = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
|
|
||||||
@ -78,18 +74,19 @@ def game():
|
|||||||
|
|
||||||
# -------- Main Program Loop -----------
|
# -------- Main Program Loop -----------
|
||||||
while not done:
|
while not done:
|
||||||
|
# obsluga zdarzen typu nacisniecie klawisza lub przycisku myszy
|
||||||
for event in pygame.event.get(): # User did something
|
for event in pygame.event.get(): # User did something
|
||||||
if event.type == pygame.QUIT: # If user clicked close
|
if event.type == pygame.QUIT: # If user clicked close
|
||||||
done = True # Flag that we are done so we exit this loop
|
done = True # Flag that we are done so we exit this loop
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
# User clicks the mouse. Get the position
|
# 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
|
# Change the x/y screen coordinates to grid coordinates
|
||||||
column = pos[0] // (WIDTH + MARGIN)
|
kolumna = pozycja_myszki[0] // (WIDTH + MARGIN)
|
||||||
row = pos[1] // (HEIGHT + MARGIN)
|
wiersz = pozycja_myszki[1] // (HEIGHT + MARGIN)
|
||||||
# Set that location to one
|
|
||||||
plansza[row][column] = 1
|
print("Click ", pozycja_myszki, "Grid coordinates: ", wiersz, kolumna)
|
||||||
print("Click ", pos, "Grid coordinates: ", row, column)
|
|
||||||
elif event.type == pygame.KEYDOWN:
|
elif event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
smieciarka.w_lewo()
|
smieciarka.w_lewo()
|
||||||
@ -103,19 +100,17 @@ def game():
|
|||||||
# Set the screen background
|
# Set the screen background
|
||||||
obraz.fill(BLACK)
|
obraz.fill(BLACK)
|
||||||
|
|
||||||
# Draw the grid
|
# rysowanie planszy
|
||||||
for row in range(15):
|
# for wiersz in range(ILOSC_WIERSZY):
|
||||||
for column in range(15):
|
# for kolumna in range(ILOSC_KOLUMN):
|
||||||
color = GREY
|
# kolor = GREY
|
||||||
# if grid[row][column] == 1:
|
# pygame.draw.rect(obraz,
|
||||||
# color = BLUE
|
# kolor,
|
||||||
pygame.draw.rect(obraz,
|
# [(MARGIN + WIDTH) * kolumna + MARGIN,
|
||||||
color,
|
# (MARGIN + HEIGHT) * wiersz + MARGIN,
|
||||||
[(MARGIN + WIDTH) * column + MARGIN,
|
# WIDTH,
|
||||||
(MARGIN + HEIGHT) * row + MARGIN,
|
# HEIGHT])
|
||||||
WIDTH,
|
#obraz.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
||||||
HEIGHT])
|
|
||||||
obraz.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
|
||||||
all_sprites_list.draw(obraz)
|
all_sprites_list.draw(obraz)
|
||||||
|
|
||||||
# Limit to 60 frames per second
|
# Limit to 60 frames per second
|
||||||
|
@ -58,9 +58,11 @@ class Kontener(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
|
|
||||||
class Kratka(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.pozX = poz_x
|
||||||
self.pozY = poz_y
|
self.pozY = poz_y
|
||||||
|
# 0 - nieprzypisany; 1 - smieciarka; 2 - kontener; 3 - wysypisko
|
||||||
|
self.rodzaj_przypisanego_obiektu = nr_obiektu
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.image = pygame.image.__class__
|
self.image = pygame.image.__class__
|
||||||
self.rect = pygame.Rect(self.pozX * WIDTH + MARGIN * self.pozX + MARGIN, self.pozY * HEIGHT + MARGIN * self.pozY + MARGIN,
|
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):
|
def setImage(self, image):
|
||||||
self.image = image
|
self.image = image
|
||||||
|
|
||||||
|
def setRodzajObiektu(self,rodzaj):
|
||||||
|
self.rodzaj_przypisanego_obiektu = rodzaj
|
Loading…
Reference in New Issue
Block a user