コード例 #1
0
ファイル: mapviewer.py プロジェクト: lordmauve/wasabi-root
 def __init__(self, viewport, topleft, bottomright, pos=(0, 0)):
     self.viewport = viewport
     self.topleft = HexGrid.coord_to_screen(topleft)
     bottomright = HexGrid.coord_to_screen(bottomright)
     self.bottomright = (bottomright[0] - HEX_WIDTH / 2,
                         bottomright[1] - HEX_HEIGHT)
     self.pos = pos
コード例 #2
0
ファイル: mapviewer.py プロジェクト: jribbens/wasabi-root
 def __init__(self, viewport, topleft, bottomright, pos=(0, 0)):
     self.viewport = viewport
     self.topleft = HexGrid.coord_to_screen(topleft)
     bottomright = HexGrid.coord_to_screen(bottomright)
     self.bottomright = (bottomright[0] - HEX_WIDTH / 2,
                         bottomright[1] - HEX_HEIGHT)
     self.pos = pos
コード例 #3
0
ファイル: mapviewer.py プロジェクト: jribbens/wasabi-root
 def coord_to_viewport(self, coord):
     """Given a tile coordinate, get its viewport position."""
     cx, cy = self.pos
     wx, wy = HexGrid.coord_to_world(coord)
     sx, sy = HexGrid.coord_to_screen(coord)
     return (
         sx - cx,
         self.viewport[1] - sy + cy
     )
コード例 #4
0
ファイル: mapviewer.py プロジェクト: jribbens/wasabi-root
 def centre(self, coord):
     """Re-centre the camera on the given coord."""
     sx, sy = HexGrid.coord_to_screen(coord)
     self.pos = self.clip(
         sx - self.viewport[0] // 2,
         sy - self.viewport[1] // 2,
     )
コード例 #5
0
def group_connected(triggers):
    """Group the given list of triggers into connected sets."""
    groups = []
    ungrouped = set(
        (x, y, difficulty) for (x, y), difficulty in triggers.items())
    while ungrouped:
        x, y, difficulty = ungrouped.pop()
        pos = x, y
        locs = [pos]
        queue = [pos]
        while queue:
            pos = queue.pop()
            for x, y in HexGrid.neighbours(pos):
                if (x, y, difficulty) in ungrouped:
                    ungrouped.discard((x, y, difficulty))
                    c = x, y
                    locs.append(c)
                    queue.append(c)
        groups.append(TriggerArea(locs, difficulty))

    groups_by_loc = {}
    for g in groups:
        for l in g.locs:
            groups_by_loc[l] = g
    return groups, groups_by_loc
コード例 #6
0
ファイル: mapviewer.py プロジェクト: lordmauve/wasabi-root
 def centre(self, coord):
     """Re-centre the camera on the given coord."""
     sx, sy = HexGrid.coord_to_screen(coord)
     self.pos = self.clip(
         sx - self.viewport[0] // 2,
         sy - self.viewport[1] // 2,
     )
コード例 #7
0
ファイル: effects.py プロジェクト: lordmauve/wasabi-root
 def random_sprites(self, num=1):
     x, y = HexGrid.coord_to_world(self.pos)
     for _ in range(num):
         im = random.choice(self.images)
         dx = random.random() - 0.5
         dy = random.random() - 0.5
         c = x + dx, y + dy
         yield c, im
コード例 #8
0
ファイル: effects.py プロジェクト: jribbens/wasabi-root
 def random_sprites(self, num=1):
     x, y = HexGrid.coord_to_world(self.pos)
     for _ in range(num):
         im = random.choice(self.images)
         dx = random.random() - 0.5
         dy = random.random() - 0.5
         c = x + dx, y + dy
         yield c, im
コード例 #9
0
 def __init__(self, filename):
     self.floor = {
     }  # A list of floor graphics in draw order, keyed by coord
     self.objects = {}  # Static images occupying a tile, keyed by coord
     self.grid = HexGrid()
     self.images = {}
     self.pois = {}
     self.triggers = {}
     self.load_file(filename)
コード例 #10
0
ファイル: effects.py プロジェクト: jribbens/wasabi-root
    def create_particles(self, value, max_value):
        self.particles = []
        for points, img in zip(self.POINTS, self.images):
            if points > max_value:
                continue
            num, value = divmod(value, points)

            x, y = HexGrid.coord_to_world(self.pos)
            for _ in range(num):
                v = self.V
                vx = random.uniform(-v, v)
                vy = random.uniform(-v, v)
                z = 30
                vz = random.uniform(60, 100)
                self.particles.append((x + vx * 0.5, y + vy * 0.5, z, vx, vy, vz, img))
            if not value:
                break
コード例 #11
0
ファイル: effects.py プロジェクト: lordmauve/wasabi-root
    def create_particles(self, value, max_value):
        self.particles = []
        for points, img in zip(self.POINTS, self.images):
            if points > max_value:
                continue
            num, value = divmod(value, points)

            x, y = HexGrid.coord_to_world(self.pos)
            for _ in range(num):
                v = self.V
                vx = random.uniform(-v, v)
                vy = random.uniform(-v, v)
                z = 30
                vz = random.uniform(60, 100)
                self.particles.append(
                    (x + vx * 0.5, y + vy * 0.5, z, vx, vy, vz, img))
            if not value:
                break
コード例 #12
0
ファイル: behaviour.py プロジェクト: lordmauve/wasabi-root
def chase_closest_enemy(actor, t, dt):
    if actor.walking_to is None:
        grid = actor.world.grid
        enemies = [a.position for a in actor.world.actors if a.faction != actor.faction]
        distance_to_actor = lambda p: HexGrid.distance(p, actor.position)
        enemies.sort(key=distance_to_actor)
        # print([a.faction for a in actor.world.actors])
        for e in enemies:
            if distance_to_actor(e) < 2:
                # We're already there! adjacent are at distance sqrt3
                # Just change facing
                actor.look(e)
                return
            # Find closest unblocked location to attack
            attackable = [p for p in grid.neighbours(e) if not grid.blocks_movement(p)]
            if attackable:
                dest = min(attackable, key=distance_to_actor)
                actor.walk_to(dest)
                break
コード例 #13
0
ファイル: maploader.py プロジェクト: jribbens/wasabi-root
def group_connected(triggers):
    """Group the given list of triggers into connected sets."""
    groups = []
    ungrouped = set((x, y, difficulty) for (x, y), difficulty in triggers.items())
    while ungrouped:
        x, y, difficulty = ungrouped.pop()
        pos = x, y
        locs = [pos]
        queue = [pos]
        while queue:
            pos = queue.pop()
            for x, y in HexGrid.neighbours(pos):
                if (x, y, difficulty) in ungrouped:
                    ungrouped.discard((x, y, difficulty))
                    c = x, y
                    locs.append(c)
                    queue.append(c)
        groups.append(TriggerArea(locs, difficulty))

    groups_by_loc = {}
    for g in groups:
        for l in g.locs:
            groups_by_loc[l] = g
    return groups, groups_by_loc
コード例 #14
0
ファイル: mapviewer.py プロジェクト: lordmauve/wasabi-root
 def viewport_to_coord(self, coord):
     """Given a viewport coordinate, get the tile coordinate."""
     return HexGrid.world_to_coord(self.viewport_to_world(coord))
コード例 #15
0
ファイル: mapviewer.py プロジェクト: jribbens/wasabi-root
 def viewport_to_coord(self, coord):
     """Given a viewport coordinate, get the tile coordinate."""
     return HexGrid.world_to_coord(self.viewport_to_world(coord))
コード例 #16
0
 def calc_damage(self, actor, target):
     range = HexGrid.distance(actor.position, target.position)
     return random.randint(1, int(self.damage * (self.max_range - range)))
コード例 #17
0
ファイル: mapviewer.py プロジェクト: lordmauve/wasabi-root
 def coord_to_viewport(self, coord):
     """Given a tile coordinate, get its viewport position."""
     cx, cy = self.pos
     wx, wy = HexGrid.coord_to_world(coord)
     sx, sy = HexGrid.coord_to_screen(coord)
     return (sx - cx, self.viewport[1] - sy + cy)
コード例 #18
0
ファイル: weapon.py プロジェクト: jribbens/wasabi-root
 def calc_damage(self,actor, target):
     range = HexGrid.distance(actor.position, target.position)
     return random.randint(1,int(self.damage * (self.max_range - range)))