From 3067eda937ca502507d2696e92a3bf5355bd4d32 Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Thu, 3 Jun 2021 16:13:29 +0200 Subject: [PATCH] Zaktualizuj 'tractor.py' --- tractor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tractor.py b/tractor.py index 6716e0c..8ba6bc4 100644 --- a/tractor.py +++ b/tractor.py @@ -17,16 +17,19 @@ from colors import * from sprites import * class Tractor(pygame.sprite.Sprite): - def __init__(self, field): + def __init__(self, field, position): super(Tractor, self).__init__() self.surf = pygame.Surface((WIDTH, HEIGHT)) self.surf = tractor_img_0 - self.position = field.position + self.position = position + self.field = field self.rect = self.surf.get_rect( topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN)) self.direction = [1, 0] + self.field[self.position[0]][self.position[1]].tractor_there = True def move(self): + self.field[self.position[0]][self.position[1]].tractor_there = False self.rect.move_ip(self.direction[0]*(WIDTH + MARGIN), self.direction[1]*(HEIGHT + MARGIN)) self.position[0] += self.direction[0] self.position[1] += self.direction[1] @@ -48,7 +51,9 @@ class Tractor(pygame.sprite.Sprite): if self.rect.right > SCREEN_WIDTH-MARGIN: self.rect.right = SCREEN_WIDTH-MARGIN + self.field[self.position[0]][self.position[1]].tractor_there = True + def rotate_right(self): if self.direction == [1, 0]: self.direction = [0, 1]