import pygame import random class Tractor: def __init__(self, parent_screen, cell_size): self.parent_screen = parent_screen self.lastVisitedBlocks = [] # tractor stores last 3 visited blocks self.up = pygame.image.load(r'resources/up.png').convert_alpha() self.down = pygame.image.load(r'resources/down.png').convert_alpha() self.left = pygame.image.load(r'resources/left.png').convert_alpha() self.right = pygame.image.load(r'resources/right.png').convert_alpha() self.up = pygame.transform.scale(self.up, (cell_size+2, cell_size)) self.down = pygame.transform.scale(self.down, (cell_size, cell_size+2)) self.left = pygame.transform.scale(self.left, (cell_size+2, cell_size+2)) self.right = pygame.transform.scale(self.right, (cell_size+4, cell_size+1)) self.x = cell_size*2 # to-check: start pos may be written explicit self.y = cell_size*2 #self.pos = Vector2(self.x, self.y) self.angle = 180 self.direction = 'up' self.image = self.down self.step = 0 self.lastVisitedBlocks = [] # as tractor moves it stores last 3 coordinates def draw(self): self.parent_screen.blit(self.image, (self.x, self.y)) # rotate tractor def move(self, direction, cell_size, cell_number): if direction == 'move': if self.angle == 0 and self.y != 0: self.y -= cell_size if self.angle == 90 and self.x != (cell_number-1)*cell_size: self.x += cell_size if self.angle == 180 and self.y != (cell_number-1)*cell_size: self.y += cell_size if self.angle == 270 and self.x != 0: self.x -= cell_size if direction == 'right': self.angle += 90 if self.angle == 360: self.angle = 0 if direction == 'left': self.angle -= 90 if self.angle == -90: self.angle = 270 if self.angle == 0: self.image = self.up if self.angle == 90: self.image = self.right if self.angle == 180: self.image = self.down if self.angle == 270: self.image = self.left self.step = self.step + 1 print(self.x, self.y) print(self.step) def water(self, body_before, body_after, cell_size): self.pos = [self.x/cell_size, self.y/cell_size] if self.pos in body_before: body_before.remove(self.pos) body_after.append(self.pos) print('HERE!') #print(body) def put_seed(self, body, seed_body, cell_size): #self.step = 0 self.pos = [self.x/cell_size, self.y/cell_size] if self.pos in body: #body.remove(self.pos) seed_body.append(self.pos) print('HERE IS THE SEED!') def harvest(self, seed_body, wheat_body, cell_size): self.pos = [self.x/cell_size, self.y/cell_size] if self.pos in seed_body: seed_body.remove(self.pos) wheat_body.append(self.pos) print('HERE IS THE WHEAT!') def walk(self): choice = ['up', 'down', 'left', 'right'] if self.x == 450: choice.pop(3) if self.x == 0: choice.pop(2) if self.y == 0: choice.pop(0) if self.y == 450: choice.pop(1) self.direction = random.choice(choice) self.move(self.direction)