diff --git a/source/__pycache__/crop_protection_product.cpython-311.pyc b/source/__pycache__/crop_protection_product.cpython-311.pyc index d4e10b4..6a05fd6 100644 Binary files a/source/__pycache__/crop_protection_product.cpython-311.pyc and b/source/__pycache__/crop_protection_product.cpython-311.pyc differ diff --git a/source/__pycache__/ground.cpython-311.pyc b/source/__pycache__/ground.cpython-311.pyc index 440582a..adf86d0 100644 Binary files a/source/__pycache__/ground.cpython-311.pyc and b/source/__pycache__/ground.cpython-311.pyc differ diff --git a/source/__pycache__/plant.cpython-311.pyc b/source/__pycache__/plant.cpython-311.pyc index 4dca0be..3976f89 100644 Binary files a/source/__pycache__/plant.cpython-311.pyc and b/source/__pycache__/plant.cpython-311.pyc differ diff --git a/source/__pycache__/tile.cpython-311.pyc b/source/__pycache__/tile.cpython-311.pyc index afdea50..415b652 100644 Binary files a/source/__pycache__/tile.cpython-311.pyc and b/source/__pycache__/tile.cpython-311.pyc differ diff --git a/source/area/__pycache__/__init__.cpython-311.pyc b/source/area/__pycache__/__init__.cpython-311.pyc index a319c59..1de898d 100644 Binary files a/source/area/__pycache__/__init__.cpython-311.pyc and b/source/area/__pycache__/__init__.cpython-311.pyc differ diff --git a/source/area/__pycache__/constants.cpython-311.pyc b/source/area/__pycache__/constants.cpython-311.pyc index fc5dca7..170b454 100644 Binary files a/source/area/__pycache__/constants.cpython-311.pyc and b/source/area/__pycache__/constants.cpython-311.pyc differ diff --git a/source/area/__pycache__/field.cpython-311.pyc b/source/area/__pycache__/field.cpython-311.pyc index e78f0fe..3a7109f 100644 Binary files a/source/area/__pycache__/field.cpython-311.pyc and b/source/area/__pycache__/field.cpython-311.pyc differ diff --git a/source/area/__pycache__/tractor.cpython-311.pyc b/source/area/__pycache__/tractor.cpython-311.pyc index d57462a..36769f1 100644 Binary files a/source/area/__pycache__/tractor.cpython-311.pyc and b/source/area/__pycache__/tractor.cpython-311.pyc differ diff --git a/source/area/constants.py b/source/area/constants.py index 1aff5be..c0326a0 100644 --- a/source/area/constants.py +++ b/source/area/constants.py @@ -12,6 +12,9 @@ GROUND = "" # path to ground image GREY = (20, 17, 17, 255) - +DIRECTION_NORTH = 1 +DIRECTION_EAST = 2 +DIRECTION_SOUTH = 3 +DIRECTION_WEST = 4 diff --git a/source/area/tractor.py b/source/area/tractor.py index dc27ee8..1dab655 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -1,9 +1,13 @@ from crop_protection_product import CropProtectionProduct +from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH +from area.field import fieldX,fieldY +import pygame class Tractor: x = None y = None + direction = None #direction takes values in the range of 1 to 4 image = None cypermetryna = CropProtectionProduct("pests", "cereal") diflufenikan = CropProtectionProduct("weeds", "cereal") @@ -13,10 +17,12 @@ class Tractor: metazachlor = CropProtectionProduct("weeds", "vegetable") # etc - def __init__(self, x, y): + def __init__(self, x, y, direction): self.x = x self.y = y - self.image = 'resources/images/tractor.png' + self.direction = direction + self.image = pygame.image.load('resources/images/tractor.png').convert_alpha() + def work_on_field(self, tile, ground, plant1): if plant1 is None: @@ -58,3 +64,43 @@ class Tractor: if ground.nutrients_level < plant1.nutrients_requirements: ground.nutrients_level += 20 print("Tractor added some nutrients") + + + + def move(self): + if self.direction == DIRECTION_EAST: + self.x = self.x + TILE_SIZE + + elif self.direction == DIRECTION_WEST: + self.x = self.x - TILE_SIZE + + elif self.direction == DIRECTION_NORTH: + self.y = self.y - TILE_SIZE + + elif self.direction == DIRECTION_SOUTH: + self.y = self.y + TILE_SIZE + + + def rotate_to_right(self): + if self.direction == 4: + self.direction = 1 + else: + self.direction += 1 + self.image = pygame.transform.rotate(self.image, -90) + + + def rotate_to_left(self): + if self.direction == 1: + self.direction = 4 + else: + self.direction -= 1 + self.image = pygame.transform.rotate(self.image, 90) + + + def draw_tractor(self, win): + + imageTractor = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE)) + self.x += fieldX + self.y += fieldY + win.blit(imageTractor, (self.x, self.y)) + pygame.display.flip() \ No newline at end of file diff --git a/source/main.py b/source/main.py index 2dac1b5..4f62a5c 100644 --- a/source/main.py +++ b/source/main.py @@ -2,7 +2,7 @@ import pygame import time import random -from area.constants import WIDTH, HEIGHT +from area.constants import WIDTH, HEIGHT, TILE_SIZE from area.field import drawWindow from area.tractor import Tractor from area.field import tiles @@ -16,6 +16,8 @@ def main(): run = True window = drawWindow(WIN) pygame.display.update() + + while run: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -28,12 +30,19 @@ def main(): d1 = Dirt(random.randint(1, 100), random.randint(1,100)) d1.pests_and_weeds() tile1.ground=d1 - t1 = Tractor(10, 10) - t1.work_on_field(tile1, d1, p1) + + tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 2) + tractor.rotate_to_right() + tractor.move() + tractor.draw_tractor(WIN) + + pygame.display.update() + tractor.work_on_field(tile1, d1, p1) time.sleep(3) print("\n") -# in loop move tractor +# in loop move tractor: + main()