SZI-Smieciarka/modele.py

95 lines
2.7 KiB
Python
Raw Normal View History

2020-03-29 16:12:46 +02:00
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
2020-03-29 21:02:00 +02:00
# kolory
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
GREY = (128, 128, 128)
2020-03-29 16:12:46 +02:00
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)
2020-03-29 17:27:02 +02:00
self.image = pygame.image.__class__
2020-03-29 16:12:46 +02:00
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y + MARGIN,
WIDTH, HEIGHT)
2020-03-29 21:02:00 +02:00
def setImage(self, image):
2020-03-29 17:27:02 +02:00
self.image = image
2020-03-29 16:12:46 +02:00
class Kratka(pygame.sprite.Sprite):
2020-03-29 21:02:00 +02:00
def __init__(self, poz_x, poz_y):
2020-03-29 16:12:46 +02:00
self.pozX = poz_x
self.pozY = poz_y
2020-03-29 21:02:00 +02:00
self.jestSmieciarka = False
self.jestKontenerem = False
self.jestWysypiskiem = False
self.kolor = GREY
2020-03-29 16:12:46 +02:00
pygame.sprite.Sprite.__init__(self)
2020-03-29 17:27:02 +02:00
self.image = pygame.image.__class__
2020-03-29 21:02:00 +02:00
self.rect = pygame.Rect(self.pozX * WIDTH + MARGIN * self.pozX + MARGIN,
self.pozY * HEIGHT + MARGIN * self.pozY + MARGIN,
2020-03-29 16:12:46 +02:00
WIDTH, HEIGHT)
def setImage(self, image):
self.image = image
2020-03-29 19:59:24 +02:00
2020-03-29 21:02:00 +02:00
def setJestSmieciarka(self, bool):
self.jestSmieciarka = bool
def setJestKontenerem(self, bool):
self.jestKontenerem = bool
def setJestWysypiskiem(self, bool):
self.jestWysypiskiem = bool
def setKolor(self,kolor):
self.kolor = kolor