merge
50
game.py
@ -1,26 +1,34 @@
|
||||
import pygame
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
class Smieciarka(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.image = pygame.image.load('smieciarka.png')
|
||||
self.ruch = 0
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x +
|
||||
MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH, HEIGHT)
|
||||
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH,
|
||||
HEIGHT)
|
||||
|
||||
def w_lewo(self):
|
||||
if self.x > 0:
|
||||
self.x -= 1
|
||||
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
|
||||
if self.ruch == 2:
|
||||
self.image = pygame.image.load('smieciarka.png')
|
||||
self.ruch = 1
|
||||
|
||||
def w_prawo(self):
|
||||
if self.x < 14:
|
||||
self.x += 1
|
||||
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):
|
||||
if self.y > 0:
|
||||
@ -33,12 +41,22 @@ class Smieciarka(pygame.sprite.Sprite):
|
||||
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
|
||||
BLACK = (0, 0, 0)
|
||||
WHITE = (255, 255, 255)
|
||||
GREEN = (0, 255, 0)
|
||||
RED = (255, 0, 0)
|
||||
BLUE = (0, 0, 255)
|
||||
GREY = (128, 128, 128)
|
||||
|
||||
# This sets the WIDTH and HEIGHT of each grid location
|
||||
WIDTH = 60
|
||||
@ -61,9 +79,6 @@ for row in range(100):
|
||||
# column numbers start at zero.)
|
||||
grid[0][0] = 1
|
||||
|
||||
# Initialize pygame
|
||||
pygame.init()
|
||||
|
||||
# Set the HEIGHT and WIDTH of the screen
|
||||
WINDOW_SIZE = [980, 980]
|
||||
screen = pygame.display.set_mode(WINDOW_SIZE)
|
||||
@ -78,12 +93,26 @@ done = False
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
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()
|
||||
all_sprites_list = pygame.sprite.Group()
|
||||
|
||||
kontener_list.add(kontener_plastik, kontener_metal,
|
||||
kontener_organiczne, kontener_papier, kontener_szklo)
|
||||
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 -----------
|
||||
while not done:
|
||||
@ -115,15 +144,16 @@ while not done:
|
||||
# Draw the grid
|
||||
for row in range(15):
|
||||
for column in range(15):
|
||||
color = WHITE
|
||||
if grid[row][column] == 1:
|
||||
color = BLUE
|
||||
color = GREY
|
||||
# if grid[row][column] == 1:
|
||||
# color = BLUE
|
||||
pygame.draw.rect(screen,
|
||||
color,
|
||||
[(MARGIN + WIDTH) * column + MARGIN,
|
||||
(MARGIN + HEIGHT) * row + MARGIN,
|
||||
WIDTH,
|
||||
HEIGHT])
|
||||
screen.blit(pygame.image.load("wysypisko.jpg"), (5, 5))
|
||||
all_sprites_list.draw(screen)
|
||||
|
||||
# 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 |