120 lines
3.5 KiB
Python
120 lines
3.5 KiB
Python
import pygame
|
|
import game
|
|
import random
|
|
|
|
# wysokosc i szerokosc kazdej kratki
|
|
WIDTH = 60
|
|
HEIGHT = 60
|
|
|
|
# margines pomiedzy kratkami
|
|
MARGIN = 5
|
|
|
|
# kolory
|
|
BLACK = (0, 0, 0)
|
|
WHITE = (255, 255, 255)
|
|
GREEN = (0, 255, 0)
|
|
RED = (255, 0, 0)
|
|
BLUE = (40, 50, 200)
|
|
GREY = (128, 128, 128)
|
|
|
|
|
|
class Smieciarka(pygame.sprite.Sprite):
|
|
def __init__(self, x, y):
|
|
self.x = x
|
|
self.y = y
|
|
self.image = pygame.image.load('resources/plansza/smieciarka.png')
|
|
self.obraz = None
|
|
self.ruch = 1
|
|
self.plansza = None
|
|
self.obiekty = None
|
|
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 setObraz(self, obraz):
|
|
self.obraz = obraz
|
|
|
|
def rand_move(self):
|
|
rand_int = random.randint(0, 3)
|
|
if rand_int == 0:
|
|
self.w_lewo()
|
|
elif rand_int == 1:
|
|
self.w_prawo()
|
|
elif rand_int == 2:
|
|
self.w_gore()
|
|
elif rand_int == 3:
|
|
self.w_dol()
|
|
|
|
def w_lewo(self):
|
|
if self.x > 0:
|
|
if self.ruch == 2:
|
|
self.image = pygame.image.load(
|
|
'resources/plansza/smieciarka.png')
|
|
self.ruch = 1
|
|
|
|
self.plansza[self.x - 1, self.y].setKolor(BLUE)
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
self.rect.x -= 5
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
self.x -= 1
|
|
|
|
def w_prawo(self):
|
|
if self.x < 14:
|
|
if self.ruch == 1:
|
|
self.image = pygame.transform.flip(self.image, True, False)
|
|
self.ruch = 2
|
|
|
|
self.plansza[self.x + 1, self.y].setKolor(BLUE)
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
self.rect.x += 5
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
self.x += 1
|
|
|
|
def w_gore(self):
|
|
if self.y > 0:
|
|
self.plansza[self.x, self.y - 1].setKolor(BLUE)
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
self.rect.y -= 5
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
self.y -= 1
|
|
|
|
def w_dol(self):
|
|
if self.y < 14:
|
|
self.plansza[self.x, self.y + 1].setKolor(BLUE)
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
self.rect.y += 5
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
self.y += 1
|
|
|
|
def setPlansza(self, plansza):
|
|
self.plansza = plansza
|
|
|
|
def setObiekty(self, obiekty):
|
|
self.obiekty = obiekty
|
|
|
|
|
|
class Kratka(pygame.sprite.Sprite):
|
|
def __init__(self, poz_x, poz_y):
|
|
self.pozX = poz_x
|
|
self.pozY = poz_y
|
|
self.kolor = GREY
|
|
self.obiekt = None
|
|
pygame.sprite.Sprite.__init__(self)
|
|
self.image = pygame.image.__class__
|
|
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
|
|
|
|
def setObiekt(self, obiekt):
|
|
self.obiekt = obiekt
|
|
|
|
def setKolor(self, kolor):
|
|
self.kolor = kolor
|