Ejemplo n.º 1
0
    def find_charge_path(self, d):

        charging = True
        charge_path = []

        pos = Hex(*self.player.pos)

        while charging:

            next_hex = Hex.hex_neighbour(pos, d)
            next_pos = next_hex.to_tuple()
            if self.is_on_map(next_pos):
                if self.is_obstacle(next_pos):
                    charging = False
                elif self.slows_charge(next_pos):
                    charging = False
                    charge_path.append(next_pos)
                else:
                    charge_path.append(next_pos)
            else:
                charging = False

            pos = next_hex

        return charge_path
Ejemplo n.º 2
0
    def calculate_hex_move_time(self):

        a = Hex(*self.animation.hex_start)
        b = Hex(*self.animation.hex_end)
        hex_distance = Hex.hex_distance(a, b)

        return self.animation.move.duration / hex_distance
Ejemplo n.º 3
0
    def is_in_range(self, point):

        a = Hex(*point)
        b = Hex(*self.player.pos)

        dist = Hex.hex_distance(a, b)
        return self.player.min_range <= dist <= self.player.max_range
Ejemplo n.º 4
0
    def draw_overlapping_trees(self, surface):

        hex = pixel_to_hex(self.game.hex_layout, self.position.screen_pos())

        bl = Hex.hex_neighbour(hex, 4)
        br = Hex.hex_neighbour(hex, 5)

        for hex in (bl, br):

            if self.game.map.get_tile((hex.x, hex.y)) == Tile.WOODS:
                self.game.map_image.image.draw_overlap_trees(surface, hex)
Ejemplo n.º 5
0
    def weigh_mark_options(self, actor, in_range):

        actor_pos = Hex(*actor.pos)
        weighted = {}

        for coord in in_range:

            value = self.dijkstra_map.get_value(coord)
            if value is None:
                weighted[coord] = UnitControl.IMPASSABLE_WEIGHT
            else:
                weighted[coord] = value * UnitControl.PROXIMITY_WEIGHT
                weighted[coord] += Hex.hex_distance(actor_pos, Hex(*coord))

        return weighted
Ejemplo n.º 6
0
    def _draw_tree(self, hex_coord):

        px, py = hex_to_pixel(self.game.hex_layout, Hex(*hex_coord))
        [
            self.tree_sprite.draw(self.surface, pos=(px + tx, py + ty))
            for (tx, ty) in TREE_POSITIONS
        ]
Ejemplo n.º 7
0
    def get_tiles_in_range(self):

        player = Hex(*self.owner.pos)

        def in_range(coord):
            c = Hex(*coord)
            return Hex.hex_distance(player, c) <= self._range

        coords = self.owner.game.map.all_except(Tile.WOODS)

        return filter(in_range, coords)
Ejemplo n.º 8
0
    def calculate_foe_trample(self, foe):

        # get all adj hexes to foe
        # filter out obstructed hexes
        # if any hex is deadly, choose that
        # otherwise choose a random hex
        # add chosen hex to obstruction map
        # if no valid hex, return DIES constant

        adj = [h.to_tuple() for h in Hex.get_hex_neighbours(Hex(*foe.pos))]

        valid_adj = [a for a in adj if self.is_valid_run_pos(a)]

        if not valid_adj:
            return 'trample'

        deadly = [a for a in valid_adj if self.is_deadly(a)]
        if deadly:
            run_pos = choice(deadly)
        else:
            run_pos = choice(valid_adj)

        self._obstruction_map.add(run_pos)
        return run_pos
Ejemplo n.º 9
0
 def get_adj(self, actor):
     a = Hex(*actor.pos)
     return self.move_map.available_moves(
         [h.to_tuple() for h in Hex.get_hex_neighbours(a)])
Ejemplo n.º 10
0
    def player_in_range(self):

        player = Hex(*self.player.pos)
        owner = Hex(*self.owner.pos)

        return Hex.hex_distance(player, owner) <= self._range
Ejemplo n.º 11
0
    def adj_to_player(self):

        player = Hex(*self.player.pos)
        owner = Hex(*self.owner.pos)

        return Hex.hex_distance(player, owner) == 1
Ejemplo n.º 12
0
 def in_range(coord):
     c = Hex(*coord)
     return Hex.hex_distance(player, c) <= self._range
Ejemplo n.º 13
0
 def _get_pixel_pos(self, pos):
     px, py = hex_to_pixel(self.game.hex_layout, Hex(*pos))
     return px, py
Ejemplo n.º 14
0
    def _draw_tile(self, hex_coord):

        tile_image = get_tile_image(self.map.get_tile(hex_coord))
        pixel_coord = hex_to_pixel(self.game.hex_layout, Hex(*hex_coord))
        tile_image.draw(self.surface, pixel_coord)
Ejemplo n.º 15
0
 def _get_hex_pos(self, pos):
     px, py = hex_to_pixel(self.game.hex_layout, Hex(*pos))
     py -= GameObject.ACTOR_OFFSET
     return px, py
Ejemplo n.º 16
0
 def is_adj(self, pos):
     a = Hex(*pos)
     b = Hex(*self.player.pos)
     return Hex.hex_distance(a, b) == 1