Esempio 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)
Esempio 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
Esempio 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()
Esempio 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
Esempio 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
Esempio 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))
Esempio 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)
Esempio 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))
Esempio n. 9
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)
Esempio n. 10
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
Esempio n. 11
0
 def get_size(self):
     return Vec2(self.get_width(), self.get_height())
Esempio n. 12
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)
Esempio n. 13
0
 def get_info_origin(self):
     return Vec2(0, 1)
Esempio n. 14
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))
Esempio n. 15
0
 def draw_info(self):
     pencil = self._screen.create_pencil(self.get_info_origin())
     pencil.draw(Vec2(0, 0), "Seed: '{}'".format(self._seed))
Esempio n. 16
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)
Esempio n. 17
0
 def get_grid_coordinates_of(self, index):
     return Vec2(index % self._dimension, index // self._dimension)