dodano wysypisko

This commit is contained in:
s444349 2020-03-29 05:01:12 +02:00
parent 8ecd8d3af6
commit ba52a72fd9
7 changed files with 31 additions and 9 deletions

38
game.py
View File

@ -1,5 +1,6 @@
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):
@ -7,7 +8,8 @@ class Smieciarka(pygame.sprite.Sprite):
self.y = y self.y = y
self.image = pygame.image.load('smieciarka.png') self.image = pygame.image.load('smieciarka.png')
pygame.sprite.Sprite.__init__(self) 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): def w_lewo(self):
if self.x > 0: if self.x > 0:
@ -32,12 +34,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
@ -60,9 +72,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)
@ -77,12 +86,24 @@ 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:
@ -114,15 +135,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

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
pojemnik_organiczne.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
pojemnik_papier.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
pojemnik_plastik.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
pojemnik_szklo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
wysypisko.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB