Ejemplo n.º 1
0
 def _draw_silhouettes(self, pc, tx,ty, ent, sight):
     '''
     #   extend a line from tile tx,ty to a distant tile
     #   which is in the same direction from the player.
     #   Check for lit tiles, and if we find any along the way,
     #   draw a silhouette for the location of interest.
     #   Basically, if the ent is backlit, you can see
     #   a silhouette.
     '''
     world=rog.world()
     if not sight:
         return
     if not (ent and world.has_component(ent, cmp.Creature)):
         return
     pos=world.component_for_entity(ent, cmp.Position)  
     dist=maths.dist(pos.x,pos.y, tx,ty)
     dx=(tx - pos.x)/dist
     dy=(ty - pos.y)/dist
     xdest=tx + int(dx*sight)
     ydest=ty + int(dy*sight)
     libtcod.line_init(tx,ty, xdest,ydest)
     while True:
         x,y=libtcod.line_step()
         if x is None: return
         if maths.dist(pos.x,pos.y, x,y) > sight: return
         if self.get_blocks_sight(x,y):  return
         if self.get_perceived_light_value(x,y):
             libtcod.console_put_char(self.con_map_state, tx,ty, "?")
             return
Ejemplo n.º 2
0
    def shine(self):  # shine light on environment; add light to lightmap
        assert (self.shone == False)  # cannot shine if we already did
        self.shone = True
        rang = self.getLumens(self.lum)
        libtcod.map_compute_fov(  # Get the tiles we can see
            rog.getfovmap(self.fovID),
            self.x,
            self.y,
            rang,
            light_walls=True,
            algo=libtcod.FOV_RESTRICTIVE)
        for x in range(max(0, self.x - rang), min(ROOMW, self.x + rang + 1)):
            for y in range(max(0, self.y - rang), min(ROOMH,
                                                      self.y + rang + 1)):

                if (rog.in_range(self.x, self.y, x, y, rang)
                        and libtcod.map_is_in_fov(rog.getfovmap(self.fovID), x,
                                                  y)):
                    dist = maths.dist(self.x, self.y, x, y)
                    # F = L / 4 * pi * d^2 (formula for light dispersion)
                    lux = self.lum // (12.5663706144 * (dist**2))
                    if lux:
                        self.add_tile(x, y, lux)
                        rog.tile_lighten(x, y, lux)
        # end for
        return True  #success
Ejemplo n.º 3
0
 def shine(self):        # add light to the lightmap
     if (self.shone):    # must unshine before shining again.
         print("ERROR: shine failed: shone==True")
         return False
     self.shone=True
     #get the tiles we can see and lighten them up
     libtcod.map_compute_fov(
         self.fov_map, self.x,self.y, self.brightness,
         light_walls = True, algo=libtcod.FOV_RESTRICTIVE)
     rang = self.brightness
     for x in     range( max(0, self.x-rang), min(ROOMW, self.x+rang+1) ):
         for y in range( max(0, self.y-rang), min(ROOMH, self.y+rang+1) ):
             
             if ( rog.in_range(self.x,self.y, x,y, rang)
                     and libtcod.map_is_in_fov(self.fov_map, x,y) ):
                 dist=maths.dist(self.x,self.y, x,y)
                 value=round(self.brightness - dist)
                 if value > 0:
                     self.add_tile(x,y, value )
                     rog.tile_lighten(x,y,value)
     return True     #success
Ejemplo n.º 4
0
def can_hear(obj, x,y, volume):
    if ( on(obj,DEAD) or on(obj,DEAF) or not obj.stats.get('hearing') ):
         return False
    dist=maths.dist(obj.x, obj.y, x, y)
    maxHearDist=volume*obj.stats.get('hearing')/AVG_HEARING
    if (obj.x == x and obj.y == y): return (0,0,maxHearDist,)
    if dist > maxHearDist: return False
    # calculate a path
    path=path_init_sound()
    path_compute(path, obj.x,obj.y, x,y)
    pathSize=libtcod.path_size(path)
    if dist >= 2:
        semifinal=libtcod.path_get(path, 0)
        xf,yf=semifinal
        dx=xf - obj.x
        dy=yf - obj.y
    else:
        dx=0
        dy=0
    path_destroy(path)
    loudness=(maxHearDist - pathSize - (pathSize - dist))
    if loudness > 0:
        return (dx,dy,loudness)
Ejemplo n.º 5
0
def explosion(bomb):
    con=libtcod.console_new(ROOMW, ROOMH)
    rog.msg("{t}{n} explodes!".format(t=bomb.title, n=bomb.name))
    fov=rog.fov_init()
    libtcod.map_compute_fov(
        fov, bomb.x,bomb.y, bomb.r,
        light_walls = True, algo=libtcod.FOV_RESTRICTIVE)
    
    for x in range(bomb.r*2 + 1):
        for y in range(bomb.r*2 + 1):
            xx=x + bomb.x - bomb.r
            yy=y + bomb.y - bomb.r
            if not libtcod.map_is_in_fov(fov, xx,yy):
                continue
            if not rog.is_in_grid(xx,yy): continue
            dist=maths.dist(bomb.x,bomb.y, xx,yy)
            if dist > bomb.r: continue
            
            thing=rog.thingat(xx, yy)
            if thing:
                if rog.on(thing,DEAD): continue
                
                if thing.isCreature:
                    decay=bomb.dmg/bomb.r
                    dmg= bomb.dmg - round(dist*decay) - thing.stats.get('arm')
                    rog.hurt(thing, dmg)
                    if dmg==0: hitName="not damaged"
                    elif rog.on(thing,DEAD): hitName="killed"
                    else: hitName="hit"
                    rog.msg("{t}{n} is {h} by the blast.".format(
                        t=thing.title,n=thing.name,h=hitName) )
                else:
                    # explode any bombs caught in the blast
                    if (thing is not bomb
                            and hasattr(thing,'explode')
                            and dist <= bomb.r/2 ):
                        thing.timer=0
Ejemplo n.º 6
0
def in_range(x1,y1,x2,y2,Range):    return (maths.dist(x1,y1, x2,y2) <= Range + .34)

# view
def getx(x):        return x + view_port_x() - view_x()
Ejemplo n.º 7
0
def in_range(x1, y1, x2, y2, Range):
    return (maths.dist(x1, y1, x2, y2) <= Range + .34)