dodane pliki main i modele
This commit is contained in:
parent
a9aac81db6
commit
1cc7c44a0b
BIN
__pycache__/game.cpython-37.pyc
Normal file
BIN
__pycache__/game.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/modele.cpython-37.pyc
Normal file
BIN
__pycache__/modele.cpython-37.pyc
Normal file
Binary file not shown.
109
game.py
109
game.py
@ -1,54 +1,7 @@
|
||||
import pygame
|
||||
import modele
|
||||
|
||||
pygame.init()
|
||||
|
||||
class Smieciarka(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.image = pygame.image.load('resources/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)
|
||||
|
||||
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('resources/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
|
||||
if self.ruch == 1:
|
||||
self.image = pygame.transform.flip(smieciarka.image, True, False)
|
||||
self.ruch = 2
|
||||
|
||||
def w_gore(self):
|
||||
if self.y > 0:
|
||||
self.y -= 1
|
||||
self.rect.y = self.y * HEIGHT + self.y * MARGIN
|
||||
|
||||
def w_dol(self):
|
||||
if self.y < 14:
|
||||
self.y += 1
|
||||
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
|
||||
# kolory
|
||||
BLACK = (0, 0, 0)
|
||||
WHITE = (255, 255, 255)
|
||||
GREEN = (0, 255, 0)
|
||||
@ -56,13 +9,45 @@ RED = (255, 0, 0)
|
||||
BLUE = (0, 0, 255)
|
||||
GREY = (128, 128, 128)
|
||||
|
||||
# This sets the WIDTH and HEIGHT of each grid location
|
||||
# wysokosc i szerokosc kazdej kratki
|
||||
WIDTH = 60
|
||||
HEIGHT = 60
|
||||
|
||||
# This sets the margin between each cell
|
||||
# margines pomiedzy kratkami
|
||||
MARGIN = 5
|
||||
|
||||
# rozmiar okna
|
||||
WINDOW_SIZE = [980, 980]
|
||||
|
||||
|
||||
def game():
|
||||
|
||||
# TWORZENIE OBIEKTOW
|
||||
smieciarka = modele.Smieciarka(10, 10)
|
||||
kontener_plastik = modele.Kontener(0, 0)
|
||||
kontener_plastik.image = pygame.image.load("resources/pojemnik_plastik.png")
|
||||
kontener_metal = modele.Kontener(0, 4)
|
||||
kontener_metal.image = pygame.image.load("resources/pojemnik_metal.png")
|
||||
kontener_organiczne = modele.Kontener(2, 2)
|
||||
kontener_organiczne.image = pygame.image.load("resources/pojemnik_organiczne.png")
|
||||
kontener_papier = modele.Kontener(4, 0)
|
||||
kontener_papier.image = pygame.image.load("resources/pojemnik_papier.png")
|
||||
kontener_szklo = modele.Kontener(4, 4)
|
||||
kontener_szklo.image = pygame.image.load("resources/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(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo,
|
||||
smieciarka)
|
||||
|
||||
pygame.init()
|
||||
|
||||
# Create a 2 dimensional array. A two dimensional
|
||||
# array is simply a list of lists.
|
||||
grid = []
|
||||
@ -73,12 +58,11 @@ for row in range(100):
|
||||
for column in range(100):
|
||||
grid[row].append(0) # Append a cell
|
||||
|
||||
# Set row 1, cell 5 to one. (Remember rows and
|
||||
# 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
|
||||
WINDOW_SIZE = [980, 980]
|
||||
screen = pygame.display.set_mode(WINDOW_SIZE)
|
||||
|
||||
# Set title of screen
|
||||
@ -90,25 +74,6 @@ done = False
|
||||
# Used to manage how fast the screen updates
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
smieciarka = Smieciarka(10, 10)
|
||||
kontener_plastik = Kontener(0, 0)
|
||||
kontener_plastik.image = pygame.image.load("resources/pojemnik_plastik.png")
|
||||
kontener_metal = Kontener(0, 4)
|
||||
kontener_metal.image = pygame.image.load("resources/pojemnik_metal.png")
|
||||
kontener_organiczne = Kontener(2, 2)
|
||||
kontener_organiczne.image = pygame.image.load("resources/pojemnik_organiczne.png")
|
||||
kontener_papier = Kontener(4, 0)
|
||||
kontener_papier.image = pygame.image.load("resources/pojemnik_papier.png")
|
||||
kontener_szklo = Kontener(4, 4)
|
||||
kontener_szklo.image = pygame.image.load("resources/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(kontener_plastik, kontener_metal, kontener_organiczne, kontener_papier, kontener_szklo, smieciarka)
|
||||
|
||||
# -------- Main Program Loop -----------
|
||||
while not done:
|
||||
|
10
main.py
Normal file
10
main.py
Normal file
@ -0,0 +1,10 @@
|
||||
import pygame
|
||||
import game
|
||||
|
||||
|
||||
def main():
|
||||
print("poczatek programu")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
67
modele.py
Normal file
67
modele.py
Normal file
@ -0,0 +1,67 @@
|
||||
import pygame
|
||||
|
||||
# This sets the WIDTH and HEIGHT of each grid location
|
||||
WIDTH = 60
|
||||
HEIGHT = 60
|
||||
|
||||
# This sets the margin between each cell
|
||||
MARGIN = 5
|
||||
|
||||
|
||||
class Smieciarka(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.image = pygame.image.load('resources/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)
|
||||
|
||||
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('resources/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
|
||||
if self.ruch == 1:
|
||||
self.image = pygame.transform.flip(self.image, True, False)
|
||||
self.ruch = 2
|
||||
|
||||
def w_gore(self):
|
||||
if self.y > 0:
|
||||
self.y -= 1
|
||||
self.rect.y = self.y * HEIGHT + self.y * MARGIN
|
||||
|
||||
def w_dol(self):
|
||||
if self.y < 14:
|
||||
self.y += 1
|
||||
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)
|
||||
|
||||
|
||||
class Kratka(pygame.sprite.Sprite):
|
||||
def __init__(self, poz_x, poz_y):
|
||||
self.pozX = poz_x
|
||||
self.pozY = poz_y
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.image.__init__()
|
||||
self.rect = pygame.Rect(self.pozX * WIDTH + MARGIN * self.pozX + MARGIN, self.pozY * HEIGHT + MARGIN * self.pozY + MARGIN,
|
||||
WIDTH, HEIGHT)
|
||||
|
||||
def setImage(self, image):
|
||||
self.image = image
|
Loading…
Reference in New Issue
Block a user