dodany pakiet numpy
This commit is contained in:
parent
55c0218bca
commit
c7351ef952
61
game.py
61
game.py
@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import modele
|
import modele
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
# kolory
|
# kolory
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
@ -16,54 +17,55 @@ HEIGHT = 60
|
|||||||
# margines pomiedzy kratkami
|
# margines pomiedzy kratkami
|
||||||
MARGIN = 5
|
MARGIN = 5
|
||||||
|
|
||||||
|
# rozmiar kratki
|
||||||
|
ILOSC_WIERSZY = 100
|
||||||
|
ILOSC_KOLUMN = 100
|
||||||
|
|
||||||
# rozmiar okna
|
# rozmiar okna
|
||||||
WINDOW_SIZE = [980, 980]
|
WINDOW_SIZE = [980, 980]
|
||||||
|
|
||||||
|
|
||||||
def game():
|
|
||||||
|
|
||||||
# TWORZENIE OBIEKTOW
|
# TWORZENIE OBIEKTOW
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
smieciarka = modele.Smieciarka(10, 10)
|
smieciarka = modele.Smieciarka(10, 10)
|
||||||
|
|
||||||
kontener_plastik = modele.Kontener(0, 0)
|
kontener_plastik = modele.Kontener(0, 0)
|
||||||
kontener_plastik.image = pygame.image.load("resources/pojemnik_plastik.png")
|
kontener_plastik.setImage(pygame.image.load("resources/pojemnik_plastik.png"))
|
||||||
|
|
||||||
kontener_metal = modele.Kontener(0, 4)
|
kontener_metal = modele.Kontener(0, 4)
|
||||||
kontener_metal.image = pygame.image.load("resources/pojemnik_metal.png")
|
kontener_metal.setImage(pygame.image.load("resources/pojemnik_metal.png"))
|
||||||
|
|
||||||
kontener_organiczne = modele.Kontener(2, 2)
|
kontener_organiczne = modele.Kontener(2, 2)
|
||||||
kontener_organiczne.image = pygame.image.load("resources/pojemnik_organiczne.png")
|
kontener_organiczne.setImage(pygame.image.load("resources/pojemnik_organiczne.png"))
|
||||||
|
|
||||||
kontener_papier = modele.Kontener(4, 0)
|
kontener_papier = modele.Kontener(4, 0)
|
||||||
kontener_papier.image = pygame.image.load("resources/pojemnik_papier.png")
|
kontener_papier.setImage(pygame.image.load("resources/pojemnik_papier.png"))
|
||||||
|
|
||||||
kontener_szklo = modele.Kontener(4, 4)
|
kontener_szklo = modele.Kontener(4, 4)
|
||||||
kontener_szklo.image = pygame.image.load("resources/pojemnik_szklo.png")
|
kontener_szklo.setImage(pygame.image.load("resources/pojemnik_szklo.png"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kratka_list = pygame.sprite.Group()
|
||||||
kontener_list = pygame.sprite.Group()
|
kontener_list = pygame.sprite.Group()
|
||||||
smieciarka_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)
|
kontener_list.add(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo)
|
||||||
smieciarka_list.add(smieciarka)
|
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():
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
# Create a 2 dimensional array. A two dimensional
|
plansza = np.array([[0 for i in range(ILOSC_KOLUMN)] for j in range(ILOSC_WIERSZY)])
|
||||||
# array is simply a list of lists.
|
plansza[0][0] = 1
|
||||||
grid = []
|
|
||||||
for row in range(100):
|
|
||||||
# Add an empty array that will hold each cell
|
|
||||||
# in this row
|
|
||||||
grid.append([])
|
|
||||||
for column in range(100):
|
|
||||||
grid[row].append(0) # Append a cell
|
|
||||||
|
|
||||||
# Set row 0, cell 0 to one. (Remember rows and
|
|
||||||
# column numbers start at zero.)
|
|
||||||
grid[0][0] = 1
|
|
||||||
|
|
||||||
# Set the HEIGHT and WIDTH of the screen
|
# Set the HEIGHT and WIDTH of the screen
|
||||||
screen = pygame.display.set_mode(WINDOW_SIZE)
|
obraz = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
|
|
||||||
# Set title of screen
|
# Set title of screen
|
||||||
pygame.display.set_caption("Inteligentna śmieciarka")
|
pygame.display.set_caption("Inteligentna śmieciarka")
|
||||||
@ -74,7 +76,6 @@ def game():
|
|||||||
# Used to manage how fast the screen updates
|
# Used to manage how fast the screen updates
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
|
||||||
# -------- Main Program Loop -----------
|
# -------- Main Program Loop -----------
|
||||||
while not done:
|
while not done:
|
||||||
for event in pygame.event.get(): # User did something
|
for event in pygame.event.get(): # User did something
|
||||||
@ -87,7 +88,7 @@ def game():
|
|||||||
column = pos[0] // (WIDTH + MARGIN)
|
column = pos[0] // (WIDTH + MARGIN)
|
||||||
row = pos[1] // (HEIGHT + MARGIN)
|
row = pos[1] // (HEIGHT + MARGIN)
|
||||||
# Set that location to one
|
# Set that location to one
|
||||||
grid[row][column] = 1
|
plansza[row][column] = 1
|
||||||
print("Click ", pos, "Grid coordinates: ", row, column)
|
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:
|
||||||
@ -100,7 +101,7 @@ def game():
|
|||||||
smieciarka.w_dol()
|
smieciarka.w_dol()
|
||||||
|
|
||||||
# Set the screen background
|
# Set the screen background
|
||||||
screen.fill(BLACK)
|
obraz.fill(BLACK)
|
||||||
|
|
||||||
# Draw the grid
|
# Draw the grid
|
||||||
for row in range(15):
|
for row in range(15):
|
||||||
@ -108,14 +109,14 @@ def game():
|
|||||||
color = GREY
|
color = GREY
|
||||||
# if grid[row][column] == 1:
|
# if grid[row][column] == 1:
|
||||||
# color = BLUE
|
# color = BLUE
|
||||||
pygame.draw.rect(screen,
|
pygame.draw.rect(obraz,
|
||||||
color,
|
color,
|
||||||
[(MARGIN + WIDTH) * column + MARGIN,
|
[(MARGIN + WIDTH) * column + MARGIN,
|
||||||
(MARGIN + HEIGHT) * row + MARGIN,
|
(MARGIN + HEIGHT) * row + MARGIN,
|
||||||
WIDTH,
|
WIDTH,
|
||||||
HEIGHT])
|
HEIGHT])
|
||||||
screen.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
obraz.blit(pygame.image.load("resources/wysypisko.jpg"), (5, 5))
|
||||||
all_sprites_list.draw(screen)
|
all_sprites_list.draw(obraz)
|
||||||
|
|
||||||
# Limit to 60 frames per second
|
# Limit to 60 frames per second
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
1
main.py
1
main.py
@ -4,6 +4,7 @@ import game
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("poczatek programu")
|
print("poczatek programu")
|
||||||
|
game.game()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -50,9 +50,11 @@ class Kontener(pygame.sprite.Sprite):
|
|||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.image = pygame.image.__init__()
|
self.image = pygame.image.__class__
|
||||||
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y + MARGIN,
|
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y + MARGIN,
|
||||||
WIDTH, HEIGHT)
|
WIDTH, HEIGHT)
|
||||||
|
def setImage(self,image):
|
||||||
|
self.image = image
|
||||||
|
|
||||||
|
|
||||||
class Kratka(pygame.sprite.Sprite):
|
class Kratka(pygame.sprite.Sprite):
|
||||||
@ -60,7 +62,7 @@ class Kratka(pygame.sprite.Sprite):
|
|||||||
self.pozX = poz_x
|
self.pozX = poz_x
|
||||||
self.pozY = poz_y
|
self.pozY = poz_y
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.image = pygame.image.__init__()
|
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,
|
||||||
WIDTH, HEIGHT)
|
WIDTH, HEIGHT)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user