def update_visibility(self): self.clear_visibility() fieldOfView( self.player.pos.col, self.player.pos.row, len(self.get_cur_floor().base[0]) - 1, len(self.get_cur_floor().base) - 1, self.player.vis_range, (lambda x, y: self.set_visible(y, x)), (lambda x, y: self.get_cur_floor().base_blocks_vision(y, x)))
def look(self, char): """List everything the character can see from its current position""" r = [] def see(x,y): r.append(((x,y), self.terrain((x,y)))) for m in self.objects[(x,y)]: r.append(((x,y),m)) fov.fieldOfView(char.coords[0], char.coords[1], self.w, self.h, self.w+self.h, see, lambda x,y: self.is_opaque((x,y))) return r
def run(self): actcall = self.player.level.act() while True: fov.fieldOfView(self.player.x, self.player.y, 10, self.see, lambda x, y: not self.player.level[x, y].is_passable) self.draw() key = self.stdscr.getch() if key == ord('q'): if self.ask("Really quit? [yN]").lower() == 'y': return elif key in self.MOVEMENT: delta = self.MOVEMENT[key] try: self.player.move_by(*delta) except MovementObstructed: pass next(actcall)
def updateFOV(self, tileBlockes, markVisible): self.resetFOV() xCoord = self.getPlayerCoordX() yCoord = self.getPlayerCoordY() fov.fieldOfView(xCoord, yCoord, self.numCols, self.numRows, PLAYER_RANGE, \ markVisible, tileBlockes) for agent in self.agents: if self.guardFovInRange(agent): xCoord = self.getAgentCoordX(agent.x) yCoord = self.getAgentCoordY(agent.y) # Called by fov alg for every tile that an agent cast light on. def markColored(x, y): if self.tileLit(x, y) and not tileBlockes(x, y) and \ self.get2pDist(agent.x, agent.y, x*TILESIZE, y*TILESIZE) \ <= agent.range**2: self.lightMap[x][y].append(agent) fov.fieldOfView(xCoord, yCoord, self.numCols, self.numRows, agent.range, markColored, tileBlockes)
def UpdateFoV(self, sio=None): self.drawRangesOld = self.drawRangesNew self.drawRangesNew = {} def fVisited(x, y): if x < self.worldViewX or x > self.worldViewX + self.windowWidth: return if y < self.worldViewY or y > self.worldViewY + self.windowHeight+1: return self.AddTileBits(x, y, TILE_SEEN) if y in self.drawRangesNew: minX, maxX = self.drawRangesNew[y] self.drawRangesNew[y] = [ min(x, minX), max(x, maxX) ] else: self.drawRangesNew[y] = [ x, x ] def fBlocked(x, y): return sorrows.world.IsLocationOpaque(x, y) # if self._GetTileBits(x, y) & TILE_OPEN: # return False # return True #return False playerX, playerY = self.user.body.GetPosition() fov.fieldOfView(playerX, playerY, sorrows.world.mapWidth, sorrows.world.mapHeight, VIEW_RADIUS, fVisited, fBlocked) # The update ranges should cover the old and the new field of views. # Tiles outside the new field of view (and in the old) will get # deemphasised. And tiles within the new FoV will get the opposite. drawRanges = self.drawRangesOld.copy() for y, t1 in self.drawRangesNew.iteritems(): if y not in drawRanges: drawRanges[y] = t1 else: t0 = drawRanges[y] if t0 != t1: drawRanges[y] = [ min(t0[0], t1[0]), max(t0[1], t1[1]) ] sio_ = StringIO.StringIO() if sio is None else sio for y, (minX, maxX) in drawRanges.iteritems(): vMinX = (minX - self.worldViewX) + 1 vMaxX = (maxX - self.worldViewX) + 1 if vMinX < 1 or vMaxX > self.windowWidth: continue vy = (y - self.worldViewY) + 1 if vy < self.windowYStartOffset or vy > self.windowYEndOffset: continue self.MoveCursor(vMinX, vy, sio=sio_) for s in self.ViewedTileRange(minX, maxX, y): sio_.write(s) # arr = array.array('c', (c for c in self.ViewedTileRange(minX, maxX, y))) #sio_.write(arr.tostring()) self.UpdatePlayer(sio=sio_) if sio is None: self.user.Write(sio_.getvalue())
def update_fov(self): self.fov = [] fieldOfView(self.x,self.y, self.map.size_x, self.map.size_y, self.view_distance, lambda x,y: self.fov.append((x,y)), lambda x,y: not self.map.is_view_passable(x,y)) print len(self.fov)
def calculate_fov(self): self.fov_tiles_list = [] fov.fieldOfView(self.x, self.y, gameObject.conGame.width, gameObject.conGame.height, self.fov_range, self.visit_fov_tile, self.fov_tile_blocked)
def doFOV(self): fieldOfView(self.player.pos.x, self.player.pos.y, self.width, self.height, 15, self.funcVisit, self.funcBlocked)