merge
50
game.py
@ -1,26 +1,34 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
|
||||||
class Smieciarka(pygame.sprite.Sprite):
|
class Smieciarka(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.image = pygame.image.load('smieciarka.png')
|
self.image = pygame.image.load('smieciarka.png')
|
||||||
|
self.ruch = 0
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x +
|
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH,
|
||||||
MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH, HEIGHT)
|
HEIGHT)
|
||||||
|
|
||||||
def w_lewo(self):
|
def w_lewo(self):
|
||||||
if self.x > 0:
|
if self.x > 0:
|
||||||
self.x -= 1
|
self.x -= 1
|
||||||
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
|
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
|
||||||
|
if self.ruch == 2:
|
||||||
self.image = pygame.image.load('smieciarka.png')
|
self.image = pygame.image.load('smieciarka.png')
|
||||||
|
self.ruch = 1
|
||||||
|
|
||||||
def w_prawo(self):
|
def w_prawo(self):
|
||||||
if self.x < 14:
|
if self.x < 14:
|
||||||
self.x += 1
|
self.x += 1
|
||||||
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
|
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
|
||||||
self.image = pygame.image.load('smieciarka_odwrocona.png')
|
if self.ruch == 1:
|
||||||
|
self.image = pygame.transform.flip(
|
||||||
|
smieciarka.image, True, False)
|
||||||
|
self.ruch = 2
|
||||||
|
|
||||||
def w_gore(self):
|
def w_gore(self):
|
||||||
if self.y > 0:
|
if self.y > 0:
|
||||||
@ -33,12 +41,22 @@ class Smieciarka(pygame.sprite.Sprite):
|
|||||||
self.rect.y = self.y * HEIGHT + self.y * MARGIN
|
self.rect.y = self.y * HEIGHT + self.y * MARGIN
|
||||||
|
|
||||||
|
|
||||||
|
class Kontener(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
pygame.sprite.Sprite.__init__(self)
|
||||||
|
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y + MARGIN,
|
||||||
|
WIDTH, HEIGHT)
|
||||||
|
|
||||||
|
|
||||||
# Define some colors
|
# Define some colors
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
GREEN = (0, 255, 0)
|
GREEN = (0, 255, 0)
|
||||||
RED = (255, 0, 0)
|
RED = (255, 0, 0)
|
||||||
BLUE = (0, 0, 255)
|
BLUE = (0, 0, 255)
|
||||||
|
GREY = (128, 128, 128)
|
||||||
|
|
||||||
# This sets the WIDTH and HEIGHT of each grid location
|
# This sets the WIDTH and HEIGHT of each grid location
|
||||||
WIDTH = 60
|
WIDTH = 60
|
||||||
@ -61,9 +79,6 @@ for row in range(100):
|
|||||||
# column numbers start at zero.)
|
# column numbers start at zero.)
|
||||||
grid[0][0] = 1
|
grid[0][0] = 1
|
||||||
|
|
||||||
# Initialize pygame
|
|
||||||
pygame.init()
|
|
||||||
|
|
||||||
# Set the HEIGHT and WIDTH of the screen
|
# Set the HEIGHT and WIDTH of the screen
|
||||||
WINDOW_SIZE = [980, 980]
|
WINDOW_SIZE = [980, 980]
|
||||||
screen = pygame.display.set_mode(WINDOW_SIZE)
|
screen = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
@ -78,12 +93,26 @@ done = False
|
|||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
smieciarka = Smieciarka(10, 10)
|
smieciarka = Smieciarka(10, 10)
|
||||||
|
kontener_plastik = Kontener(0, 0)
|
||||||
|
kontener_plastik.image = pygame.image.load("pojemnik_plastik.png")
|
||||||
|
kontener_metal = Kontener(0, 4)
|
||||||
|
kontener_metal.image = pygame.image.load("pojemnik_metal.png")
|
||||||
|
kontener_organiczne = Kontener(2, 2)
|
||||||
|
kontener_organiczne.image = pygame.image.load("pojemnik_organiczne.png")
|
||||||
|
kontener_papier = Kontener(4, 0)
|
||||||
|
kontener_papier.image = pygame.image.load("pojemnik_papier.png")
|
||||||
|
kontener_szklo = Kontener(4, 4)
|
||||||
|
kontener_szklo.image = pygame.image.load("pojemnik_szklo.png")
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
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(smieciarka)
|
all_sprites_list.add(kontener_plastik, kontener_metal,
|
||||||
|
kontener_organiczne, kontener_papier, kontener_szklo, smieciarka)
|
||||||
|
|
||||||
# -------- Main Program Loop -----------
|
# -------- Main Program Loop -----------
|
||||||
while not done:
|
while not done:
|
||||||
@ -115,15 +144,16 @@ while not done:
|
|||||||
# Draw the grid
|
# Draw the grid
|
||||||
for row in range(15):
|
for row in range(15):
|
||||||
for column in range(15):
|
for column in range(15):
|
||||||
color = WHITE
|
color = GREY
|
||||||
if grid[row][column] == 1:
|
# if grid[row][column] == 1:
|
||||||
color = BLUE
|
# color = BLUE
|
||||||
pygame.draw.rect(screen,
|
pygame.draw.rect(screen,
|
||||||
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("wysypisko.jpg"), (5, 5))
|
||||||
all_sprites_list.draw(screen)
|
all_sprites_list.draw(screen)
|
||||||
|
|
||||||
# Limit to 60 frames per second
|
# Limit to 60 frames per second
|
||||||
|
BIN
pojemnik_metal.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
pojemnik_organiczne.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
pojemnik_papier.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
pojemnik_plastik.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
pojemnik_szklo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
smieciarka.png
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 4.2 KiB |
BIN
wysypisko.jpg
Normal file
After Width: | Height: | Size: 32 KiB |