2024-03-23 22:54:51 +01:00
|
|
|
from crop_protection_product import CropProtectionProduct
|
2024-04-09 15:02:58 +02:00
|
|
|
from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH
|
|
|
|
from area.field import fieldX,fieldY
|
|
|
|
import pygame
|
2024-03-23 22:54:51 +01:00
|
|
|
|
|
|
|
|
2024-03-07 18:01:12 +01:00
|
|
|
class Tractor:
|
|
|
|
x = None
|
|
|
|
y = None
|
2024-04-09 15:02:58 +02:00
|
|
|
direction = None #direction takes values in the range of 1 to 4
|
2024-03-07 18:01:12 +01:00
|
|
|
image = None
|
2024-03-23 22:54:51 +01:00
|
|
|
cypermetryna = CropProtectionProduct("pests", "cereal")
|
|
|
|
diflufenikan = CropProtectionProduct("weeds", "cereal")
|
|
|
|
spirotetramat = CropProtectionProduct("pests", "fruit")
|
|
|
|
oksadiargyl = CropProtectionProduct("weeds", "fruit")
|
|
|
|
spinosad = CropProtectionProduct("pests", "vegetable")
|
|
|
|
metazachlor = CropProtectionProduct("weeds", "vegetable")
|
2024-03-07 18:01:12 +01:00
|
|
|
# etc
|
2024-03-23 22:54:51 +01:00
|
|
|
|
2024-04-09 15:02:58 +02:00
|
|
|
def __init__(self, x, y, direction):
|
2024-03-07 18:01:12 +01:00
|
|
|
self.x = x
|
|
|
|
self.y = y
|
2024-04-09 15:02:58 +02:00
|
|
|
self.direction = direction
|
|
|
|
self.image = pygame.image.load('resources/images/tractor.png').convert_alpha()
|
|
|
|
|
2024-03-22 22:14:05 +01:00
|
|
|
|
2024-03-23 22:54:51 +01:00
|
|
|
def work_on_field(self, tile, ground, plant1):
|
|
|
|
if plant1 is None:
|
|
|
|
tile.randomizeContent()
|
|
|
|
# sprobuj zasadzic cos
|
2024-03-25 01:02:03 +01:00
|
|
|
print("Tarctor planted something")
|
2024-03-23 22:54:51 +01:00
|
|
|
elif plant1.growth_level == 100:
|
|
|
|
tile.plant = None
|
2024-03-25 01:02:03 +01:00
|
|
|
ground.nutrients_level -= 40
|
|
|
|
ground.water_level -= 40
|
|
|
|
print("Tractor collected something")
|
2024-03-23 22:54:51 +01:00
|
|
|
else:
|
2024-03-25 01:02:03 +01:00
|
|
|
plant1.try_to_grow(50,50) #mozna dostosowac jeszcze
|
|
|
|
ground.nutrients_level -= 11
|
|
|
|
ground.water_level -= 11
|
2024-03-23 22:54:51 +01:00
|
|
|
if ground.pest:
|
2024-03-22 22:14:05 +01:00
|
|
|
# traktor pozbywa sie szkodnikow
|
2024-03-23 22:54:51 +01:00
|
|
|
if plant1.plant_type == self.cypermetryna.plant_type:
|
|
|
|
t = "Tractor used Cypermetryna"
|
|
|
|
elif plant1.plant_type == self.spirotetramat.plant_type:
|
|
|
|
t = "Tractor used Spirotetramat"
|
|
|
|
elif plant1.plant_type == self.spinosad.plant_type:
|
|
|
|
t = "Tractor used Spinosad"
|
|
|
|
print(t)
|
2024-03-22 22:14:05 +01:00
|
|
|
ground.pest = False
|
2024-03-23 22:54:51 +01:00
|
|
|
if ground.weed:
|
2024-03-22 22:14:05 +01:00
|
|
|
# traktor pozbywa się chwastow
|
2024-03-23 22:54:51 +01:00
|
|
|
if plant1.plant_type == self.diflufenikan.plant_type:
|
|
|
|
t = "Tractor used Diflufenikan"
|
|
|
|
elif plant1.plant_type == self.oksadiargyl.plant_type:
|
|
|
|
t = "Tractor used Oksadiargyl"
|
|
|
|
elif plant1.plant_type == self.metazachlor.plant_type:
|
|
|
|
t = "Tractor used Metazachlor"
|
|
|
|
print(t)
|
2024-03-22 22:14:05 +01:00
|
|
|
ground.weed = False
|
2024-03-25 01:02:03 +01:00
|
|
|
if ground.water_level < plant1.water_requirements:
|
|
|
|
ground.water_level += 20
|
|
|
|
print("Tractor watered the plant")
|
|
|
|
if ground.nutrients_level < plant1.nutrients_requirements:
|
|
|
|
ground.nutrients_level += 20
|
|
|
|
print("Tractor added some nutrients")
|
2024-04-09 15:02:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|