2022-03-11 03:02:29 +01:00
|
|
|
import pygame
|
|
|
|
import settings
|
|
|
|
|
|
|
|
|
|
|
|
class Instance:
|
2022-03-24 15:13:59 +01:00
|
|
|
def __init__(self, tank_capacity):
|
2022-03-11 03:02:29 +01:00
|
|
|
size = settings.Field.size
|
|
|
|
self.rect = pygame.Rect(0, 0, size(), size())
|
|
|
|
self.action = ''
|
2022-03-24 15:13:59 +01:00
|
|
|
self.tank_capacity = tank_capacity
|
2022-03-11 03:02:29 +01:00
|
|
|
|
2022-03-11 03:34:20 +01:00
|
|
|
def coordinates(self):
|
2022-03-11 03:02:29 +01:00
|
|
|
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())
|
2022-03-24 15:13:59 +01:00
|
|
|
|
|
|
|
def get_tank_capacity(self):
|
|
|
|
return self.tank_capacity
|
2022-03-11 03:02:29 +01:00
|
|
|
|
2022-03-24 15:13:59 +01:00
|
|
|
def set_tank_capacity(self, fuel_units):
|
|
|
|
self.tank_capacity = fuel_units
|
|
|
|
|
2022-03-11 03:02:29 +01:00
|
|
|
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]:
|
2022-03-11 03:34:20 +01:00
|
|
|
return 'open_window'
|
|
|
|
return 'none'
|