class Area(object): def __init__(self): self.terrain = GeoGraph(self) self.features = GeoGraph(self) self.entities = GeoGraph(self) self.constructor = Block((100,100)) self.constructor.build() chasm = set() for zone in self.constructor.zones: for point in zone.chasm: self.terrain[point] = GeoNode(point, {'chasm' : True}) chasm.add(point) for point in zone.floor: self.terrain[point] = GeoNode(point, {'chasm' : False}) for point in zone.wall: self.features[point] = GeoNode(point) possible_points = set(self.terrain.data).difference(set(self.features.data)).difference(chasm) for point in possible_points: if random.randrange(0,75) == 0: self.entities[point] = EntityNode(point) print str(len(self.entities.nodes)) self.fov_mask = self.features.get_mask() def get_nodes(self, mask): result = set() result.update(self.terrain.get_nodes(mask)) result.update(self.features.get_nodes(mask)) result.update(self.entities.get_nodes(mask)) return result
class Session(object): def __init__(self): pygame.init() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode(SCREEN_SIZE) self.dungeon = Block((125,125)) self.dungeon.build() def tick(self, input_events): self.screen.fill((0,0,0)) for event in input_events: if event.type == QUIT: sys.exit() for zone in self.dungeon.zones: for point in zone.floor: xy = point[0] * 3, point[1] * 3 pygame.draw.rect(self.screen, zone.color, (xy,(2,2))) for point in zone.wall: xy = point[0] * 3, point[1] * 3 pygame.draw.rect(self.screen, (230,230,230), (xy,(2,2))) for point in zone.path: xy = point[0] * 3, point[1] * 3 pygame.draw.rect(self.screen, (120,120,120), (xy,(2,2)))
def __init__(self): pygame.init() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode(SCREEN_SIZE) self.dungeon = Block((125,125)) self.dungeon.build()