master #1

Merged
s444427 merged 39 commits from s452664/Sztuczna_Inteligencja-projekt:master into master 2021-06-03 16:39:57 +02:00
Showing only changes of commit 3067eda937 - Show all commits

View File

@ -17,16 +17,19 @@ from colors import *
from sprites import * from sprites import *
class Tractor(pygame.sprite.Sprite): class Tractor(pygame.sprite.Sprite):
def __init__(self, field): def __init__(self, field, position):
super(Tractor, self).__init__() super(Tractor, self).__init__()
self.surf = pygame.Surface((WIDTH, HEIGHT)) self.surf = pygame.Surface((WIDTH, HEIGHT))
self.surf = tractor_img_0 self.surf = tractor_img_0
self.position = field.position self.position = position
self.field = field
self.rect = self.surf.get_rect( self.rect = self.surf.get_rect(
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN)) topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
self.direction = [1, 0] self.direction = [1, 0]
self.field[self.position[0]][self.position[1]].tractor_there = True
def move(self): 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.rect.move_ip(self.direction[0]*(WIDTH + MARGIN), self.direction[1]*(HEIGHT + MARGIN))
self.position[0] += self.direction[0] self.position[0] += self.direction[0]
self.position[1] += self.direction[1] self.position[1] += self.direction[1]
@ -48,7 +51,9 @@ class Tractor(pygame.sprite.Sprite):
if self.rect.right > SCREEN_WIDTH-MARGIN: if self.rect.right > SCREEN_WIDTH-MARGIN:
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): def rotate_right(self):
if self.direction == [1, 0]: if self.direction == [1, 0]:
self.direction = [0, 1] self.direction = [0, 1]