Exemple #1
0
    def take_action(self, nav_map, entities, game_state):
        results = []
        target = None

        monster = self.owner

        if game_state == GameStates.STANDART:
            libtcod.map_compute_fov(nav_map, monster.x, monster.y, 10, True, 0)
            #self.fov_recompute = False

            for entity in entities:
                if entity.ai.__class__.__name__ == 'Player' and libtcod.map_is_in_fov(
                        nav_map, entity.x, entity.y):
                    target = entity
                    self.seen_target = (target.x, target.y)

            if target:
                if monster.distance_to(target) >= 2:
                    monster.move_astar(target.x, target.y, entities, nav_map)

                elif target.combat_aspect.active:
                    attack_results = monster.combat_aspect.attack(
                        target, 'cut')
                    results.extend(attack_results)

            elif self.seen_target:
                if (monster.x, monster.y) != self.seen_target:
                    x, y = self.seen_target
                    monster.move_astar(x, y, entities, nav_map)
                else:
                    self.seen_target = None

            results.extend(monster.combat_aspect.update_combatant_state())

        return results
Exemple #2
0
def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
    """
    Recalcule le champ de vision à partir d'un FOV déjà existant

    Parametres:
    ----------
    fov_map : tcod.map

    x : int

    y : int

    radius : int

    light_walls : bool

    algorithm : int
        Intenditifiant de l'algorithme de calcul du FOV propre à libtcod

    Renvoi:
    -------
    Aucun

    """
    libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
Exemple #3
0
 def process(self):
     global fov_map, fov_recompute
     if fov_recompute:
         fov_recompute = False
         for Player, (Player, Position) in self.world.get_components(Components.Player, Components.Position):
             tcod.map_compute_fov(fov_map, Position.X, Position.Y, 15, FOV_LIGHT_WALLS, FOV_ALGO)
         for y in range(MAP_HEIGHT):
             for x in range(MAP_WIDTH):
                 visible = tcod.map_is_in_fov(fov_map, x, y)
                 wall = map[x][y].block_sight
                 if not visible:
                     if map[x][y].explored:  # It's out of the player's FOV
                         if wall:
                             con.print(x, y, '#', tcod.grey, tcod.black)
                         else:
                             con.print(x, y, ' ', tcod.grey, tcod.black)
                 else:  # It's visible
                     if wall:
                         con.print(x, y, '#', tcod.white, tcod.black)
                     else:
                         con.print(x, y, ' ', tcod.white, tcod.black)
                     map[x][y].explored = True
         for Entity, (Render, Position) in self.world.get_components(Components.Render, Components.Position):
             visible = tcod.map_is_in_fov(fov_map, Position.X, Position.Y)
             if not visible:
                 if not Render.In_FoV:
                     Render.value = False
             else:
                 if Render.Exists:
                     Render.value = True
def render(player, con, fov_map, check_explored):
    tcod.map_compute_fov(fov_map, player.xPos, player.yPos, TORCH_RADIUS,
                         FOV_LIGHT_WALLS, FOV_ALGO)

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = tcod.map_is_in_fov(fov_map, x, y)
            compute_fov = False
            wall = map[x][y].wall
            if not visible and (map[x][y].explored or not check_explored):
                if check_explored:
                    color = tcod.grey
                else:
                    color = tcod.light_grey

                if wall:
                    tcod.console_put_char_ex(con, x, y, '#', color, tcod.black)
                else:
                    tcod.console_put_char_ex(con, x, y, '.', color, tcod.black)

            if visible:
                map[x][y].explored = True
                if wall:
                    tcod.console_put_char_ex(con, x, y, '#', tcod.light_yellow,
                                             tcod.black)
                else:
                    tcod.console_put_char_ex(con, x, y, '.', tcod.light_yellow,
                                             tcod.black)

    tcod.console_put_char_ex(con, MAP_WIDTH - 2, MAP_HEIGHT - 2, 'X',
                             tcod.fuchsia, tcod.black)
    player.draw(con)
Exemple #5
0
def recomputer_fov(fov_map,
                   x,
                   y,
                   radius,
                   light_walls=FOV_LIGHT_WALLS,
                   algorithm=FOV_ALGO):
    tcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
Exemple #6
0
def render_all():
    global color_light_wall, color_dark_wall
    global color_light_ground, color_dark_ground
    global FOV_map, FOV_recompute

    if FOV_recompute:
        FOV_recompute = False
        tcod.map_compute_fov(FOV_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

    # Iterate Room Tiles and Set Color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = tcod.map_is_in_fov(FOV_map, x, y)
            wall = map[x][y].block_sight
            if not visible:
                if map[x][y].explored:
                    if wall:
                        tcod.console_set_char_background(con, x, y, color_dark_wall, tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(con, x, y, color_dark_ground, tcod.BKGND_SET)
            else:
                if wall:
                    tcod.console_set_char_background(con, x, y, color_light_wall, tcod.BKGND_SET)
                else:
                    tcod.console_set_char_background(con, x, y, color_light_ground, tcod.BKGND_SET)
                map[x][y].explored = True

    for object in objects:  # Object List
        object.draw()       # Draw All Objects

    tcod.console_blit(con, 0, 0 , SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) # Blit Contents To Root Console
def recompute_fov(fov_map,
                  x,
                  y,
                  fov_algorithm=0,
                  fov_radius=5,
                  fov_light_walls=True):
    libtcod.map_compute_fov(fov_map, x, y, fov_radius, fov_light_walls,
                            fov_algorithm)
Exemple #8
0
def recompute_fov(fov_map,
                  player_x,
                  player_y,
                  radius,
                  light_walls=True,
                  algorithm=0):
    tcod.map_compute_fov(fov_map, player_x, player_y, radius, light_walls,
                         algorithm)
def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
    """
    Cette fonction met à jour le champ de vision du joueur en fonction
   de la position du joueur et du rayon de son champ de vision.
   L'algorithme FOV utilisé par défaut est le 0.

    """
    libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
Exemple #10
0
def map_calculate_fov():
    global FOV_CALCULATE

    if FOV_CALCULATE:
        FOV_CALCULATE = False
        tcod.map_compute_fov(FOV_MAP, PLAYER.x, PLAYER.y,
                             constants.TORCH_RADIUS, constants.FOV_LIGHT_WALLS,
                             constants.FOV_ALGO)
Exemple #11
0
 def recalc_fov(self):
     T.map_compute_fov(self.fov_map,
                             self.player.x, self.player.y,
                             MAP_W,
                             True)
     for x in range(MAP_W):
         for y in range(MAP_H):
             if self.is_visible(x, y):
                 self.tiles[x][y].remember_glyph()
Exemple #12
0
 def update(self, entities):
     for e in entities:
         if e.has(FovComponent) and e.get(FovComponent).fov_recalculate:
             tcod.map_compute_fov(self.fov_map,
                                  e.get(DisplayComponent).x,
                                  e.get(DisplayComponent).y, FOV_RADIUS,
                                  FOV_LIGHT_WALLS, FOV_ALGORITHM)
             e.get(FovComponent).fov_map = self.fov_map
             e.get(FovComponent).fov_recalculate = False
Exemple #13
0
def map_calc_fov():
    global FOV_CALC

    if globalvars.FOV_CALC:
        globalvars.FOV_CALC = False
        libtcodpy.map_compute_fov(globalvars.FOV_MAP, globalvars.PLAYER.x,
                                  globalvars.PLAYER.y, constants.TORCH_RADIUS,
                                  constants.FOV_LIGHT_WALLS,
                                  constants.FOV_ALGO)
Exemple #14
0
def setup_level(world, level_number, player):
    level = make_level(world, level_number, player)
    place_in_room(level, player)
    tcod.map_compute_fov(level.map_grid,
                         player.location.x,
                         player.location.y,
                         radius=FOV_RADIUS,
                         light_walls=FOV_LIGHT_WALLS,
                         algo=FOV_ALGO)
    return level
Exemple #15
0
def play_level(level):
    game_state = handle_keys(level)
    update_level(level)
    tcod.map_compute_fov(level.map_grid,
                         level.player.location.x,
                         level.player.location.y,
                         radius=FOV_RADIUS - level.number // 2,
                         light_walls=FOV_LIGHT_WALLS,
                         algo=FOV_ALGO)
    update_screen(level)
    return game_state
 def run(self):
     while 1:
         job, obj = jobs.get()
         if job == 'fov':
             tcod.map_compute_fov(obj, MAP_WIDTH // 2, MAP_HEIGHT // 2)
         elif job == 'astar':
             tcod.path_compute(self.astar,
                               0, 0, MAP_WIDTH - 1 , MAP_HEIGHT - 1)
             x, y = tcod.path_walk(self.astar, False)
             while x is not None:
                 x, y = tcod.path_walk(self.astar, False)
         jobs.task_done()
Exemple #17
0
 def run(self):
     while 1:
         job, obj = jobs.get()
         if job == 'fov':
             tcod.map_compute_fov(obj, MAP_WIDTH // 2, MAP_HEIGHT // 2)
         elif job == 'astar':
             tcod.path_compute(self.astar, 0, 0, MAP_WIDTH - 1,
                               MAP_HEIGHT - 1)
             x, y = tcod.path_walk(self.astar, False)
             while x is not None:
                 x, y = tcod.path_walk(self.astar, False)
         jobs.task_done()
Exemple #18
0
def recompute_fov(fov_map,
                  x,
                  y,
                  radius,
                  light_walls=True,
                  algorithm=0):  # 1 = diamond algorithm - it's orthogonal
    libtcod.map_compute_fov(m=fov_map,
                            x=x,
                            y=y,
                            radius=radius,
                            light_walls=light_walls,
                            algo=algorithm)
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_ground,
                                libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_ground, libtcod.BKGND_SET)
                    #since it's visible, explore it
                    map[x][y].explored = True

    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

    #show the player's stats
    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(
        0, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))
def render_all():
    global color_light_wall, color_dark_wall
    global color_light_ground, color_dark_ground
    global fov_recompute
    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = libtcod.map_is_in_fov(fov_map, x, y)
            wall = map[x][y].block_sight
            if not visible:
                if map[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, color_dark_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, color_dark_ground, libtcod.BKGND_SET)
            else:
                if wall:
                    libtcod.console_set_char_background(
                        con, x, y, color_light_wall, libtcod.BKGND_SET)
                else:
                    libtcod.console_set_char_background(
                        con, x, y, color_light_ground, libtcod.BKGND_SET)
                map[x][y].explored = True
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, line)
        y += 1
    render_bar(1, 1, BAR_WIDTH, "HP", player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level ' + str(dungeon_level))
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse())
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Exemple #21
0
 def process(self):
     if self.scene.fov_recompute:
         for pos in self.get_player_position():
             tcod.map_compute_fov(
                 self.scene.game_map,
                 x=pos.x,
                 y=pos.y,
                 radius=self.radius,
                 light_walls=self.light_walls,
                 algo=self.algo,
             )
             fov_bool_array = self.scene.game_map.fov
             self.scene.game_map.explored[fov_bool_array] = True
Exemple #22
0
    def recompute_fov(self, x, y):
        self.log.debug("Recomputing FOV map...")
        radius = self.config.vision.radius
        light_walls = self.config.vision.light_walls
        algorithm = self.config.vision.algorithm

        libtcod.map_compute_fov(self.fov_map, x, y, radius, light_walls, algorithm)

        for entity, (position, optics) in self.world.get_components(Position, Optics):
            optics.lit = self.fov_map.fov[position.y, position.x] or self.config.vision.debug

            if optics.lit:
                optics.explored = True
def nethack_render():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_put_char_ex(
                                con, x, y, '#', libtcod.white, libtcod.black)
                        else:
                            libtcod.console_put_char_ex(
                                con, x, y, '.', libtcod.grey, libtcod.black)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, '#',
                                                    libtcod.white,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y, '.',
                                                    libtcod.white,
                                                    libtcod.black)
                        #since it's visible, explore it
                    map[x][y].explored = True
            for object in objects:
                #only show if it's visible to the player; or it's set to "always visible" and on an explored tile
                if (libtcod.map_is_in_fov(fov_map, object.x, object.y)
                        or (object.always_visible
                            and map[object.x][object.y].explored)):
                    object.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 1)

    #print the game messages, one line at a time
    y = 1
    libtcod.console_print_ex(0, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, "Hey")
Exemple #24
0
def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
    """Helper function to modify fov_map based on player location, determin light
    radius, and whether or not walls are lit

    :fov_map: TODO
    :x: TODO
    :y: TODO
    :radius: TODO
    :light_walls: TODO
    :algorithm: TODO
    :returns: TODO

    """
    libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
Exemple #25
0
def compute_fov(fov_map,
                x,
                y,
                radius,
                light_walls=True,
                algorithm=0,
                memory=None):
    tcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)

    if memory is not None:
        # Must use "is not None" because [] also evaluates to False
        for xi in range(x - radius, x + radius):
            for yi in range(y - radius, y + radius):
                if tcod.map_is_in_fov(fov_map, xi, yi):
                    memory[xi][yi] = True
def recompute_fov(fov_map,
                  player,
                  radius,
                  entities,
                  light_walls=True,
                  algorithim=0):
    for entity in entities:
        if entity != player:
            if entity.sight_passes:
                sight_blocked = entity.blocks and not entity.sight_passes
            else:
                sight_blocked = entity.blocks
            tcod.map_set_properties(fov_map, entity.x, entity.y,
                                    not sight_blocked, not entity.blocks)
    tcod.map_compute_fov(fov_map, player.x, player.y, radius, light_walls,
                         algorithim)
Exemple #27
0
    def update(self, radius, light_walls=True, algorithm=0) -> None:
        """
        """

        if self.needs_fov_recompute:
            logger.debug(
                f"Recomputing FOV for {self.player.position} radius {radius} algorithm:{algorithm}"
            )
            tcod.map_compute_fov(
                self.fov_map,
                self.player.x,
                self.player.y,
                radius,
                light_walls,
                algorithm,
            )
Exemple #28
0
def render_all():
    tcod.console_set_default_foreground(con, tcod.white)
    tcod.console_print_ex(
        con, 1, SCREEN_HEIGHT - 2, tcod.BKGND_NONE, tcod.LEFT,
        'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))

    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        tcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                             FOV_LIGHT_WALLS, FOV_ALGO)

        # go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    # it's out of the player's FOV
                    if wall:
                        tcod.console_set_char_background(
                            con, x, y, color_dark_wall, tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            con, x, y, color_dark_ground, tcod.BKGND_SET)
                else:
                    # it's visible
                    if wall:
                        tcod.console_set_char_background(
                            con, x, y, color_light_wall, tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            con, x, y, color_light_ground, tcod.BKGND_SET)

    # draw all objects in the list
    for object in objects:
        if object != player:
            object.draw()

    player.draw()

    # blit the contents of "con" to the root console
    tcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
Exemple #29
0
    def handleMessage(self, name, value):
        if name == 'processExplosions':
            self.events = {'explosions':None}
            explosionList = []
            avatars = value['avatars']
            worldMap = value['map']
            items = value['items']
            self.addedItems = []

            for item in items + avatars:
                keys = item.events.keys()
                if item.active == True and 'explode-multi' in keys:
                    for data in item.events['explode-multi']:
                        [x,y] = data['coord']
                        foo = Entity({})
                        foo.x = x
                        foo.y = y
                        self.addExplosion({'params': data}, foo, worldMap)
                    item.events['explode-multi'] = {}

                if item.active == True and 'explode' in item.events.keys():
                    details = item.events['explode']
                    if 'params' in details.keys():    
                        self.addExplosion(details, item, worldMap)
                    item.events['explode'] = {}

            for item in items + self.addedItems:
                if type(item).__name__ == 'Exploder' and item.active == True:
                    affectedSpaces = []
                    fov_map = libtcod.map_new(worldMap.MAP_WIDTH, worldMap.MAP_HEIGHT)
                    for y in range(item.y - item.radius, item.y + item.radius):
                        for x in range(item.x - item.radius, item.x + item.radius):
                            not_block_sight = not worldMap.mapArray[x][y].block_sight if (x>0 and x< worldMap.MAP_WIDTH - 1 and y > 0 and y < worldMap.MAP_HEIGHT - 1) else False
                            not_block = not worldMap.mapArray[x][y].blocked if (x>0 and x< worldMap.MAP_WIDTH - 1 and y > 0 and y < worldMap.MAP_HEIGHT - 1) else False
                            libtcod.map_set_properties(fov_map, x, y, not_block_sight, not_block)
                    libtcod.map_compute_fov(fov_map, item.x, item.y, item.radius, False, 0)
                    for y in range(item.y - item.radius, item.y + item.radius):
                        for x in range(item.x - item.radius, item.x + item.radius):
                            if libtcod.map_is_in_fov(fov_map, x, y):
                                affectedSpaces.append([x, y])
                                worldMap.mapArray[x][y].msg('create', {'duration':item.duration, 'type':item.name, 'power':item.power, 'owner':item.pwner, 'maxSpreads':item.maxSpreads, 'original':id(item)})
                        
                    explosionList.append({'originator':item, 'name':item.name, 'affectedSpaces':affectedSpaces})
                    item.active = False

            self.events = {'explosions':explosionList}
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
 
    #show the player's stats
    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(0, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))
Exemple #31
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        # go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    # if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(
                                con, x, y, color_dark_ground,
                                libtcod.BKGND_SET)
                else:
                    # it's visible
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, color_light_ground, libtcod.BKGND_SET)
                    # since it's visible, explore it
                    map[x][y].explored = True

    # draw all objects in the list
    for object in objects:
        object.draw()

    # blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
Exemple #32
0
def renderAll():
    global fovRecompute, fovMap
    if fovRecompute:
        fovRecompute = False
        tcod.map_compute_fov(fovMap, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visable = tcod.map_is_in_fov(fovMap, x, y)
            wall = map[x][y].blockSight
            if not visable:
                if map[x][y].explored:
                    if wall:
                        tcod.console_set_char_background(con, x, y, colorDarkWall, tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(con, x, y, colorDarkGround, tcod.BKGND_SET)
            else:
                if wall:
                    tcod.console_set_char_background(con, x, y, colorLightWall, tcod.BKGND_SET)
                else:
                    tcod.console_set_char_background(con, x, y, colorLightGround, tcod.BKGND_SET)
                    map[x][y].explored = True
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    tcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    tcod.console_set_default_background(panel, tcod.black)
    tcod.console_clear(panel)
    tcod.console_set_default_foreground(panel, tcod.light_gray)
    tcod.console_print_ex(panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT, getNamesUnderMouse())

#messageLog
    y = 1
    for (line, color) in gameMSGs:
        tcod.console_set_default_foreground(panel, color)
        tcod.console_print_ex(panel, MSG_X, y, tcod.BKGND_NONE,tcod.LEFT, line)
        y += 1
#health bar
    renderBar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.maxHp, tcod.light_red, tcod.darker_red)
    tcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def render_all(fov, player, map, fov_map, char_con, objects):
    #call it with fov_recompute
    if fov:
        fov = False
        light_walls = int(const['FOV_LIGHT_WALLS'])
        tcod.map_compute_fov(fov_map, int(player.axis_X), int(player.axis_Y),
                             const['TORCH_RADIUS'], light_walls,
                             const['FIELD_OF_VIEW_ALGO'])

        for h in range(const['MAP_HEIGHT']):
            for w in range(const['MAP_WIDTH']):
                visible = tcod.map_is_in_fov(fov_map, w, h)
                wall = map[w][h].block_sight
                if not visible:
                    if map[w][h].explored:
                        #not visible and not explored- everything is black
                        if wall:
                            tcod.console_set_char_background(
                                char_con, int(w), int(h),
                                const['color_dark_wall'], tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(
                                char_con, int(w), int(h),
                                const['color_ground'], tcod.BKGND_SET)
                    else:
                        if wall:
                            tcod.console_set_char_background(
                                char_con, int(w), int(h),
                                const['color_light_wall'], tcod.BKGND_SET)
                        else:

                            tcod.console_set_char_background(
                                char_con, int(w), int(h),
                                const['color_ground'], tcod.BKGND_SET)
                        map[w][h].explored = True

            for object in objects:
                object.draw(fov_map, char_con)

            tcod.console_blit(char_con, 0, 0, const['SCREEN_WIDTH'],
                              const['SCREEN_HEIGHT'], 0, 0, 0)
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list
    for object in objects:
        object.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
def test_map_fov(map_):
    libtcodpy.map_compute_fov(map_, *POINT_A)
def test_fov_single():
    for m in maps:
        tcod.map_compute_fov(m, MAP_WIDTH // 2, MAP_HEIGHT // 2)
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
 
    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
 
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
 
 
    #prepare to render the GUI panel
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)
 
    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1
 
    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.light_red, libtcod.darker_red)
 
    #display names of objects under the mouse
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse())
 
    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)