SzybciorSmartTraktor/agent.py
s464852 7eae2b25c2 Add new methods to agent
TO DO: add irrigation, fertelization etc.
2022-03-24 15:13:59 +01:00

47 lines
1.3 KiB
Python

import pygame
import settings
class Instance:
def __init__(self, tank_capacity):
size = settings.Field.size
self.rect = pygame.Rect(0, 0, size(), size())
self.action = ''
self.tank_capacity = tank_capacity
def coordinates(self):
return {
'x': self.x(),
'y': self.y()
}
def x(self):
return int(self.rect.x / settings.Field.size())
def y(self):
return int(self.rect.y / settings.Field.size())
def get_tank_capacity(self):
return self.tank_capacity
def set_tank_capacity(self, fuel_units):
self.tank_capacity = fuel_units
def move(self):
key_pressed = pygame.key.get_pressed()
height = settings.Pygame.height()
width = settings.Pygame.width()
tile_size = settings.Field.size()
if key_pressed[pygame.K_LEFT] and self.rect.x > 0:
self.rect.x -= tile_size
elif key_pressed[pygame.K_RIGHT] and self.rect.x < width - tile_size:
self.rect.x += tile_size
elif key_pressed[pygame.K_UP] and self.rect.y > 0:
self.rect.y -= tile_size
elif key_pressed[pygame.K_DOWN] and self.rect.y < height - tile_size:
self.rect.y += tile_size
elif key_pressed[pygame.K_SPACE]:
return 'open_window'
return 'none'