Example #1
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground, fov_recompute

    if fov_recompute:
        #recompute FOV if needed
        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_put_char_ex(
                                con, x, y, '#', color_dark_wall, libtcod.black)

                        else:
                            libtcod.console_put_char_ex(
                                con, x, y, '.', color_dark_ground,
                                libtcod.black)
                else:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, '#',
                                                    color_light_wall,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y, '.',
                                                    color_light_ground,
                                                    libtcod.black)
                    map[x][y].explored = True

    #draw everything
    for stuff in objects:
        if stuff != player:
            stuff.draw()
    player.draw()
    #we are "blitting" our offscreen console oot the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

    #render GUI
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)

    #print game messages
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    #show player stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)

    #blit onto root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Example #2
0
 def take_turn(self, game_map, fov_map, path_map, game_objects, playerxy):
     npc = self.owner
     x, y = (0, 0)
     if self.behaviour == MoveAI.SKITTISH:
         if dice(2):
             npc.move(game_map, game_objects, random.randint(-1, 1), random.randint(-1, 1))
         else:
             x, y = playerxy
             libtcod.map_compute_fov(fov_map, npc.x, npc.y, npc.fov_radius
                                             ,C.FOV_LIGHT_WALLS, C.FOV_ALGO)
             if libtcod.map_is_in_fov(fov_map, x, y):
                 # player in sight!
                 if libtcod.path_compute(path_map, npc.x, npc.y, x, y):
                     x, y = libtcod.path_walk(path_map, True)
                     if not x is None:
                         npc.move(game_map, game_objects, npc.x - x, npc.y - y)
     elif self.behaviour == MoveAI.NEUTRAL:
         if dice(self.erraticity):
             x = random.randint(-1, 1)
         if dice(self.erraticity):
             y = random.randint(-1, 1)
         npc.move(game_map, game_objects, x, y)
     elif self.behaviour == MoveAI.FRIENDLY:
         x, y = playerxy
         # player in sight!
         if libtcod.path_compute(path_map, npc.x, npc.y, x, y):
             # stick a little bit away
             if libtcod.path_size(path_map) > 3:
                 x, y = libtcod.path_walk(path_map, True)
                 if not x is None:
                     npc.move(game_map, game_objects, x - npc.x, y - npc.y)
     elif self.behaviour == MoveAI.HUNTING:
         # look for prey
         x, y = playerxy
         libtcod.map_compute_fov(fov_map, npc.x, npc.y, npc.fov_radius
                                         ,C.FOV_LIGHT_WALLS, C.FOV_ALGO)
         if libtcod.map_is_in_fov(fov_map, x, y):
             # player in sight!
             if libtcod.path_compute(path_map, npc.x, npc.y, x, y):
                 self.prey_x = x
                 self.prey_y = y
                 x, y = libtcod.path_walk(path_map, True)
                 if not x is None:
                     npc.move(game_map, game_objects, x - npc.x, y - npc.y)
         else:
             # prowl last know prey location
             if libtcod.path_compute(path_map, npc.x, npc.y
                                     ,self.prey_x, self.prey_y):
                 x, y = libtcod.path_walk(path_map, True)
                 if not x is None:
                     npc.move(game_map, game_objects, x - npc.x, y - npc.y)
Example #3
0
def render_all():
	global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground, fov_recompute
	
	if fov_recompute:
		#recompute FOV if needed
		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_put_char_ex(con, x, y, '#', color_dark_wall, libtcod.black)

						else:
							libtcod.console_put_char_ex(con, x, y, '.', color_dark_ground, libtcod.black)
				else:
					if wall:
						libtcod.console_put_char_ex(con, x, y, '#', color_light_wall, libtcod.black)
					else:
						libtcod.console_put_char_ex(con, x, y, '.', color_light_ground, libtcod.black)
					map[x][y].explored = True
	
	#draw everything
	for stuff in objects:
		if stuff != player:
			stuff.draw()
	player.draw()
	#we are "blitting" our offscreen console oot the root console
	libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

	#render GUI
	libtcod.console_set_background_color(panel, libtcod.black)
	libtcod.console_clear(panel)

	#print game messages
	y = 1
	for (line, color) in game_msgs:
		libtcod.console_set_foreground_color(panel, color)
		libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
		y += 1

	#show player stats
	render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

	#blit onto root console
	libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Example #4
0
def warp_level():
    """
        Warp to the next game level.
    """
    global game_map
    global fov_map
    global path_map
    global game_objects
    global player
    global maps_avail
    global save_screenshot

    #prepare ftl
    player.warp_prep()
    player.wizard = False
    if player.level == 1:
        player.msg("Press %c'?'%c for help" % (C.COL1, C.COLS))
    if player.level == 10:
        player.add_dialogue(cls.Dialogue("Puppy", "icon-puppy.png", "Thank you " \
        "for rescuing me Top Dog! Those Mafiosos sure got taught a lesson." \
        "\n\nLet us go home now, and play some ball...\n\n*Woof!*"))
        player.add_dialogue(cls.Dialogue("Wez", "icon-paw.png", \
        "Thanks for playing! Our adventure ends here, as this short game was " \
        "made in a couple of days.\n\nBut you never know when Top Dog will find " \
        "more adventure and doggy treats..."))
        gamestate.pop()
        gamestate.push(C.STATE_VICTORY)
        gamestate.push(C.STATE_DIALOGUE)
        save_screenshot = True
    else:
        # init new maps
        game_map, fov_map, path_map = factory.generate_map(maps_avail)
        # add player, NPC's, foliage, food
        game_objects = [player]
        # add level npcs, food, items
        game_objects.extend(factory.spawn_level_objects(game_map, player.level))
        # add level quests and story
        factory.spawn_level_quests(game_map, game_objects, player.level)
        factory.spawn_level_storyline(game_map, game_objects, player)

        # compute field of vision
        libtcod.map_compute_fov(fov_map, player.x, player.y
                                ,player.fov_radius, C.FOV_LIGHT_WALLS, C.FOV_ALGO)
        # carry our inventory item into this new level
        if player.carrying:
            game_objects.append(player.carrying)
Example #5
0
def game_turn(player_move_x, player_move_y):
    """
        Call all game turn actions.
    """
    if player.move(game_map, game_objects, player_move_x, player_move_y):
        # move NPC's
        for npc in game_objects:
            if isinstance(npc, cls.AnimalBase):
                if npc.move_ai:
                    npc.move_ai.take_turn(game_map, fov_map, path_map
                                        ,game_objects, (player.x, player.y))
        # recompute field of vision since we moved
        libtcod.map_compute_fov(fov_map, player.x, player.y
                                ,player.fov_radius
                                ,C.FOV_LIGHT_WALLS, C.FOV_ALGO)
    # are we still alive?
    if player.hp == 0:
        gamestate.push(C.STATE_LOST)
    else:
        # check game state for NPC dialogues
        if len(player.dialogues) > 0:
            gamestate.push(C.STATE_DIALOGUE)
Example #6
0
def render_graphics():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
    global emitters
    emitters = []
    global glosnosc
    glosnosc = {}

    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_back(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_back(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_background_color(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_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.hp, player.max_hp,
        libtcod.light_red, libtcod.darker_red)

    render_bar(1, 2, BAR_WIDTH, 'XP', player.xp, 100,
        libtcod.light_blue, libtcod.darker_blue)

    render_info(1, 4, BAR_WIDTH, 'Floor: ' + str(floor))
 
    #display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())

    mouse = libtcod.mouse_get_status()
    (x1, y1) = (mouse.cx, mouse.cy)

    #print str(math.atan2(player.y-y1, player.x-x1)/math.pi*180)
 
    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
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)
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level ' + str(dungeon_level))

    # 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)
Example #8
0
def render_graphics():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute
    global emitters
    emitters = []
    global glosnosc
    glosnosc = {}

    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_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(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_background_color(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_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.hp, player.max_hp,
               libtcod.light_red, libtcod.darker_red)

    render_bar(1, 2, BAR_WIDTH, 'XP', player.xp, 100, libtcod.light_blue,
               libtcod.darker_blue)

    render_info(1, 4, BAR_WIDTH, 'Floor: ' + str(floor))

    #display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               get_names_under_mouse())

    mouse = libtcod.mouse_get_status()
    (x1, y1) = (mouse.cx, mouse.cy)

    #print str(math.atan2(player.y-y1, player.x-x1)/math.pi*180)

    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Example #9
0
player = Entity(27, 22, "@", libtcod.white, con, world)
npc = Entity(56, 27, "J", libtcod.yellow, con, world)
objects = [npc, player]

fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT)
for y in range(MAP_HEIGHT):
    for x in range(MAP_WIDTH):
        libtcod.map_set_properties(fov_map, x, y, not world[x][y].block_sight, not world[x][y].blocked)

fov_recompute = True

while not libtcod.console_is_window_closed():
    libtcod.console_set_default_foreground(0, libtcod.white)

    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

    render_all(fov_map)

    libtcod.console_flush()

    for object in objects:
        object.clear()

    if handle_keys():
        break

exit()
Example #10
0
File: map.py Project: jimperio/pyrl
 def compute_fov(self, x, y):
   libtcod.map_compute_fov(self.__fov_map, x, y, self.torch_radius, self.light_walls, self.fov_algorithm)
Example #11
0
 def recompute_fov(self, x, y):
     if x != self.fov_x or y != self.fov_y:
         libtcod.map_compute_fov(self.fov_map, x, y, VIEW_RADIUS,
                                 FOV_LIGHT_WALLS, FOV_ALGO)
         self.fov_x = x
         self.fov_y = y