コード例 #1
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_dialogues():
    """
        Draw dialogues onto the screen.
    """
    if len(player.dialogues) > 0:
        libtcod.console_clear(0)
        dlg = player.dialogues[-1]
        if dlg.npc_picture:
            icon = libtcod.image_load(os.path.join('data', 'images', dlg.npc_picture))
        else:
            icon = libtcod.image_load(os.path.join('data', 'images', 'icon-%s.png' % (dlg.npc_name)))
        frame = libtcod.image_load(os.path.join('data', 'images', 'dialogue-frame.png'))
        libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
        libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
        # title
        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), 2,
                            libtcod.BKGND_NONE, libtcod.CENTER, 
                            "%c%s says:%c" % (C.COL4, dlg.npc_name, C.COLS))
#        # the message
#        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), C.MAP_TOP + 4,
#                            libtcod.BKGND_NONE, libtcod.CENTER, 
#                            "\"%c%s%c\"" % (C.COL5, dlg.dialogue, C.COLS))
        try:
            libtcod.console_print_rect(
                    0, 4, 6, C.MAP_WIDTH - 4, C.MAP_HEIGHT - 2,
                    "%s" % (dlg.dialogue))
        except e:
            print('dialogue string format error: %s' % (e))

        # press space
        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), 
                            C.SCREEN_HEIGHT - 1, 
                            libtcod.BKGND_NONE, libtcod.CENTER, 
                            "(spacebar or enter...)")
コード例 #2
0
ファイル: renderer.py プロジェクト: bhallen/yelpdor
    def render_map(self, player, dmap):
        camera = self.camera
        con = self.map_console

        # Clear screen before redraw
        libtcod.console_clear(con)

        camera.move(player.x, player.y)
        dmap.recompute_fov(player.x, player.y)
        for x in range(camera.width):
            for y in range(camera.height):
                (map_x, map_y) = (camera.x + x, camera.y + y)

                tile = dmap[map_x][map_y]
                in_fov = libtcod.map_is_in_fov(dmap.fov_map, map_x, map_y)
                self.draw_tile(x, y, tile, in_fov)

        for obj in dmap.objects:
            if obj != player:
                if libtcod.map_is_in_fov(dmap.fov_map, obj.x, obj.y):
                    (x, y) = camera.convert_coordinates(obj.x, obj.y)
                    self.draw_obj(con, x, y, obj)
        (x, y) = camera.convert_coordinates(player.x, player.y)
        self.draw_obj(con, x, y, player)

        return con
コード例 #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)
コード例 #4
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_about():
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'about-frame.png'))
    libtcod.image_blit_rect(icon, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    try:
        readme = file('README', 'r')
    except IOError, e:
        libtcod.console_print_ex(0, 2, 2,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "Error: about file not found :'(")
        return None
コード例 #5
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_lost():
    libtcod.console_clear(0)
    frame = libtcod.image_load(os.path.join('data', 'images', 'dialogue-frame.png'))
    libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    icon = libtcod.image_load(os.path.join('data', 'images', 'icon-paw.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 4,
                        libtcod.BKGND_NONE, libtcod.CENTER, \
                        "Ouch! You lost all your health.\n\n" \
                        "You rest to retry this level.\n\n" \
                        "(press space to try again)")
コード例 #6
0
ファイル: libtcoddemo.py プロジェクト: davidwinters/deadhack
def initialize_fov():
	global fov_recompute, fov_map

	libtcod.console_clear(con) #reset console to black

	fov_recompute = True

	#create the FOV map
	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 map[x][y].block_sight, not map[x][y].blocked)
コード例 #7
0
def initialize_fov():
    global fov_recompute, fov_map
    fov_recompute = True

    # create the FOV map, according to the generated map
    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 map[x][y].block_sight,
                                       not map[x][y].blocked)
    # unexplored areas start black (which is the default background color)
    libtcod.console_clear(con)
コード例 #8
0
ファイル: libtcoddemo.py プロジェクト: davidwinters/deadhack
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)
コード例 #9
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_victory():
    libtcod.console_clear(0)
    frame = libtcod.image_load(os.path.join('data', 'images', 'about-frame.png'))
    libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    results = ["You won, Top Dog!"]
    results.append("You moved %s times." % (player.moves))
    results.append("You drank %s puddles." % (player.quenches))
    results.append("You took %s bites." % (player.bites_taken))
    results.append("You ate %s treats." % (player.treats_eaten))
    results.append("You piddled %s times." % (player.piddles_taken))
    results.append("Your score is %s!" % (player.score))
    results.append("Well Done ^_^")
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 4,
                        libtcod.BKGND_NONE, libtcod.CENTER, "\n\n".join(results))
コード例 #10
0
def initialize_fov():
    global fov_recompute, fov_map

    libtcod.console_clear(con)  #reset console to black

    fov_recompute = True

    #create the FOV map
    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 map[x][y].block_sight,
                                       not map[x][y].blocked)
コード例 #11
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_menu():
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'intro.png'))
    libtcod.image_blit_rect(icon, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    text = [
        "version %s" % (C.VERSION)
        ,"%cA%cbout" % (C.COL1, C.COLS)
        ,"%cspace%c to continue"  % (C.COL4, C.COLS)
        ]
    libtcod.console_print_ex(0, 2, 45,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(text))
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 24,
                        libtcod.BKGND_NONE, libtcod.CENTER, 
                        "in 'The Lost Puppy'")
コード例 #12
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_help():
    """
        Show help.
    """
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'stats-frame.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 2,
                        libtcod.BKGND_NONE, libtcod.CENTER, 
                        "%cTop Dog%c\nv%s\n^_^" % (C.COL5, C.COLS, C.VERSION))
                            

#    helptext = ["%c%s%s" % (C.COL5, C.COLS, C.VERSION)]
    helptext = ["The %cPuppy%c has been kidnapped by the %cFat Cat Mafioso%c. You travel from yard to yard, searching for the crafty Cats!" % (C.COL4, C.COLS, C.COL1, C.COLS)]
    
    helptext.append("\nYou are the %c@%c sign. Walk into other animals to interact with them." % (C.COL3, C.COLS))
    helptext.append("\n%cKEYPAD%c" % (C.COL5, C.COLS))
    helptext.append("\nUse the %cKeypad%c to move, this is preferred as \
diagonals are the dog's bark. Keypad 5 shows your stats, as does [i]nfo. The %cARROW%c keys also move you." \
        % (C.COL4, C.COLS, C.COL4, C.COLS))

    helptext.append("\n%cACTIONS%c" % (C.COL5, C.COLS))
    helptext.append("\n[%cd%c]rink water" % (C.COL5, C.COLS))
    helptext.append("[%ce%c]at food" % (C.COL5, C.COLS))
    helptext.append("[%cp%c]piddle to relieve yourself" % (C.COL5, C.COLS))
    helptext.append("[%ci%c]nfo screen: stats and quests" % (C.COL5, C.COLS))

    helptext.append("\nThe keypad also map to actions, use this mnemonic to remember:")
    helptext.append("\n%cD%crink and %cD%civide\n%cE%cat and %cM%cultiply\n%cP%ciddling %cS%coothes ;)" % (C.COL1, C.COLS, C.COL1, C.COLS
                , C.COL2, C.COLS, C.COL2, C.COLS
                , C.COL3, C.COLS, C.COL3, C.COLS))

    helptext.append("\nNow go find that %cPuppy!%c" % (C.COL5, C.COLS))
    helptext.append("\nWOOF!")

    libtcod.console_print_rect(0, 4, 10, C.MAP_WIDTH - 4, C.MAP_HEIGHT - 2,
                        "\n".join(helptext))
コード例 #13
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, 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)
コード例 #14
0
ファイル: grimdungeon.py プロジェクト: mard/grimdungeon
def reset():
    global con
    init_start()
    init_mechanics()    
    libtcod.console_clear(con)
    message('Map reset\'d.')
コード例 #15
0
ファイル: grimdungeon.py プロジェクト: mard/junk
def reset():
    global con
    init_start()
    init_mechanics()
    libtcod.console_clear(con)
    message('Map reset\'d.')
コード例 #16
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
def blit_player_stats():
    """
        Draw player stats and quests screen.
    """
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'stats-frame.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    
    if player.carrying:
        if player.carrying.quest_id:
            inv_item = "%c%s%c\n%c*quest item*%c" % \
                (C.COL3, player.carrying.name, C.COLS, C.COL4, C.COLS)
        else:
            inv_item = "%c%s%c" % (C.COL3, player.carrying.name, C.COLS)
    else:
        inv_item = ""
    
    labels = (
        ""
        ,""
        ,"%clevel%c:" % (C.COL5, C.COLS)
        ,"%cscore%c:" % (C.COL5, C.COLS)
        ,"%cmoves%c:" % (C.COL5, C.COLS)
        ,"%cinventory%c:" % (C.COL5, C.COLS)
        )
    values = [
        "%cTop Dog%c" % (C.COL5, C.COLS)
        ,""
        ,str(player.level)
        ,str(player.score)
        ,str(player.moves)
        ,inv_item
    ]
    
    # name, score, inventory
    libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT, C.STATS_SCREEN_TOP,
                        libtcod.BKGND_NONE, libtcod.RIGHT, 
                        "\n".join(labels))

    libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT + 2, C.STATS_SCREEN_TOP,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(values))
    
    # quests
    values = []
    if len(player.quests) > 0:
        values = ["%cQUESTS%c\n" % (C.COL5, C.COLS)]
    for q in player.quests:
        values.append("+ %s" % (q.title))
    
    # hungry, thirsty, piddle, inventory
    if player.weak:
        values.append("+ %cweak%c, [e]at food" % (C.COL1, C.COLS))
    if player.hungry:
        values.append("+ %chungry%c, [e]at *food*" % (C.COL2, C.COLS))
    if player.thirsty:
        values.append("+ %cthirsty%c, [d]rink water" % (C.COL2, C.COLS))
    libtcod.console_print_ex(0, 4, C.SCREEN_HEIGHT / 2,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(values))

    
    
    # player hearts
    if player.weak:
        heart_colors = [libtcod.red]* 10
    else:
        heart_colors = (libtcod.red, libtcod.red, libtcod.orange, libtcod.orange
                        , libtcod.amber, libtcod.amber, libtcod.lime, libtcod.lime
                        , libtcod.chartreuse, libtcod.chartreuse)
    for heart in range(player.get_hearts()):
        libtcod.console_put_char_ex(
                        0, heart + C.STAT_HEART_LEFT, C.STAT_HEART_TOP
                        ,chr(3), heart_colors[heart], None)
コード例 #17
0
ファイル: grimdungeon.py プロジェクト: mard/grimdungeon
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)
コード例 #18
0
ファイル: grimdungeon.py プロジェクト: mard/junk
def next_level():
    global con, floor
    floor += 1
    init_mechanics()
    libtcod.console_clear(con)
    message('You have entered the next level.')
コード例 #19
0
ファイル: grimdungeon.py プロジェクト: mard/grimdungeon
def next_level():
    global con, floor
    floor += 1
    init_mechanics()
    libtcod.console_clear(con)
    message('You have entered the next level.')
コード例 #20
0
ファイル: grimdungeon.py プロジェクト: mard/junk
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)
コード例 #21
0
    def decorator(self, *args, **kwargs):
        libtcod.console_set_default_background(self.panel, libtcod.light_red)
        libtcod.console_clear(self.panel)

        func(self, *args, **kwargs)
コード例 #22
0
ファイル: topdog.py プロジェクト: wesleywerner/topdog
 
 while not libtcod.console_is_window_closed():
     state = gamestate.peek()
     if state == C.STATE_MENU:
         blit_menu()
     elif state == C.STATE_ABOUT:
         blit_about()
     elif state == C.STATE_PLAYING:
         if not player:
             player = cls.Player()
             aai = cls.ActionManual(player)
             aai.attack_rating = 10
             player.action_ai = aai
             warp_level()
         # clear our displays
         libtcod.console_clear(0)
         libtcod.console_clear(canvas)
         # draw screens
         draw_map()
         draw_player_stats()
         draw_objects()
         blit_playtime()
         draw_messages()
     elif state == C.STATE_DIALOGUE:
         blit_dialogues()
         if len(player.dialogues) > 0:
             dlg = player.dialogues[-1]
         else:
             gamestate.pop()
     elif state == C.STATE_STATS:
         blit_player_stats()