sprawdzanie czy jest przeszkoda

This commit is contained in:
s444349 2020-04-03 16:27:21 +02:00
parent a7d4492559
commit 37931930a6

View File

@ -1,4 +1,5 @@
import pygame import pygame
import game
# This sets the WIDTH and HEIGHT of each grid location # This sets the WIDTH and HEIGHT of each grid location
WIDTH = 60 WIDTH = 60
@ -27,7 +28,7 @@ class Smieciarka(pygame.sprite.Sprite):
HEIGHT) HEIGHT)
def w_lewo(self): def w_lewo(self):
if self.x > 0: if self.x > 0 or game.plansza[self.x - 1, self.y].jestPrzeszkoda is not True:
self.x -= 1 self.x -= 1
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
if self.ruch == 2: if self.ruch == 2:
@ -36,7 +37,7 @@ class Smieciarka(pygame.sprite.Sprite):
self.ruch = 1 self.ruch = 1
def w_prawo(self): def w_prawo(self):
if self.x < 14: if self.x < 14 or game.plansza[self.x + 1, self.y].jestPrzeszkoda is not True:
self.x += 1 self.x += 1
self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN
if self.ruch == 1: if self.ruch == 1:
@ -44,12 +45,12 @@ class Smieciarka(pygame.sprite.Sprite):
self.ruch = 2 self.ruch = 2
def w_gore(self): def w_gore(self):
if self.y > 0: if self.y > 0 or game.plansza[self.x, self.y - 1].jestPrzeszkoda is not True:
self.y -= 1 self.y -= 1
self.rect.y = self.y * HEIGHT + self.y * MARGIN self.rect.y = self.y * HEIGHT + self.y * MARGIN
def w_dol(self): def w_dol(self):
if self.y < 14: if self.y < 14 or game.plansza[self.x, self.y + 1].jestPrzeszkoda is not True:
self.y += 1 self.y += 1
self.rect.y = self.y * HEIGHT + self.y * MARGIN self.rect.y = self.y * HEIGHT + self.y * MARGIN
@ -71,9 +72,9 @@ class Kratka(pygame.sprite.Sprite):
def __init__(self, poz_x, poz_y): def __init__(self, poz_x, poz_y):
self.pozX = poz_x self.pozX = poz_x
self.pozY = poz_y self.pozY = poz_y
self.jestSmieciarka = False
self.jestKontenerem = False self.jestKontenerem = False
self.jestWysypiskiem = False self.jestWysypiskiem = False
self.jestPrzeszkoda = False
self.kolor = GREY self.kolor = GREY
pygame.sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.__class__ self.image = pygame.image.__class__
@ -87,6 +88,9 @@ class Kratka(pygame.sprite.Sprite):
def setJestSmieciarka(self, bool): def setJestSmieciarka(self, bool):
self.jestSmieciarka = bool self.jestSmieciarka = bool
def setJestPrzeszkoda(self, bool):
self.jestPrzeszkoda = bool
def setJestKontenerem(self, bool): def setJestKontenerem(self, bool):
self.jestKontenerem = bool self.jestKontenerem = bool