import pygame import settings class Instance: def __init__(self, tank_capacity, direction): size = settings.Field.size self.rect = pygame.Rect(0, 0, size(), size()) self.action = '' self.tank_capacity = tank_capacity self.direction = direction 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_UP] and self.direction == 'west' and self.rect.x > 0: self.rect.x -= tile_size elif key_pressed[pygame.K_UP] and self.direction == 'east' and self.rect.x < width - tile_size: self.rect.x += tile_size elif key_pressed[pygame.K_UP] and self.direction == 'north' and self.rect.y > 0: self.rect.y -= tile_size elif key_pressed[pygame.K_UP] and self.direction == 'south' and self.rect.y < height - tile_size: self.rect.y += tile_size elif key_pressed[pygame.K_SPACE]: return 'open_window' return 'none' def rotate(self): key_pressed = pygame.key.get_pressed() if key_pressed[pygame.K_LEFT] and self.direction == 'east': self.direction = 'north' elif key_pressed[pygame.K_LEFT] and self.direction == 'north': self.direction = 'west' elif key_pressed[pygame.K_LEFT] and self.direction == 'west': self.direction = 'south' elif key_pressed[pygame.K_LEFT] and self.direction == 'south': self.direction = 'east' elif key_pressed[pygame.K_RIGHT] and self.direction == 'north': self.direction = 'east' elif key_pressed[pygame.K_RIGHT] and self.direction == 'west': self.direction = 'north' elif key_pressed[pygame.K_RIGHT] and self.direction == 'south': self.direction = 'west' elif key_pressed[pygame.K_RIGHT] and self.direction == 'east': self.direction = 'south' return 'none'