示例#1
0
 def check_move(self, pos1, pos2):
     key1 = point2key(tuple(pos1))
     if key1 not in self.graph:
         return False
     key2 = point2key(tuple(pos2))
     if key2 not in self.graph:
         return False
     for neighbor in self.graph[key1]:
         if neighbor["key"] == key2:
             return neighbor["cost"]
     return False
示例#2
0
 def check_move(self, pos1, pos2):
     key1 = point2key(tuple(pos1))
     if key1 not in self.graph:
         return False
     key2 = point2key(tuple(pos2))
     if key2 not in self.graph:
         return False
     for neighbor in self.graph[key1]:
         if neighbor["key"] == key2:
             return neighbor["cost"]
     return False
示例#3
0
 def get_fov(self, team, member):
     fov = {}
     person = team.members[member]
     fov, items = person.field_of_view(self.level)
     if len(self.teams) > 1:
         other_team = (set(self.teams) - set([team])).pop()  # tadaa!
         enemies_seen = [
             e for e in other_team.members
             if (point2key(tuple(e.position)) in fov or point2key((
                 e.position[0], e.position[1], e.position[2] + 1)) in fov)
         ]
     else:
         enemies_seen = []
     return fov, enemies_seen
示例#4
0
 def get_team_fov(self, team, exclude_members=[]):
     fov = {}
     for i, person in enumerate(team.members):
         if i not in exclude_members:
             person_fov, items = person.field_of_view(self.level)
             fov.update(person_fov)
     if len(self.teams) > 1:
         other_team = (set(self.teams) - set([team])).pop()  # tadaa!
         enemies_seen = [
             e for e in other_team.members
             if (point2key(tuple(e.position)) in fov or point2key((
                 e.position[0], e.position[1], e.position[2] + 1)) in fov)
         ]
     else:
         enemies_seen = []
     return fov, enemies_seen
示例#5
0
def load_level(levelfile):

    level = []
    textures = {}
    with open(levelfile) as f:
        # first read the texture offsets
        for line in (l.strip() for l in f):
            if len(line) == 0:
                break
            character, offset = line.split("=")
            textures[character] = offset
        a = []
        level.append(a)
        for line in (l.strip() for l in f):
            if len(line) > 0:
                a.append(line)
            else:
                a = []
                level.append(a)

    xmax = len(level[0][0]) // 2
    ymax = len(level[0]) // 2
    zmax = len(level) // 2

    # level = "".join(level_lines)

    walls = {}

    for z in range(zmax):
        for y in range(ymax):
            for x in range(xmax):
                # print(x, y, z)
                center = level[z * 2 + 1][y * 2 + 1][x * 2 + 1]

                north = level[z * 2 + 1][y * 2][x * 2 + 1]
                west = level[z * 2 + 1][y * 2 + 1][x * 2]
                south = level[z * 2 + 1][y * 2 + 2][x * 2 + 1]
                east = level[z * 2 + 1][y * 2 + 1][x * 2 + 2]
                top = level[z * 2 + 2][y * 2 + 1][x * 2 + 1]
                bottom = level[z * 2][y * 2 + 1][x * 2 + 1]

                if center == "0" or all([
                        north != ".", west != ".", south != ".", east != ".",
                        top != "."
                ]):
                    result = "000000"
                else:
                    result = west + east + north + south + top + bottom
                if result != "......":
                    walls[point2key((x, y, z))] = result

    return walls, textures
示例#6
0
def load_level(levelfile):

    level = []
    textures = {}
    with open(levelfile) as f:
        # first read the texture offsets
        for line in (l.strip() for l in f):
            if len(line) == 0:
                break
            character, offset = line.split("=")
            textures[character] = offset
        a = []
        level.append(a)
        for line in (l.strip() for l in f):
            if len(line) > 0:
                a.append(line)
            else:
                a = []
                level.append(a)

    xmax = len(level[0][0]) // 2
    ymax = len(level[0]) // 2
    zmax = len(level) // 2

    # level = "".join(level_lines)

    walls = {}

    for z in range(zmax):
        for y in range(ymax):
            for x in range(xmax):
                # print(x, y, z)
                center = level[z*2+1][y*2+1][x*2+1]

                north = level[z*2+1][y*2][x*2+1]
                west = level[z*2+1][y*2+1][x*2]
                south = level[z*2+1][y*2+2][x*2+1]
                east = level[z*2+1][y*2+1][x*2+2]
                top = level[z*2+2][y*2+1][x*2+1]
                bottom = level[z*2][y*2+1][x*2+1]

                if center == "0" or all([north != ".", west != ".", south != ".", east != ".", top != "."]):
                    result = "000000"
                else:
                    result = west + east + north + south + top + bottom
                if result != "......":
                    walls[point2key((x, y, z))] = result

    return walls, textures
示例#7
0
def get_neighbor_key(key, dx=0, dy=0, dz=0):
    x, y, z = key2point(key)
    return point2key((x+dx, y+dy, z+dz))
示例#8
0
def get_neighbor_key(key, dx=0, dy=0, dz=0):
    x, y, z = key2point(key)
    return point2key((x + dx, y + dy, z + dz))