示例#1
0
    def __init__(self,
                 texture_name: str,
                 robustness: Robustness = 0,
                 position: Point = (0, 0),
                 id: Optional[int] = None):
        x, y = position
        filename = get_path_to_file(texture_name)
        super().__init__(filename, center_x=x, center_y=y)
        OwnedObject.__init__(self, owners=True)
        EventsCreator.__init__(self)
        self.object_name = texture_name

        GameObject.total_objects_count += 1
        if id is None:
            self.id = GameObject.total_objects_count
        else:
            self.id = id

        self._robustness = robustness  # used to determine if object makes a
        # tile not-walkable or can be destroyed by vehicle entering the MapTile

        self.is_updated = True
        self.is_rendered = True

        self.selective_spritelist: Optional[SelectiveSpriteList] = None
 def __init__(self,
              texture_name: str,
              x: int,
              y: int,
              name: Optional[str] = None,
              active: bool = True,
              visible: bool = True,
              parent: Optional[Hierarchical] = None,
              functions: Optional[Union[Callable, Tuple[Callable]]] = None,
              subgroup: Optional[int] = None,
              selectable_group: Optional[SelectableGroup] = None,
              color: Optional[Color] = None):
     super().__init__('',
                      x,
                      y,
                      name,
                      active,
                      visible,
                      parent,
                      functions,
                      subgroup=subgroup,
                      selectable_group=selectable_group)
     # we load 2 textures for button: normal and for 'highlighted' button:
     full_texture_name = get_path_to_file(texture_name)
     image = PIL.Image.open(full_texture_name)
     width, height = image.size[0] // 2, image.size[1]
     self.textures = [
         load_texture(full_texture_name, 0, 0, width, height),
         load_texture(full_texture_name, width, 0, width, height)
     ]
     self.set_texture(0)
     self.button_color = color
示例#3
0
    def __init__(self, width: int, height: int, update_rate: float):
        Window.__init__(self, width, height, update_rate=update_rate)
        self.set_fullscreen(FULL_SCREEN)
        self.set_caption(__title__)

        self.settings = Settings()  # shared with Game

        self.sound_player = AudioPlayer()

        self.save_manager = SaveManager('saved_games', 'scenarios')

        self._updated: List[Updateable] = []

        # Settings, gameobjects configs, game-progress data, etc.
        self.configs = read_csv_files('resources/configs')

        # views:
        self._current_view: Optional[LoadableWindowView] = None

        self.menu_view: Menu = Menu()
        self.game_view: Optional[Game] = None

        self.show_view(LoadingScreen(loaded_view=self.menu_view))

        # cursor-related:
        self.cursor = MouseCursor(self, get_path_to_file('normal.png'))
        # store viewport data to avoid redundant get_viewport() calls and call
        # get_viewport only when viewport is actually changed:
        self.current_viewport = self.get_viewport()

        # keyboard-related:
        self.keyboard = KeyboardHandler(window=self)
 def __init__(self,
              texture_name: str,
              x: int,
              y: int,
              name: Optional[str] = None,
              active: bool = True,
              visible: bool = True,
              parent: Optional[Hierarchical] = None,
              functions: Optional[Union[Callable, Tuple[Callable]]] = None,
              can_be_dragged: bool = False,
              subgroup: Optional[int] = None,
              selectable_group: Optional[SelectableGroup] = None):
     full_texture_name = get_path_to_file(
         name_to_texture_name(texture_name))
     super().__init__(full_texture_name, center_x=x, center_y=y)
     ToggledElement.__init__(self, active, visible)
     CursorInteractive.__init__(self,
                                can_be_dragged,
                                functions,
                                parent=parent)
     OwnedObject.__init__(self, owners=True)
     Selectable.__init__(self, selectable_group=selectable_group)
     self.name = name
     self.bundle = None
     self.subgroup = subgroup
     self.ui_spritelist = None
    def __init__(self,
                 texture_name: str,
                 x: int,
                 y: int,
                 text: str,
                 font_size: int = 10,
                 text_color: Color = WHITE,
                 name: Optional[str] = None,
                 active: bool = True,
                 visible: bool = True,
                 parent: Optional[Hierarchical] = None,
                 functions: Optional[Callable] = None,
                 ticked: bool = False,
                 variable: Tuple[object, str] = None,
                 subgroup: Optional[int] = None,
                 selectable_group: Optional[SelectableGroup] = None):
        """

        :param texture_name:
        :param x:
        :param y:
        :param name:
        :param active:
        :param visible:
        :param parent:
        :param function_on_right_click:
        :param functions:
        :param ticked:
        :param variable: Tuple[object, str] -- to bind a variable to this
        Checkbox you must pass a tuple which first element is an reference
        to the python object and second is a string name of this object
        attribute, e.g. (self, 'name_of_my_attribute').
        """
        super().__init__(texture_name,
                         x,
                         y,
                         name,
                         active,
                         visible,
                         parent,
                         functions,
                         subgroup=subgroup,
                         selectable_group=selectable_group)
        self.ticked = ticked
        self.variable = variable
        full_texture_name = get_path_to_file(texture_name)
        self.textures = [
            load_texture(full_texture_name, 0, 0, 30, 30),
            load_texture(full_texture_name, 30, 0, 30, 30)
        ]
        self.set_texture(int(self.ticked))
        self.text_label = UiTextLabel(x - int(len(text) * font_size * 0.45), y,
                                      text, font_size, text_color)
示例#6
0
 def _load_textures_and_reset_hitbox(self, texture_name: str):
     """
     Create 8 lists of 8-texture spritesheets for each combination of hull
     and turret directions.
     """
     full_texture_name = get_path_to_file(texture_name)
     width, height = get_texture_size(texture_name, columns=8)
     self.all_textures[IDLE] = load_textures(full_texture_name,
                                             [(i * width, 0, width, height)
                                              for i in range(8)])
     self.textures = self.all_textures[self.pose]
     self.set_texture(self.facing_direction)
     self.set_hit_box(self.texture.hit_box_points)
 def _spawn_wreck(name, position, texture_index) -> GameObject:
     wreck = TerrainObject(name, Robustness.INDESTRUCTIBLE, position)
     texture_name = get_path_to_file(name)
     width, height = PIL.Image.open(texture_name).size
     if isinstance(texture_index, Tuple):  # for tanks with turrets
         i, j = texture_index
         wreck.texture = load_texture(texture_name, j * (width // 8),
                                      i * (height // 8), width // 8,
                                      height // 8)
     else:
         wreck.texture = load_texture(texture_name,
                                      texture_index * (width // 8),
                                      0, width // 8, height)
     return wreck
示例#8
0
 def _load_textures_and_reset_hitbox(self, texture_name: str):
     """
     Create 8 lists of 8-texture spritesheets for each combination of hull
     and turret directions.
     """
     width, height = get_texture_size(texture_name, 8, 8)
     full_texture_name = get_path_to_file(texture_name)
     self.textures = [
         load_textures(full_texture_name,
                       [(i * width, j * height, width, height)
                        for i in range(8)]) for j in range(8)
     ]
     self.set_texture(self.facing_direction)
     self.set_hit_box(self.texture.hit_box_points)
 def __init__(self,
              gameobject_name: str,
              x: int,
              y: int,
              parent,
              functions=None):
     super().__init__('small_button_none.png',
                      x,
                      y,
                      parent=parent,
                      functions=functions)
     self.gameobject_name = get_path_to_file(gameobject_name)
     w, h = self.width, self.height
     self.gameobject_texture = load_texture(self.gameobject_name, 0, 0, w,
                                            h)
示例#10
0
    def __init__(self,
                 texture_name: str,
                 player: Player,
                 weight: UnitWeight,
                 position: Point,
                 id: int = None):
        super().__init__(texture_name, player, weight, position, id)
        self.virtual_angle = int(ROTATION_STEP * self.cur_texture_index) % 360

        thread_texture = f'{self.object_name.rsplit("_", 1)[0]}_threads.png'
        self.thread_texture = get_path_to_file(thread_texture)
        self.threads_time = 0

        self.fuel = 100.0
        self.fuel_consumption = 0.0
示例#11
0
from utils.colors import GREEN, RED, YELLOW
from game import Game
from players_and_factions.player import PlayerEntity
from units.units import Unit, Vehicle
from utils.functions import get_path_to_file, ignore_in_menu
from utils.geometry import average_position_of_points_group

UNIT_HEALTH_BAR_WIDTH = 5
SOLDIER_HEALTH_BAR_WIDTH = 4
BUILDING_HEALTH_BAR_WIDTH = 10
UNIT_HEALTHBAR_LENGTH_RATIO = 0.6
SOLDIER_HEALTHBAR_LENGTH_RATIO = 0.4
BUILDING_HEALTHBAR_LENGTH_RATIO = 1.8

selection_textures = load_textures(
    get_path_to_file('unit_selection_marker.png'),
    [(i * 60, 0, 60, 60) for i in range(10)])
building_selection_texture = load_texture(
    get_path_to_file('building_selection_marker.png'), 0, 0, 180, 180)
soldier_selection_texture = load_texture(
    get_path_to_file('soldier_selection_marker.png'), 0, 0, 40, 40)


def selected_unit_marker(entity):
    if entity.is_infantry:
        return SelectedSoldierMarker(entity)
    else:
        return SelectedUnitMarker(entity)


class SelectedEntityMarker:
示例#12
0
def read_single_file(filename: str) -> Dict[str, Dict[str, Any]]:
    category_dict = {}
    with open(get_path_to_file(filename), newline='') as file:
        for row in csv.DictReader(file):
            category_dict[row['object_name']] = convert_csv_data(row)
    return category_dict
示例#13
0
from utils.enums import TerrainCost
from utils.scheduling import EventsCreator
from utils.functions import (
    get_path_to_file, all_files_of_type_named
)
from utils.logging import log, logger, timer
from utils.geometry import distance_2d, calculate_circular_area

# CIRCULAR IMPORTS MOVED TO THE BOTTOM OF FILE!


PATH = 'PATH'
DIAGONAL = 1.4142  # approx square root of 2
MAP_TEXTURES = {
    'mud': load_spritesheet(
        get_path_to_file('mud_tileset_6x6.png'), 60, 45, 4, 16, 0)
}
ADJACENT_OFFSETS = [
    (-1, -1), (-1, 0), (-1, +1), (0, +1), (0, -1), (+1, -1), (+1, 0), (+1, +1)
]
OPTIMAL_PATH_LENGTH = 50

random_value = random.random

# typing aliases:
NormalizedPoint = Tuple[int, int]
MapPath = Union[List[NormalizedPoint], List[GridPosition]]
PathRequest = Tuple['Unit', GridPosition, GridPosition]


def position_to_map_grid(x: Number, y: Number) -> GridPosition:
示例#14
0
 def _load_textures_and_reset_hitbox(self, texture_name: str):
     width, height = get_texture_size(texture_name, columns=8)
     full_texture_name = get_path_to_file(texture_name)
     self.textures = load_textures(get_path_to_file(full_texture_name),
                                   [(i * width, 0, width, height)
                                    for i in range(8)])