How to use the flax.geometry.Direction function in flax

To help you get started, we’ve selected a few flax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eevee / flax / flax / geometry.py View on Github external
def iter_border(self):
        for x in range(self.left + 1, self.right):
            yield Point(x, self.top), Direction.up
            yield Point(x, self.bottom), Direction.down

        for y in range(self.top + 1, self.bottom):
            yield Point(self.left, y), Direction.left
            yield Point(self.right, y), Direction.right

        yield Point(self.left, self.top), Direction.up_left
        yield Point(self.right, self.top), Direction.up_right
        yield Point(self.left, self.bottom), Direction.down_left
        yield Point(self.right, self.bottom), Direction.down_right
github eevee / flax / flax / fractor.py View on Github external
def place_portal(self, portal_type, destination):
        from flax.component import Portal
        if portal_type is e.StairsDown:
            # Add the down stairs to the room, surrounded by some pillars
            room_center = self.room_region.center()
            self.map_canvas.set_architecture(
                room_center,
                portal_type(Portal(destination=destination)),
            )
            for direction in (
                Direction.up_right, Direction.down_right,
                Direction.up_left, Direction.down_left
            ):
                self.map_canvas.set_architecture(room_center + direction, e.Pillar)
        else:
            super().place_portal(portal_type, destination)
github eevee / flax / flax / fractor.py View on Github external
def place_portal(self, portal_type, destination):
        from flax.component import Portal
        if portal_type is e.StairsDown:
            # Add the down stairs to the room, surrounded by some pillars
            room_center = self.room_region.center()
            self.map_canvas.set_architecture(
                room_center,
                portal_type(Portal(destination=destination)),
            )
            for direction in (
                Direction.up_right, Direction.down_right,
                Direction.up_left, Direction.down_left
            ):
                self.map_canvas.set_architecture(room_center + direction, e.Pillar)
        else:
            super().place_portal(portal_type, destination)
github eevee / flax / flax / geometry.py View on Github external
def edge_length(self, edge):
        if edge is Direction.up or edge is Direction.down:
            return self.width
        if edge is Direction.left or edge is Direction.right:
            return self.height
        raise ValueError("Expected an orthogonal direction")
github eevee / flax / flax / geometry.py View on Github external
def neighbors(self):
        return [self + d for d in Direction]
github eevee / flax / flax / ui / console / game.py View on Github external
from flax.event import Descend
        from flax.event import PickUp
        from flax.event import Equip
        from flax.event import Unequip
        from flax.geometry import Direction
        event = None
        if key == 'up' or key == '8':
            event = self.world.player_action_from_direction(Direction.up)
        elif key == 'down' or key == '2':
            event = self.world.player_action_from_direction(Direction.down)
        elif key == 'left' or key == '4':
            event = self.world.player_action_from_direction(Direction.left)
        elif key == 'right' or key == '6':
            event = self.world.player_action_from_direction(Direction.right)
        elif key == 'end' or key == '1':
            event = self.world.player_action_from_direction(Direction.down_left)
        elif key == 'page down' or key == '3':
            event = self.world.player_action_from_direction(Direction.down_right)
        elif key == 'home' or key == '7':
            event = self.world.player_action_from_direction(Direction.up_left)
        elif key == 'page up' or key == '9':
            event = self.world.player_action_from_direction(Direction.up_right)
        elif key == '>':
            event = Descend(self.world.player)
        elif key == '<':
            event = Ascend(self.world.player)
        elif key == ',':
            tile = self.world.current_map.find(self.world.player)
            # TODO might consolidate this to a single event later if it fucks
            # up the sense of time.  or maybe it should!
            for item in tile.items:
                self.world.push_player_action(PickUp(self.world.player, item))
github eevee / flax / flax / fractor.py View on Github external
ruination = random_normal_range(0, 0.2) + distance * 0.2
                    self.map_canvas.set_architecture(
                        point, e.Rubble(Breakable(ruination)))

        # And apply some light ruination to the inside of the room
        border = list(room_rect.iter_border())
        # TODO don't do this infinitely; give up after x tries
        while True:
            point, edge = random.choice(border)
            if self.map_canvas._arch_grid[point + edge] is CaveWall:
                break
        self.map_canvas.set_architecture(point, CaveWall)
        self.map_canvas.set_architecture(point - edge, CaveWall)
        # TODO this would be neater if it were a slightly more random pattern
        for direction in (
                Direction.up, Direction.down, Direction.left, Direction.right):
            self.map_canvas.set_architecture(
                point - edge + direction, CaveWall)
github eevee / flax / flax / component.py View on Github external
def act(self, world):
        from flax.geometry import Direction
        from flax.event import Walk
        from flax.event import MeleeAttack
        import random
        pos = world.current_map.find(self.entity).position
        player_pos = world.current_map.find(world.player).position
        for direction in Direction:
            if pos + direction == player_pos:
                world.queue_event(MeleeAttack(self.entity, direction))
                return

        # TODO try to walk towards player
        world.queue_event(Walk(self.entity, random.choice(list(Direction))))
github eevee / flax / flax / geometry.py View on Github external
def iter_border(self):
        for x in range(self.left + 1, self.right):
            yield Point(x, self.top), Direction.up
            yield Point(x, self.bottom), Direction.down

        for y in range(self.top + 1, self.bottom):
            yield Point(self.left, y), Direction.left
            yield Point(self.right, y), Direction.right

        yield Point(self.left, self.top), Direction.up_left
        yield Point(self.right, self.top), Direction.up_right
        yield Point(self.left, self.bottom), Direction.down_left
        yield Point(self.right, self.bottom), Direction.down_right
github eevee / flax / flax / fractor.py View on Github external
if (n < noise.get(Point(x, y - 1), 1) and
                        n < noise.get(Point(x, y + 1), 1)):
                    local_minima.add(point)

        for point in local_minima:
            if point not in river_blob:
                self.map_canvas.set_architecture(point, e.Dirt)

        for blob in (left_bank, right_bank):
            paths = self.flood_valleys(blob, local_minima, noise)

            for path_point in paths:
                self.map_canvas.set_architecture(path_point, e.Dirt)

        # Whoops time for another step: generating a surrounding cave wall.
        for edge in Direction.orthogonal:
            width = self.region.edge_length(edge)
            wall_noise = discrete_perlin_noise_factory(width, resolution=6)
            for n in self.region.edge_span(edge):
                offset = int(wall_noise(n) * 4 + 1)
                for m in range(offset):
                    point = self.region.edge_point(edge, n, m)
                    self.map_canvas.set_architecture(point, e.CaveWall)