Exemplo n.º 1
0
 def _create_border(self):
     self.fill_at(Vec2(0, 0), Vec2(self._dimension, 1), Terrain.BORDER_WALL)
     self.fill_at(Vec2(0, self._dimension - 1), Vec2(self._dimension, 1),
                  Terrain.BORDER_WALL)
     self.fill_at(Vec2(0, 1), Vec2(1, self._dimension - 1),
                  Terrain.BORDER_WALL)
     self.fill_at(Vec2(self._dimension - 1, 1),
                  Vec2(1, self._dimension - 1), Terrain.BORDER_WALL)
Exemplo n.º 2
0
 def __init__(self, dimension, seed):
     self._ground = Ground.fromSeed(dimension, seed)
     self._player_list = []
     self._entity_list = []
     self._spell_list = []
     self._grid = ArenaGrid(Vec2(dimension, dimension))
     self._step = 0
Exemplo n.º 3
0
    def __init__(self, dimension):
        self._dimension = dimension
        self._grid = {}

        for y in range(0, dimension.y):
            for x in range(0, dimension.x):
                self._grid[Vec2(x, y)] = ArenaGrid.GridElement()
Exemplo n.º 4
0
    def __init__(self, screen, keyboard, character, character_list, arena_size,
                 ground_grid, seed):
        self._screen = screen
        self._screen.enable_fps_counter(Vec2(0, 0))
        self._keyboard = keyboard

        self._player_character = character
        self._character_list = character_list
        self._arena_dimension = Vec2(arena_size, arena_size)
        self._ground_grid = ground_grid
        self._seed = seed

        self._last_time_stamp_skill_key = 0
        self._skill_cast_try = False

        self._skill_cast_failure_cursor_counter = 0
Exemplo n.º 5
0
    def parse(reference_list, table, dimension):
        lines = [BoxLine.NONE] * len(table)
        for i, _ in enumerate(table):
            pos = Vec2((i % dimension.x), i // dimension.x)

            if BoxLine._is_reference(reference_list, table, pos, dimension):
                up = BoxLine._is_reference(reference_list, table,
                                           Vec2(pos.x, pos.y - 1), dimension)
                down = BoxLine._is_reference(reference_list, table,
                                             Vec2(pos.x, pos.y + 1), dimension)
                left = BoxLine._is_reference(reference_list, table,
                                             Vec2(pos.x - 1, pos.y), dimension)
                right = BoxLine._is_reference(reference_list, table,
                                              Vec2(pos.x + 1, pos.y),
                                              dimension)

                lines[
                    i] = BoxLine.CENTER + up * BoxLine.UP + down * BoxLine.DOWN + left * BoxLine.LEFT + right * BoxLine.RIGHT

        return lines
Exemplo n.º 6
0
    def draw_ground_walls(self):
        pencil = self._screen.create_pencil(self.get_arena_origin())
        pencil.set_color(33)
        pencil.set_style(TermPencil.Style.DIM)

        wall_list = [Terrain.BORDER_WALL, Terrain.WALL, Terrain.INTERNAL_WALL]
        line_table = BoxLine.parse(wall_list, self._ground_grid,
                                   self._arena_dimension)

        box_drawing = BoxLineDrawing(pencil, BoxLineDrawing.Style.SINGLE_ROUND)
        box_drawing.draw(line_table, self._arena_dimension, Vec2(2, 1))
Exemplo n.º 7
0
    def draw_entities(self, entity_list):
        pencil = self._screen.create_pencil(self.get_arena_origin())

        for entity in entity_list:
            if Direction.NONE != entity.direction:
                point = entity.position + Direction.as_vector(entity.direction)
                cursor, color = ("·", 240)

                if entity.character == self._player_character:
                    if self._skill_cast_try:
                        if self.is_terrain_blocked(point):
                            self._skill_cast_failure_cursor_counter = 5
                    if self._skill_cast_failure_cursor_counter > 0:
                        cursor, color = ("×", 124)
                        self._skill_cast_failure_cursor_counter -= 1

                pencil.draw(Vec2(point.x * 2, point.y), cursor, color,
                            TermPencil.Style.BOLD)

        for entity in entity_list:
            pencil.draw(Vec2(entity.position.x * 2, entity.position.y),
                        entity.character)
Exemplo n.º 8
0
    def _draw_fps(self):
        if not self._fps_position:
            return

        pencil = self.create_pencil(self._fps_position)

        current_time = time.time()
        self._frame_counter += 1
        if current_time - self._fps_time_stamp > 1.0:
            self._fps = self._frame_counter
            self._fps_time_stamp = current_time
            self._frame_counter = 0

        pencil.draw(Vec2(0, 0), "FPS: {:2d}".format(self._fps))
Exemplo n.º 9
0
    def on_update(self, state):
        self._entity.enable_movement(False)
        last_movement = self._entity.get_position() - self._last_step_position
        if last_movement != Vec2.zero():
            self._last_step_position = self._entity.get_position().copy()
            logger.debug("Player '{}' at step {} moves {}".format(
                self._entity.get_character(), state.get_step(), last_movement))

        if self._last_cast_skill != None:
            spell = super().register_cast(state, self._last_cast_skill)
            if spell:
                state.add_spell(spell)
                logger.debug("Player '{}' at step {} casts {}".format(
                    self._entity.get_character(), state.get_step(),
                    self._last_cast_skill))

            self._last_cast_skill = None
Exemplo n.º 10
0
    def draw(self, line_table, dimension, scale):
        for i, box_line in enumerate(line_table):
            tile_line_list = self._get_line_tiles(box_line, scale)

            for offset_y, tile_line in enumerate(tile_line_list):
                if tile_line != "":
                    position = Vec2((i % dimension.x) * scale.x,
                                    (i // dimension.x) * scale.y + offset_y)

                    if position.y <= (
                            dimension.y -
                            1) * scale.y:  #skip last line if scale > 1
                        if position.x == (
                                dimension.x -
                                1) * scale.x:  #skip last line if scale > 1
                            tile_line = tile_line[0]

                        self._pencil.draw(position, tile_line)
Exemplo n.º 11
0
    def has_all_neighbours_distance(self,
                                    center,
                                    filter_terrain_list,
                                    distance,
                                    direction=None):
        left = -distance * int(direction != Direction.RIGHT)
        right = distance * int(direction != Direction.LEFT) + 1
        up = -distance * int(direction != Direction.DOWN)
        down = distance * int(direction != Direction.UP) + 1

        for x in range(left, right):
            for y in range(up, down):
                if x == 0 and y == 0:
                    continue

                position = center + Vec2(x, y)
                if not self.is_terrain(position, filter_terrain_list):
                    return False

        return True
Exemplo n.º 12
0
    def find_separated_positions(self, amount, min_distance):
        random.seed(None)
        position_list = []
        free_terrain = []
        for i, terrain in enumerate(self._grid):
            if terrain == Terrain.EMPTY:
                free_terrain.append(self.get_grid_coordinates_of(i))

        index = random.randrange(0, len(free_terrain))
        new_position = free_terrain[index]
        position_list.append(new_position)
        del free_terrain[index]

        while len(position_list) < amount:
            index = random.randrange(0, len(free_terrain))
            new_position = free_terrain[index]
            for position in position_list:
                if Vec2.distance(position, new_position) > min_distance:
                    position_list.append(new_position)
                    del free_terrain[index]
                    break

        return position_list
Exemplo n.º 13
0
 def get_size(self):
     return Vec2(self.get_width(), self.get_height())
Exemplo n.º 14
0
 def get_info_origin(self):
     return Vec2(0, 1)
Exemplo n.º 15
0
 def get_arena_origin(self):
     x = (self._screen.get_width() - self._arena_dimension.x * 2) // 2
     y = (self._screen.get_height() - self._arena_dimension.y) // 2
     return Vec2(int(x), int(y))
Exemplo n.º 16
0
 def draw_info(self):
     pencil = self._screen.create_pencil(self.get_info_origin())
     pencil.draw(Vec2(0, 0), "Seed: '{}'".format(self._seed))
Exemplo n.º 17
0
    def draw_spells(self, spell_list):
        pencil = self._screen.create_pencil(self.get_arena_origin())

        for spell in spell_list:
            pencil.draw(Vec2(spell.position.x * 2, spell.position.y), "o", 208)
Exemplo n.º 18
0
 def fill_at(self, position, dimension, terrain):
     for x in range(position.x, position.x + dimension.x):
         for y in range(position.y, position.y + dimension.y):
             self.set_at(Vec2(x, y), terrain)
Exemplo n.º 19
0
 def get_grid_coordinates_of(self, index):
     return Vec2(index % self._dimension, index // self._dimension)