Ejemplo n.º 1
0
    def draw(self, main_map):
        #Settings
        libtcod.console_set_default_background(self.console, libtcod.black)
        libtcod.console_set_alignment(self.console, libtcod.CENTER)

        if main_map.selected_unit:
            start = (self.width - 4)/2
            #Draw all units in the unit image
            for x in range(self.width - 4):
                for y in range(self.width - 4):
                    libtcod.image_put_pixel(self.unit_image, x, y, main_map.map_list[main_map.selected_unit.x + x - start][main_map.selected_unit.y + y - start].color)
                    for u in main_map.units:
                        if u.x == (main_map.selected_unit.x + x - start) and u.y == (main_map.selected_unit.y + y - start):
                            libtcod.console_set_char_foreground(self.console, x + 2, y + 4, u.color)
                            libtcod.console_set_char(self.console, x + 2, y + 4, u.char)

            libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, False, libtcod.BKGND_NONE, main_map.selected_unit.name)
            libtcod.console_rect(self.console, 0,0, 20, 1, False)
            libtcod.image_blit_rect(self.unit_image, self.console, 2, 4, self.width - 4, self.width - 4, libtcod.BKGND_SET)

            libtcod.console_set_alignment(self.console, libtcod.LEFT)
            #Unit stats
            statx = self.width + 1
            libtcod.console_print(self.console, 2, statx, 'Speed')
            libtcod.console_print(self.console, 2, statx + 1, 'Attack')
            libtcod.console_print(self.console, 2, statx + 2, 'Armor')

            libtcod.console_set_alignment(self.console, libtcod.RIGHT)
            libtcod.console_print(self.console, self.width - 2, statx, str(main_map.selected_unit.speed))
            libtcod.console_print(self.console, self.width - 2, statx + 1, str(main_map.selected_unit.attack))
            libtcod.console_print(self.console, self.width - 2, statx + 2, str(main_map.selected_unit.armor))

            libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 1, 60 - self.height/2, 1, 0.75)
Ejemplo n.º 2
0
 def draw(self, area):
     if lt.map_is_in_fov(area.fov_map, self.col, self.row):
         lt.console_set_char_foreground(area.con, self.row, self.col, self.f_color)
         light = area.area[self.col][self.row].b_color
         if light.r > 175 and light.g > 175 and light.b > 130:
             lt.console_set_char_foreground(area.con, self.row, self.col, lt.black)
         lt.console_set_char(area.con, self.row, self.col, self.char)
Ejemplo n.º 3
0
 def print_employee(self, console, employeeType, x, y):
     color = TilePainter.employeeToColor[employeeType]
     symbol = TilePainter.EMPLOYEE_SYMBOL
     libtcod.console_set_char_foreground(console,
                                         x,
                                         y,
                                         color)
     libtcod.console_set_char(console,x,y,symbol)
Ejemplo n.º 4
0
def draw_all_tiles():
    for tile in TILES:
        tcod.console_set_char_foreground(ITEM_WINDOW,
                                         TILES.keys().index(tile), 0,
                                         TILES[tile]['color'][0])
        tcod.console_set_char_background(ITEM_WINDOW,
                                         TILES.keys().index(tile), 0,
                                         TILES[tile]['color'][1])
        tcod.console_set_char(ITEM_WINDOW,
                              TILES.keys().index(tile), 0, TILES[tile]['icon'])
Ejemplo n.º 5
0
def render_local():
    global map_, fov_recompute
    
    if len(R.map_) > R.MAP_VIEW_WIDTH:
        cam_x = scrolling_map(you.x, R.MAP_VIEW_WIDTH_HALF + 1, R.MAP_VIEW_WIDTH, R.MAP_WIDTH)
    else:
        cam_x = 0
    if len(R.map_[0]) > R.MAP_VIEW_HEIGHT:
        cam_y = scrolling_map(you.y, R.MAP_VIEW_HEIGHT_HALF, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT)
    else:
        cam_y = 0

    # cam_x = scrolling_map(you.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH)
    # cam_y = scrolling_map(you.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT)

    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(R.locale.floors[you.depth].fov_map, you.x, you.y, 10, True, 0)

        for sc_y in range(R.MAP_VIEW_HEIGHT):  #this refers to the SCREEN position. NOT map.
            for sc_x in range(R.MAP_VIEW_WIDTH):
                x = sc_x + cam_x
                y = sc_y + cam_y

                if sc_x < len(R.map_) and sc_y < len(R.map_[0]):
                        # and x < len(R.map_) and y < len(R.map_[0]):  #if it's within the bounds of the map.
                    tile = R.locale.floors[you.depth].tiles[x][y]
                    visible = libtcod.map_is_in_fov(R.locale.floors[you.depth].fov_map, x, y)
                    if not visible:
                        if tile.explored or debug_mode:
                            libtcod.console_put_char_ex(con, x, y, tile.char, libtcod.dark_green, libtcod.dark_gray)
                        else:
                            libtcod.console_put_char_ex(con, x, y, " ", libtcod.black, libtcod.black)
                        libtcod.console_set_char(con_char, x, y, " ")

                    else:
                        libtcod.console_put_char_ex(con, x, y, tile.char, libtcod.green, libtcod.light_grey)
                        libtcod.console_set_char(con_char, x, y, " ")
                        tile.explored = True
                else:
                    libtcod.console_put_char_ex(con, x, y, " ", libtcod.black, libtcod.black)

        for objects in R.locale_obj:
            #if the tile is explored, then draw the object.
            if libtcod.map_is_in_fov(R.locale.floors[you.depth].fov_map, objects.x, objects.y):
                objects.draw(cam_x, cam_y)
            #if it's explored but out of sight range - draw faded!
            elif R.locale.floors[you.depth].tiles[objects.x][objects.y].explored == True:
                objects.draw_faded(cam_x, cam_y)
        you.draw(cam_x, cam_y)

    libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0)
    libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0)
    libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0, R.MAP_VIEW_WIDTH, 0)
    libtcod.console_flush()
Ejemplo n.º 6
0
def _draw_unseen(player, screen_x, screen_y, pos, terrain, icon):
    global _con
    current_map = player.current_map
    sc = terrain.unseen_color
    if not sc:
        sc = map.region_colors_unseen[current_map.region_terrain[current_map.region[pos.x][pos.y]]]
    libtcod.console_set_char_background(_con, screen_x, screen_y, sc, libtcod.BKGND_SET)
    # _debug_region(current_map, screen_x, screen_y, pos)
    if icon:
        libtcod.console_set_char_foreground(_con, screen_x, screen_y, terrain.icon_color)
        libtcod.console_set_char(_con, screen_x, screen_y, icon)
Ejemplo n.º 7
0
    def GetChoice(self):
        command = ''
        key = libtcod.console_wait_for_keypress(True)
        while key.vk != libtcod.KEY_ENTER:
            letter = chr(key.c)
            x = len(command)
            libtcod.console_set_char(
                0, x, 0,
                letter)  #print new character at appropriate position on screen
            command = command + letter  #add to the string

            key = libtcod.console_wait_for_keypress(True)
        return command
Ejemplo n.º 8
0
 def draw(self, in_sight, area):
     if in_sight:
         lt.console_set_char_foreground(area.con, self.row, self.col, self.f_color)
         lt.console_set_char_background(area.con, self.row, self.col, self.b_color)
         lt.console_set_char(area.con, self.row, self.col, self.char)
         self.explored = True
     elif self.explored:
         f_color = lt.color_lerp(area.fog, self.f_color, area.fog_density)
         b_color = lt.color_lerp(area.fog, self.b_color, area.fog_density)
         lt.console_set_char_background(area.con, self.row, self.col, b_color)
         lt.console_set_default_foreground(area.con, f_color)
         lt.console_put_char(area.con, self.row, self.col, self.char)
     else:
         lt.console_set_char_background(area.con, self.row, self.col, area.fog)
Ejemplo n.º 9
0
def _draw_unseen(player, screen_x, screen_y, pos, terrain, icon):
    global _con
    current_map = player.current_map
    sc = terrain.unseen_color
    if not sc:
        sc = map.region_colors_unseen[current_map.region_terrain[
            current_map.region[pos.x][pos.y]]]
    libtcod.console_set_char_background(_con, screen_x, screen_y, sc,
                                        libtcod.BKGND_SET)
    # _debug_region(current_map, screen_x, screen_y, pos)
    if icon:
        libtcod.console_set_char_foreground(_con, screen_x, screen_y,
                                            terrain.icon_color)
        libtcod.console_set_char(_con, screen_x, screen_y, icon)
Ejemplo n.º 10
0
def render_right_panel():
    # clear panel
    tcod.console_set_default_background(right_panel, tcod.black)
    tcod.console_clear(right_panel)
    # drawl separating line
    for y in range(SCREEN_HEIGHT):
        tcod.console_set_char(right_panel, 0, y, 186)
    # show stats for the closest mobs to player
    # note: this includes the player
    render_stats_of_mobs(get_closest_mobs_to_player())
    # show player's stats
    # blit to root console
    tcod.console_blit(
        right_panel, 0, 0, RIGHT_PANEL_WIDTH, SCREEN_HEIGHT, 0, int(CAMERA_WIDTH), 0)
Ejemplo n.º 11
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)
    
    libtcod.console_clear(con) #Unexplored areas start as black

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            libtcod.console_set_char_background(con, x, y, libtcod.black)
            libtcod.console_set_char_foreground(con, x, y, libtcod.darker_grey)
            libtcod.console_set_char(con, x, y, map[x][y].char)
Ejemplo n.º 12
0
def render_wall(con, x, y, color):
    # TODO: Think of a better way to do this
    # TODO: Improve outside walls
    if y + 1 >= consts.MAP_HEIGHT:
        north = False
    else:
        north = Map_Tiles[x][y + 1].blocked
    if y - 1 < 0:
        south = False
    else:
        south = Map_Tiles[x][y - 1].blocked
    if x + 1 >= consts.MAP_WIDTH:
        west = False
    else:
        west = Map_Tiles[x + 1][y].blocked
    if x - 1 < 0:
        east = False
    else:
        east = Map_Tiles[x - 1][y].blocked
    if north and south and east and west:
        wall_char = libtcod.CHAR_DCROSS
    elif north and not south and east and west:
        wall_char = libtcod.CHAR_DTEES
    elif not north and south and east and west:
        wall_char = libtcod.CHAR_DTEEN
    elif north and south and east and not west:
        wall_char = libtcod.CHAR_DTEEW
    elif north and south and not east and west:
        wall_char = libtcod.CHAR_DTEEE
    elif north and not south and east and not west:
        wall_char = libtcod.CHAR_DNE
    elif north and not south and not east and west:
        wall_char = libtcod.CHAR_DNW
    elif not north and south and east and not west:
        wall_char = libtcod.CHAR_DSE
    elif not north and south and not east and west:
        wall_char = libtcod.CHAR_DSW
    elif north and south:
        wall_char = libtcod.CHAR_DVLINE
    elif east and west:
        wall_char = libtcod.CHAR_DHLINE
    else:
        wall_char = libtcod.CHAR_DCROSS
    libtcod.console_set_char_foreground(con, x, y, color)
    libtcod.console_set_char(con, x, y, wall_char)
Ejemplo n.º 13
0
	def draw(self, x, y, color_filter):
		feature = self.feature_at(x, y)
		item = self.item_at(x, y)
		actor = self.actor_at(x, y)
		
		if self.console is None:
			self.init_console()
		
		if feature:
			libtcod.console_put_char_ex(self.console, feature.x, feature.y, feature.symbol, color_filter(feature.color_fore), color_filter(feature.color_back))
		
		if item:
			libtcod.console_set_fore(self.console, item.x, item.y, color_filter(item.color))
			libtcod.console_set_char(self.console, item.x, item.y, item.symbol)
		
		if actor:
			libtcod.console_set_fore(self.console, actor.x, actor.y, color_filter(actor.color))
			libtcod.console_set_char(self.console, actor.x, actor.y, actor.symbol)
Ejemplo n.º 14
0
def draw_map(player):
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, 0, 0, 80, 40, True, libtcod.BKGND_SET)
	
	for x, y in player.fov.get_visible():
		player.memory.update(x, y)
	
	libtcod.console_blit(player.memory.console, 0, 0, 80, 40, 0, 0, 0)
	
	for feature in player.fov.get_visible_features():
		libtcod.console_put_char_ex(0, feature.x, feature.y, feature.symbol, feature.color_fore, feature.color_back)
	
	for item in player.fov.get_visible_items():
		libtcod.console_set_fore(0, item.x, item.y, item.color)
		libtcod.console_set_char(0, item.x, item.y, item.symbol)
	
	for actor in player.fov.get_visible_actors():
		libtcod.console_set_fore(0, actor.x, actor.y, actor.color)
		libtcod.console_set_char(0, actor.x, actor.y, actor.symbol)
Ejemplo n.º 15
0
def render():

    for y in range(R.SCREEN_HEIGHT):
        for x in range(R.SCREEN_WIDTH):
            #             r = int(libtcod.heightmap_get_value(map_.hm, x, y))
            #             g = int(libtcod.heightmap_get_value(map_.hm, x, y))
            if x < R.MAP_WIDTH and y < R.MAP_HEIGHT:
                b = int(map_.tiles[x][y].humidity)
                colour = libtcod.Color(0, 0, int(b))
                libtcod.console_set_char_background(con, x, y, colour)

                if len(map_.wind_gen.map[x][y]) > 0:
                    libtcod.console_set_char(con, x, y, ".")
                    libtcod.console_set_char_foreground(
                        con, x, y, libtcod.white)
                else:
                    libtcod.console_set_char_foreground(
                        con, x, y, libtcod.black)
                    libtcod.console_set_char(con, x, y, " ")

            if x >= R.MAP_WIDTH and y < R.MAP_HEIGHT:
                ax = x - R.MAP_WIDTH
                ay = y

                b = int(map_.tiles[ax][y].elevation)
                c = b
                if map_.tiles[ax][ay].type != "water":
                    c = 10
                colour = libtcod.Color(int(b), int(c), int(b))
                libtcod.console_set_char_background(con, x, y, colour)

            if x >= R.MAP_WIDTH and y >= R.MAP_HEIGHT:
                ax = x - R.MAP_WIDTH
                ay = y - R.MAP_HEIGHT
                b = int(map_.tiles[ax][ay].temperature)
                colour = libtcod.Color(int(b), int(b), int(b))
                libtcod.console_set_char_background(con, x, y, colour)

    libtcod.console_blit(con, 0, 0, R.SCREEN_WIDTH, R.SCREEN_HEIGHT, 0, 0, 0)

    libtcod.console_flush()
Ejemplo n.º 16
0
def handle_mouse():

    mouse = libtcod.mouse_get_status()

    (x, y) = (mouse.cx, mouse.cy)

    if x > R.MAP_WIDTH - 1:
        x = R.MAP_WIDTH - 1
    if y > R.MAP_HEIGHT - 1:
        y = R.MAP_HEIGHT - 1
    if x < 0:
        x = 0
    if y < 0:
        y = 0

    if x < R.MAP_WIDTH and y < R.MAP_HEIGHT:
        libtcod.console_set_char_foreground(con, x, y, libtcod.orange)
        libtcod.console_set_char(con, x, y, "#")

        ax = x + R.MAP_WIDTH
        ay = y

        libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange)
        libtcod.console_set_char(con, ax, ay, "#")

        ax = x + R.MAP_WIDTH
        ay = y + R.MAP_HEIGHT

        libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange)
        libtcod.console_set_char(con, ax, ay, "#")
Ejemplo n.º 17
0
def handle_mouse():
    
    mouse = libtcod.mouse_get_status()
    
    (x, y) = (mouse.cx, mouse.cy)

    if x > R.MAP_WIDTH - 1:
        x = R.MAP_WIDTH - 1
    if y > R.MAP_HEIGHT -  1:
        y = R.MAP_HEIGHT - 1
    if x < 0:
        x = 0
    if y < 0:
        y = 0
    
    if x < R.MAP_WIDTH and y < R.MAP_HEIGHT:
        libtcod.console_set_char_foreground(con, x, y, libtcod.orange)
        libtcod.console_set_char(con, x, y, "#")
        
        ax = x + R.MAP_WIDTH 
        ay = y
        
        
        libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange)
        libtcod.console_set_char(con, ax, ay, "#")  
        
        ax = x + R.MAP_WIDTH 
        ay = y + R.MAP_HEIGHT 
        
        libtcod.console_set_char_foreground(con, ax, ay, libtcod.orange)
        libtcod.console_set_char(con, ax, ay, "#")    
Ejemplo n.º 18
0
def draw_tile(tile,pos,color):
	_x = pos[0]-var.camera[0]
	_y = pos[1]-var.camera[1]
	
	if var.output=='libtcod':# and var.player.level.outside:
		#print var.player.level.tmap
		if var.player.level.tmap[pos[0]][pos[1]]:
			libtcod.console_set_char_background(var.tree,_x,_y,libtcod.Color(var.player.level.tmap[pos[0]][pos[1]],0,0), flag=libtcod.BKGND_SET)
	
	if var.player.level.outside:
		if tile.has_key('id'):
			_icon = False
			if var.buffer[_x][_y] == tile['id'] and var.player.level.outside: return
			else: var.buffer[_x][_y] = tile['id']
		elif tile.has_key('icon'):
			_icon = True
			if tile.has_key('limbs') and var.output=='libtcod':
				for __x in xrange(-6,7):
					for __y in xrange(-6,7):
						if tile['limbs'][__x][__y]:
							libtcod.console_set_char_background(var.tree, _x+__x, _y+__y, libtcod.Color(50,50,50), flag=libtcod.BKGND_SET)
							libtcod.console_set_char_foreground(var.tree, _x+__x, _y+__y, libtcod.Color(50,50,50))
							libtcod.console_set_char(var.tree, _x+__x, _y+__y, '#')
				
			if var.buffer[_x][_y] == tile['icon'] and var.player.level.outside: return
			else: var.buffer[_x][_y] = tile['icon']
	
	var.dirty.append((_x,_y))
	
	if isinstance(tile['icon'],unicode):
		tile['icon'] = str(tile['icon'])
	
	if var.output=='pygame':
		var.view.putchar(tile['icon'],x=_x,y=_y,fgcolor=color[0],bgcolor=color[1])
	else:
		_color = (var.color_codes[color[0]],var.color_codes[color[1]])
		if not var.player.level.outside:
			libtcod.console_set_char_background(var.view, _x, _y, libtcod.Color(_color[1][0],_color[1][1],_color[1][2]), flag=libtcod.BKGND_SET)
		libtcod.console_set_char_foreground(var.view, _x, _y, libtcod.Color(_color[0][0],_color[0][1],_color[0][2]))
		libtcod.console_set_char(var.view, _x, _y, tile['icon'])
Ejemplo n.º 19
0
def render(mouse):
    libtcod.console_clear(0)
    libtcod.console_clear(unit_panel.console)
    main_map.draw(0, cam)
    
    #unit_panel rendering

    #unit rendering
    libtcod.console_set_alignment(0, libtcod.CENTER)
    libtcod.console_set_default_background(0, libtcod.black)

    for u in main_map.units:
    	u.draw(0,cam)
        #Draw name function
        if (u.x == mouse.cx + cam.x and u.y == mouse.cy + cam.y) or u == main_map.selected_unit:
            libtcod.console_print(0, u.x - cam.x, u.y - cam.y -1, u.name)
            #Draw the destination if moving
            x,y = libtcod.path_get_destination(u.path)
            if not libtcod.path_is_empty(u.path):
        	    libtcod.console_set_char(0, x - cam.x, y - cam.y, libtcod.CHAR_ARROW_S)
    
    unit_panel.draw(main_map)
Ejemplo n.º 20
0
def render():
    
    for y in range(R.SCREEN_HEIGHT): 
        for x in range(R.SCREEN_WIDTH):
#             r = int(libtcod.heightmap_get_value(map_.hm, x, y))
#             g = int(libtcod.heightmap_get_value(map_.hm, x, y))
            if x < R.MAP_WIDTH and y < R.MAP_HEIGHT:
                b = int(map_.tiles[x][y].humidity)
                colour = libtcod.Color(0,0,int(b))
                libtcod.console_set_char_background(con, x, y, colour)
                
                if len(map_.wind_gen.map[x][y]) > 0:
                    libtcod.console_set_char(con,x,y,".")
                    libtcod.console_set_char_foreground(con, x, y, libtcod.white)
                else:
                    libtcod.console_set_char_foreground(con, x, y, libtcod.black)
                    libtcod.console_set_char(con, x, y, " ")
                    
            if x >= R.MAP_WIDTH and y < R.MAP_HEIGHT:
                ax = x - R.MAP_WIDTH 
                ay = y
                
                b = int(map_.tiles[ax][y].elevation)
                c = b
                if map_.tiles[ax][ay].type != "water":
                    c = 10
                colour = libtcod.Color(int(b),int(c),int(b))
                libtcod.console_set_char_background(con, x, y, colour)
                    
            if x >= R.MAP_WIDTH and y >= R.MAP_HEIGHT:
                ax = x - R.MAP_WIDTH
                ay = y - R.MAP_HEIGHT 
                b = int(map_.tiles[ax][ay].temperature)
                colour = libtcod.Color(int(b),int(b),int(b))
                libtcod.console_set_char_background(con, x, y, colour)
                    
    libtcod.console_blit(con, 0, 0, R.SCREEN_WIDTH, R.SCREEN_HEIGHT, 0, 0, 0)
    
    libtcod.console_flush()
Ejemplo n.º 21
0
def render_bottom_panel():
    # fill it with black
    tcod.console_set_default_background(bottom_panel, tcod.black)
    tcod.console_clear(bottom_panel)
    tcod.console_set_default_foreground(bottom_panel, tcod.white)
    # draw separating line
    for x in range(BOTTOM_PANEL_WIDTH):
        tcod.console_set_char(bottom_panel, x, 0, 205)
    # draw distance traveled
    tcod.console_print(bottom_panel, 1, 1, 'DISTANCE:' +
                       str(terrain.map.scroll_amount + game.player.x))
    # render player stats
    tcod.console_print(bottom_panel, 1, 4, 'Strength: ' +
                       str(game.player.strength))
    tcod.console_print(bottom_panel, 1, 5, 'Defense: ' +
                       str(game.player.defense))
    tcod.console_print(bottom_panel, 1, 7, '[z]' +
                       str(game.player.inventory[0].name))
    tcod.console_print(bottom_panel, 1, 9, '[x]' +
                       str(game.player.inventory[1].name))
    tcod.console_print(bottom_panel, 1, 11, '[c]' +
                       str(game.player.inventory[2].name))
    tcod.console_set_default_foreground(bottom_panel, tcod.cyan)
    tcod.console_print(bottom_panel, 4, 8,
                       str(game.player.inventory[0].mana_use) + ' mana')
    tcod.console_print(bottom_panel, 4, 10,
                       str(game.player.inventory[1].mana_use) + ' mana')
    tcod.console_print(bottom_panel, 4, 12,
                       str(game.player.inventory[2].mana_use) + ' mana')
    tcod.console_set_alignment(bottom_panel, tcod.LEFT)
    # render game messages
    render_messages()
    # render object and tile names under mouse
    tcod.console_set_default_foreground(bottom_panel,
                                        tcod.light_gray)
    tcod.console_print(bottom_panel, 1, 0, game.get_names_under_mouse())
    tcod.console_blit(
        bottom_panel, 0, 0, BOTTOM_PANEL_WIDTH,
        BOTTOM_PANEL_HEIGHT, 0, 0, SCREEN_HEIGHT - BOTTOM_PANEL_HEIGHT)
Ejemplo n.º 22
0
def render_wilderness():
    global cam_x, cam_y
    #clear the city locations using OLD cam position.
    for city in R.cities:
        loc = R.tiles[city.x][city.y]
        colour = loc.bg
        libtcod.console_set_char_background(con, cam_x + city.x, cam_y + city.y, colour, libtcod.BKGND_SET)
        libtcod.console_set_char(con, cam_x + city.x, cam_y + city.y, ord(' '))

    cam_x = scrolling_map(you.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH)
    cam_y = scrolling_map(you.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT)
    #now draw the map!
    for y in range(min(R.MAP_VIEW_HEIGHT, len(R.world.tiles[0]))):  #this refers to the SCREEN position. NOT map.
        for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))):
            map_pos_x = x + cam_x
            map_pos_y = y + cam_y
            if map_pos_x >= R.MAP_WIDTH:
                continue
            if map_pos_y >= R.MAP_HEIGHT:
                continue

            tile = R.world.tiles[map_pos_x][map_pos_y]
            #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y)
            visible = True
            if not visible:
                pass  #TODO: re-do the visible/ not visible code.
                #if it"s not visible right now, the player can only see it if it"s explored
                #if tile.explored:
                #if wall:
                #    libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                #    libtcod.console_set_char(con, x, y, " ")
                #else:
                #    libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                #    libtcod.console_set_char(con, x, y, " ")
            else:
                colour = tile.bg
                libtcod.console_set_char(con, x, y, " ")
                libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET)
Ejemplo n.º 23
0
def input(typ, con, posx, posy, min=0, max=100):
	command = ''
	x = 0
	done = False
	key = libtcod.Key()
	while done is False:
		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
		if key.vk == libtcod.KEY_BACKSPACE and x > 0:
			libtcod.console_set_char(con, x + posx - 1, posy, chr(95))
			libtcod.console_set_char_foreground(con, x + posx - 1, posy, libtcod.white)
			libtcod.console_set_char(con, x + posx, posy, ' ')
			command = command[:-1]
			x -= 1
		elif key.vk == libtcod.KEY_ENTER:
			if not len(command) in range(min, max):
				libtcod.console_set_default_foreground(0, libtcod.dark_red)
				libtcod.console_print(con, 2, posy + 2, 'Player name must be between ' + str(min) + ' to ' + str(max - 1) + ' characters!')
			elif typ == 'chargen':
				if command.lower() in game.savefiles:
					libtcod.console_set_default_foreground(0, libtcod.dark_red)
					libtcod.console_rect(con, 2, posy + 2, 50, 1, True)
					libtcod.console_print(con, 2, posy + 2, 'That name already exist!')
				else:
					done = True
			else:
				done = True
		elif key.c in range(32, 127) and len(command) < 20:
			libtcod.console_set_char(con, x + posx, posy, chr(key.c))  # print new character at appropriate position on screen
			libtcod.console_set_char_foreground(con, x + posx, posy, libtcod.light_red)
			libtcod.console_set_char(con, x + posx + 1, posy, chr(95))
			libtcod.console_set_char_foreground(con, x + posx + 1, posy, libtcod.white)
			command += chr(key.c)  # add to the string
			x += 1

		libtcod.console_blit(con, 0, 0, game.SCREEN_WIDTH, game.SCREEN_HEIGHT, 0, 0, 0)
		libtcod.console_flush()
	return command
Ejemplo n.º 24
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 = level_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 level_map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_foreground(con, x, y, color_dark_wall)
                            libtcod.console_set_char(con, x, y, wall_tile)

                        else:
                            libtcod.console_set_char_foreground(con, x, y, color_dark_ground)
                            libtcod.console_set_char(con, x, y, floor_tile)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char_foreground(con, x, y, color_light_wall)
                        libtcod.console_set_char(con, x, y, wall_tile)
                    else:
                        libtcod.console_set_char_foreground(con, x, y, color_light_ground)
                        libtcod.console_set_char(con, x, y, floor_tile)
                    #since it's visible, explore it
                    level_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(panel, MSG_X, y, line)
        y += 1

    #show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.combatant[0].hp, player.combatant[0].max_hp,
        libtcod.light_red, libtcod.darker_red)
    libtcod.console_print(panel, 1, 3, 'Dungeon level ' + str(dungeon_level))

    #display names of objects under the mouse
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print(panel, 1, 0, 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)
Ejemplo n.º 25
0
 def display_char(self, console, x, y, char):
     libtcod.console_set_char(console, x, y, char)
Ejemplo n.º 26
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    #global fov_recompute

    if GameState.lighting_recompute or GameState.fov_recompute:
        for y in range(cfg.MAP_HEIGHT):
                for x in range(cfg.MAP_WIDTH):
                    GameState.player.floor.Tiles[x][y].currentLight = lightsOffValue

        for o in GameState.objects:
            if (o.lightSource != None):
                libtcod.map_clear(GameState.fov_light_map)
                libtcod.map_compute_fov(GameState.fov_map, o.x, o.y, 0, cfg.FOV_LIGHT_WALLS, cfg.FOV_ALGO)
            else:
                continue
            for y in range(cfg.MAP_HEIGHT):
                for x in range(cfg.MAP_WIDTH):
                    visible = libtcod.map_is_in_fov(GameState.fov_map, x, y)
                    wall = GameState.player.floor.Tiles[x][y].block_sight
                    distance = math.sqrt(pow(o.x - x,2) + pow(o.y - y,2))
                    if visible:
                        #it's visible
                        if wall:
                            if distance != 0:
                                GameState.player.floor.Tiles[x][y].currentLight += o.lightSource.value / distance
                            else:
                                GameState.player.floor.Tiles[x][y].currentLight += o.lightSource.value / 1
                        else:
                            if distance != 0:
                                GameState.player.floor.Tiles[x][y].currentLight += o.lightSource.value / distance
                            else:
                                GameState.player.floor.Tiles[x][y].currentLight += o.lightSource.value / 1
                            #since it's visible, explore it
                        #GameState.player.floor.Tiles[x][y].explored = True
        GameState.lighting_recompute = False
        GameState.fov_recompute = True

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

        #go through all tiles, and set their background color according to the FOV
        for y in range(cfg.MAP_HEIGHT):
            for x in range(cfg.MAP_WIDTH):
                light = Lights.LightValue()
                visible = libtcod.map_is_in_fov(GameState.fov_map, x, y)
                wall = GameState.player.floor.Tiles[x][y].block_sight
                light = GameState.player.floor.Tiles[x][y].currentLight + GameState.player.floor.Tiles[x][y].NaturalLight
                if light.Brightness < 1:
                    visible = False
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    if GameState.player.floor.Tiles[x][y].explored:
                        if wall:
                            libtcod.console_set_default_foreground(cfg.con, libtcod.Color(255,255,255))
                            libtcod.console_set_char_background(cfg.con, x, y, libtcod.Color(0,0,0), libtcod.BKGND_SET)
                            libtcod.console_set_char(cfg.con, x, y,"#")
                        else:
                            libtcod.console_set_char_background(cfg.con, x, y, libtcod.Color(0,0,0), libtcod.BKGND_SET)
                            libtcod.console_set_default_foreground(cfg.con, libtcod.Color(255,255,255))
                            libtcod.console_set_char(cfg.con, x, y,".")
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_char(cfg.con, x, y," ")
                        libtcod.console_set_char_background(cfg.con, x, y, (light/2).lightToLibtcodColor(), libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_char(cfg.con, x, y," ")
                        libtcod.console_set_char_background(cfg.con, x, y, light.lightToLibtcodColor(), libtcod.BKGND_SET )
                        #since it's visible, explore it
                    if(light.Brightness >= 1):
                        GameState.player.floor.Tiles[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 GameState.objects:
        if object != GameState.player:
            object.draw()
    GameState.player.draw()

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


    #prepare to render the GUI panel
    libtcod.console_set_default_background(cfg.panel, libtcod.black)
    libtcod.console_clear(cfg.panel)

    #print the game messages, one line at a time
    y = 1
    for (line, color) in GameState.game_msgs:
        libtcod.console_set_default_foreground(cfg.panel, color)
        libtcod.console_print_ex(cfg.panel, cfg.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT,line)
        y += 1

    #show the player's stats
    #TODO: Fix HP Bar
    render_bar(1, 1, cfg.BAR_WIDTH, 'HP', GameState.player.entity.hitPoints, GameState.player.entity.maxHitPoints,
               libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(cfg.panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level ' + str(GameState.dungeon.floors.index(GameState.player.floor)))

    #display names of objects under the mouse
    libtcod.console_set_default_foreground(cfg.panel, libtcod.light_gray)
    #libtcod.console_print_ex(cfg.panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse())
    libtcod.console_print_ex(cfg.panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_light_under_mouse())

    #blit the contents of "panel" to the root console
    libtcod.console_blit(cfg.panel, 0, 0, cfg.SCREEN_WIDTH, cfg.PANEL_HEIGHT, 0, 0, cfg.PANEL_Y)
Ejemplo n.º 27
0
def render_all():
    global cam_x, cam_y, selected

    #clear the city locations using OLD cam position.
    for city in R.cities:
        loc = R.tiles[city.x][city.y]
        colour = loc.bg
        libtcod.console_set_char_background(con, cam_x + city.x, cam_y + city.y, colour, libtcod.BKGND_SET)
        libtcod.console_set_char(con, cam_x + city.x, cam_y + city.y, ord(' '))

    #clear position of old object
    for objects in R.world_obj:
        objects.clear(cam_x, cam_y)

    #find the NEW camera position
    cam_x = scrolling_map(you.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH)
    cam_y = scrolling_map(you.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT)


    #now draw the map!

    #this x and y refers to the SCREEN position. NOT map.
    for y in range(min(R.MAP_VIEW_HEIGHT, len(R.world.tiles[0]))):
        for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))):

            #find out *actual" map-pos
            map_pos_x = x + cam_x
            map_pos_y = y + cam_y

            #skip if out of bounds
            if map_pos_x >= R.MAP_WIDTH:
                continue
            if map_pos_y >= R.MAP_HEIGHT:
                continue

            tile = R.world.tiles[map_pos_x][map_pos_y]

            #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y)
            visible = True
            #wall = tile.block_sight

            if not visible:
                pass #TODO: re-do the visible/ not visible code.
                #if it"s not visible right the player can only see it if it"s explored
                #if tile.explored:
                    #if wall:
                    #    libtcod.console_set_char_backgrnow, ound(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                    #    libtcod.console_set_char(con, x, y, " ")
                    #else:
                    #    libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                    #    libtcod.console_set_char(con, x, y, " ")
            else:
                #it"s visible
                if tile.POI is None:
                    if traffic:  # for b&w image.
                        v = world.get_foot_traffic(map_pos_x, map_pos_y)
                        colour = libtcod.Color(v, v, v)
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, " ")

                    elif temperature:  # for b&w image.
                        v = world.get_temperature(map_pos_x, map_pos_y)
                        v = int(v)
                        colour = libtcod.Color(v, v, v)
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, " ")

                    elif continent:
                        m = 255 / len(R.world.continents)
                        if tile.type != "water":
                            v = tile.continent * m
                            colour = libtcod.Color(v, v, v)
                        else:
                            colour = tile.bg
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, " ")

                    elif pathfinding:


                        char = " "
                        if len(selected) > 0 and hasattr(selected[0], "ai") and selected[0].ai is not None: # and selected[0].ai.pather.end is not None:
                            if path_to_draw == 3:
                                draw_path =  selected[0].ai.path3
                                pather = selected[0].ai.pather3
                            elif path_to_draw == 2:
                                draw_path =  selected[0].ai.path2
                                pather = selected[0].ai.pather2
                            else:
                                draw_path =  selected[0].ai.path
                                pather = selected[0].ai.pather

                            loc = (map_pos_x,map_pos_y)
                            loc_str = str(loc)
                            if path_to_draw < 3 and pather.node_costs.has_key(loc_str):
                                v = float(pather.node_costs[loc_str])
                                v /= pather.largest_cost
                                v = int( v * 255 )
                                colour = libtcod.Color(v, v, v)

                                if loc in draw_path:
                                    char = "." #path tile

                            elif path_to_draw == 3 and pather.node_costs.has_key(loc): #todo: hack for old pather, remove!!!
                                v = float(pather.node_costs[loc])
                                v /= pather.largest_cost
                                v = int( v * 255 )
                                colour = libtcod.Color(v, v, v)

                                if loc in draw_path:
                                    char = "." #path tile
                            else:
                                if tile.type == "water":
                                    colour = libtcod.Color(0, 10, 100)
                                elif tile.type == "grass":
                                    colour = libtcod.Color(0, 100, 10)
                                elif tile.type == "coast":
                                    colour = libtcod.Color(50, 10, 100)
                                elif tile.type == "path":
                                    colour = libtcod.Color(10, 60, 200)
                                else:
                                    colour = libtcod.Color(100, 10, 0)
                        else:
                            if tile.type == "water":
                                colour = libtcod.Color(0, 10, 100)
                            elif tile.type == "grass":
                                colour = libtcod.Color(0, 100, 10)
                            elif tile.type == "coast":
                                colour = libtcod.Color(50, 10, 100)
                            elif tile.type == "path":
                                colour = libtcod.Color(10, 60, 200)
                            else:
                                colour = libtcod.Color(100, 10, 0)
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, char)

                    else:
                        libtcod.console_set_char(con, x, y, " ")
                        libtcod.console_set_char_background(con, x, y, tile.bg, libtcod.BKGND_SET)
                        #libtcod.console_set_char_foreground(con, x, y, libtcod.black)
                        #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET)
                else:
                    libtcod.console_set_char_background(con, x, y, tile.POI.colour, libtcod.BKGND_SET)
                    libtcod.console_set_char_foreground(con, x, y, libtcod.white)
                    libtcod.console_set_char(con, x, y, tile.POI.char)
                #since it"s visible, explore it
                tile.explored = True

    #now draw all the merchants
    for city in cities:
        for merchant in city.trade_house.caravans_out:
            merchant.draw(cam_x, cam_y)
    for objects in R.world_obj:
        if objects.ai:
            # objects.clear(cam_x, cam_y)
            objects.draw(cam_x, cam_y)
    you.draw(cam_x, cam_y)



    #libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse())         
    # libtcod.console_set_default_background(con, libtcod.white)
    libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0)
    libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0)
    libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0, R.MAP_VIEW_WIDTH, 0)
    libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0, R.MAP_VIEW_WIDTH, R.PANEL_Y)
    libtcod.console_flush()
Ejemplo n.º 28
0
 def set_symbol(self, position, icon, console=0):
     x, y = position
     libtcod.console_set_char(console, x, y, icon)
Ejemplo n.º 29
0
def render_all(con, panel, game_map, entities, player, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, tile_data, game_state):

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    if fov_recompute:
        stairs_x, stairs_y = stairs_location(entities)

        for y in range(game_map.height):
            for x in range(game_map.width):

                visible = lc.map_is_in_fov(fov_map, x, y)

                if visible:
                    lc.console_set_char_background(
                        con, x, y,
                        tile_data.get(game_map.tiles[x][y].terrain)['light'],
                        lc.BKGND_SET)
                    if not (y == stairs_y and x == stairs_x):
                        lc.console_set_char_foreground(
                            con, x, y,
                            tile_data.get(
                                game_map.tiles[x][y].terrain)['dark'])
                        lc.console_set_char(con, x, y,
                                            chr(game_map.tiles[x][y].texture))
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    # lc.console_put_char(con,x,y,chr(game_map.tiles[x][y].texture),lc.BKGND_NONE)

                    lc.console_set_char_background(
                        con, x, y,
                        tile_data.get(game_map.tiles[x][y].terrain)['dark'],
                        lc.BKGND_SET)
                    if not (y == stairs_y and x == stairs_x):
                        lc.console_set_char_foreground(con, x, y, lc.black)
                        lc.console_set_char(con, x, y,
                                            chr(game_map.tiles[x][y].texture))

    lc.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    lc.console_set_default_background(panel, lc.black)
    lc.console_clear(panel)

    y = 1
    for message in message_log.messages:
        lc.console_set_default_foreground(panel, message.colour)
        lc.console_print_ex(panel, message_log.x, y, lc.BKGND_NONE, lc.LEFT,
                            message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.health,
               player.fighter.max_health, lc.red, lc.darker_red)
    lc.console_print_ex(panel, 1, 3, lc.BKGND_NONE, lc.LEFT,
                        'Dungeon Level: {0}'.format(game_map.floor))

    lc.console_set_default_background(panel, lc.light_gray)
    lc.console_print_ex(panel, 1, 0, lc.BKGND_NONE, lc.LEFT,
                        get_names_under_mouse(mouse, entities, fov_map))

    lc.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it or Esc to cancel. \n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 30
0
 def draw_entity(self, entity):
     lbt.console_set_char(self.console,
                          entity.x,
                          entity.y,
                          entity.char)
Ejemplo n.º 31
0
def _debug_region(current_map, screen_x, screen_y, pos):
    global _con
    libtcod.console_set_char(_con, screen_x, screen_y, chr(65 + (current_map.region[pos.x][pos.y] % 26)))
Ejemplo n.º 32
0
def _debug_elevation(current_map, screen_x, screen_y, pos):
    global _con
    libtcod.console_set_char(_con, screen_x, screen_y,
                             chr(48 + current_map.region_elevations[current_map.region[pos.x][pos.y]]))
Ejemplo n.º 33
0
def draw_all_tiles():
	for tile in TILES:
		tcod.console_set_char_foreground(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['color'][0])
		tcod.console_set_char_background(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['color'][1])
		tcod.console_set_char(ITEM_WINDOW, TILES.keys().index(tile), 0, TILES[tile]['icon'])
Ejemplo n.º 34
0
 def console_set_char(self,con,x,y,chr):
     if con == 0:
         libtcod.console_set_char(con,x,y,chr)
     else:
         libtcod.console_set_char(self.mConsole[con-1],x,y,chr)
Ejemplo n.º 35
0
 def print_employee(self, console, employeeType, x, y):
     color = TilePainter.employeeToColor[employeeType]
     symbol = TilePainter.EMPLOYEE_SYMBOL
     libtcod.console_set_char_foreground(console, x, y, color)
     libtcod.console_set_char(console, x, y, symbol)
Ejemplo n.º 36
0
	player_screen_pos = player_x-offset_x,player_y-offset_y
	for y,row in enumerate(levelmap[offset_y:offset_y+Settings.SCREEN_HEIGHT]):
		for x,cell in enumerate(row[offset_x:offset_x+Settings.SCREEN_WIDTH]):
			color,char,bgcolor = mapping.get(cell, (libtcod.Color(0,0,0),' ',libtcod.Color(0,0,0)))

			color = lm.get_color(level, x+offset_x, y+offset_y, color)
			bgcolor = lm.get_color(level, x+offset_x, y+offset_y, bgcolor)

			if (x,y) == player_screen_pos:
				color = libtcod.Color(128,128,100)
				char = '\x01'


			libtcod.console_set_char_foreground(con, x,y, color)
			libtcod.console_set_char_background(con, x,y, bgcolor)
			libtcod.console_set_char(con,x,y,char)

	print 'draw loop:', time.time()-t1

	libtcod.console_print(message_con, 0,1,lm.get_tile_type(level, player_x,player_y)[0])
	libtcod.console_blit(message_con, 0,0, Settings.SCREEN_WIDTH,2, 0, 0,Settings.DISPLAY_HEIGHT-2)

	blit_x,blit_y = 0,0
	blit_w,blit_h = Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT
	if blit_x + MAP_X < Settings.SCREEN_WIDTH:
		blit_x = (Settings.SCREEN_WIDTH - (blit_x + MAP_X))/2
		blit_x = int(blit_x)
		blit_w = MAP_X
	if blit_y + MAP_Y < Settings.SCREEN_HEIGHT:
		blit_y = (Settings.SCREEN_HEIGHT - (blit_y + MAP_Y))/2
		blit_y = int(blit_y)
Ejemplo n.º 37
0
def test_console_set_char(console, ch):
    libtcodpy.console_set_char(console, 0, 0, ch)
    assert_char(console, 0, 0, ch=ch)
Ejemplo n.º 38
0
def render_all():
    global cam_x, cam_y

    #clear the city locations using OLD cam position.
    for city in R.cities:
        loc = R.tiles[city.x][city.y]
        colour = loc.bg
        libtcod.console_set_char_background(con, cam_x + city.x,
                                            cam_y + city.y, colour,
                                            libtcod.BKGND_SET)
        libtcod.console_set_char(con, cam_x + city.x, cam_y + city.y, ord(' '))

    cam_x = scrolling_map(player.x, R.MAP_VIEW_WIDTH / 2, R.MAP_VIEW_WIDTH,
                          R.MAP_WIDTH)
    cam_y = scrolling_map(player.y, R.MAP_VIEW_HEIGHT / 2, R.MAP_VIEW_HEIGHT,
                          R.MAP_HEIGHT)
    #now draw the map!
    for y in range(min(R.MAP_VIEW_HEIGHT, len(
            R.world.tiles[0]))):  #this refers to the SCREEN position. NOT map.
        for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))):
            map_pos_x = x + cam_x
            map_pos_y = y + cam_y
            if map_pos_x >= R.MAP_WIDTH:
                map_pos_x = R.MAP_WIDTH - 1
            if map_pos_y >= R.MAP_HEIGHT:
                map_pos_y = R.MAP_HEIGHT - 1

            tile = R.world.tiles[map_pos_x][map_pos_y]
            #===============================================================
            # try:
            #    tile = map[map_pos_x][map_pos_y]
            # except:
            #    print str(map_pos_x) + " or " + str(map_pos_y) + " is out of bounds."
            #    break
            #===============================================================

            #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y)
            visible = True
            #wall = tile.block_sight

            if not visible:
                pass  #TODO: re-do the visible/ not visible code.
                #if it"s not visible right now, the player can only see it if it"s explored
                #if tile.explored:
                #if wall:
                #    libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                #    libtcod.console_set_char(con, x, y, " ")
                #else:
                #    libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                #    libtcod.console_set_char(con, x, y, " ")
            else:
                #it"s visible
                if tile.POI is None:
                    if traffic:  # for b&w image.
                        v = world.get_foot_traffic(map_pos_x, map_pos_y)
                        colour = libtcod.Color(v, v, v)
                        libtcod.console_set_char_background(
                            con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, " ")

                    elif temperature:  # for b&w image.
                        v = world.get_temperature(map_pos_x, map_pos_y)
                        v = int(v)
                        colour = libtcod.Color(v, v, v)
                        libtcod.console_set_char_background(
                            con, x, y, colour, libtcod.BKGND_SET)
                        libtcod.console_set_char(con, x, y, " ")

                    else:
                        colour = tile.bg
                        libtcod.console_set_char(con, x, y, " ")
                        libtcod.console_set_char_background(
                            con, x, y, colour, libtcod.BKGND_SET)
                    #libtcod.console_set_char_foreground(con, x, y, libtcod.black)
                    #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET)
                else:
                    libtcod.console_set_char_background(
                        con, x, y, tile.POI.colour, libtcod.BKGND_SET)
                    libtcod.console_set_char_foreground(
                        con, x, y, libtcod.white)
                    libtcod.console_set_char(con, x, y, tile.POI.char)
                #since it"s visible, explore it
                tile.explored = True

    #now draw the mini map
    for cell_x in range(len(world.mini_map)):
        for cell_y in range(len(world.mini_map[cell_x])):
            colour = world.mini_map[cell_x][cell_y].bg
            libtcod.console_set_char_background(minmap, cell_x, cell_y, colour,
                                                libtcod.BKGND_SET)
            #libtcod.console_set_char_foreground(con, x, y, libtcod.white)

#    for char in R.world_obj:
#        if char != player:
#            char.draw(cam_x, cam_y)

#now draw all the merchants
    for city in cities:
        for merchant in city.trade_house.caravans_out:
            merchant.draw(cam_x, cam_y)
    for objects in R.world_obj:
        if objects.ai:
            objects.clear(cam_x, cam_y)
            objects.draw(cam_x, cam_y)
    player.draw(cam_x, cam_y)

    libtcod.console_clear(message_bar)
    libtcod.console_set_default_foreground(message_bar, libtcod.white)
    libtcod.console_print_ex(
        message_bar, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT,
        str(date[0]) + " " + str(date[1][2]) + " " + str(date[1][0]) + " " +
        str(date[2][0]))
    # print the messages, one line at a time.
    y = 2
    for (line, colour) in R.game_msgs:
        libtcod.console_set_default_foreground(message_bar, colour)
        libtcod.console_print_ex(message_bar, R.MSG_X, R.MSG_HEIGHT - y,
                                 libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1


#    y = 0
#    for y in range(R.MAP_HEIGHT):
#        for x in range(R.MAP_WIDTH):
#            libtcod.console_set_char_background(con, x, y, map_[x][y].bg, libtcod.BKGND_SET)

#libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse())

    libtcod.console_set_default_background(con, libtcod.white)
    libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0,
                         0)
    #libtcod.console_blit(con, mini_map_x, mini_map_y, mini_map_x+ mini_map_width, mini_map_y +mini_map_height, 0, 0, 0)
    libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT,
                         0, 0, 0, 1.0, 0.0)
    libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0,
                         R.MAP_VIEW_WIDTH, 0)
    libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0,
                         R.MAP_VIEW_WIDTH, R.PANEL_Y)
    libtcod.console_blit(message_bar, 0, 0, R.PANEL_WIDTH, R.PANEL_HEIGHT, 0,
                         0, R.PANEL_Y)
    libtcod.console_flush()
Ejemplo n.º 39
0
 def refresh(self):
     # First, handle the flow of combat or the active animation.
     if self.animPhase == 2: # If the blinking box phase is active, handle that.
         if time.time() >= self.animStarted + 0.5: # If a second has passed since this animation phase started, end it.
             self.animPhase = 0
             if self.checkBattleStatus() != None: # If the battle is won or lost, change the current scene.
                 return self.checkBattleStatus()
             self.advanceTurn() # Move to the next turn.
     else: # If there is no animation going on, handle the flow of combat.
         if self.turnOrder[0].isAI(): # If it's an enemy's turn, act according to their AI.
             self.parseTurnResults(self.turnOrder[0].aiAct(self.party,self.enemies)) # Execute the enemy AI, thne add the result to the log.
         elif len(self.moveBoxes) == 0: # Otherwise, it must be the player's turn. If there aren't any move boxes open, open one.
             self.moveBoxes.append(bx.SelectBox(22,3,-1,-1,None,self.turnOrder[0].getOptions(),-1))
     # Now on to the actual display.
     rl.console_clear(0) # Fill the window with the background color.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes. Only the boxes themselves for now.
         if len(self.party) <= i or self.party[i].isDead(): # Draw a gray box if party member is not present or dead.
             box.draw(rl.darker_gray)
         else: # Otherwise, draw normal stats, aside from the bars.
             rl.console_print(0, 12, i*6+1, self.party[i].getHPLine()) # Draw HP.
             rl.console_print(0, 12, i*6+2, self.party[i].getAPLine()) # Draw AP.
             rl.console_print(0, 12, i*6+3, self.party[i].getMPLine()) # Draw MP.
             rl.console_print(0, 2, i*6+4, self.party[i].getStatusLine(18)) # Draw status effects.
         if len(self.party) <= i or self.party[i].getHP() <= 0: # Draw a red box if party member is unconscious.
             box.draw(rl.darker_red)
         elif self.animPhase == 2 and (self.animTarget == i or self.animTarget == ALL_ALLIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             pass
         else: # Otherwise, draw the normal party box.
             box.draw(rl.sky)
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes. Only the boxes themselves for now.
         if len(self.enemies) <= i or self.enemies[i].getHP() <= 0: # Draw a gray box if enemy is not present or KO'd.
             box.draw(rl.darker_gray)
         elif self.animPhase == 2 and (self.animTarget - 4 == i or self.animTarget == ALL_ENEMIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
         else:
             box.draw(rl.crimson) # Otherwise, draw the normal party box.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
     self.infoBox.draw(rl.white) # Draw the combat log box.
     self.turnBox.draw(rl.white) # Draw the X's Turn box.
     rl.console_print_ex(0, 31, 1, rl.BKGND_NONE, rl.CENTER, "{0}".format(self.turnOrder[0].getColoredName())) # Draw whose turn it is.
     numBattlers = 0 # The number of conscious actors in the fight that will be shown in the turn order box (as such, this should never exceed 7).
     actorList = "" # The list of conscious actors in the fight, in the order they appear in turnOrder.
     for actor in self.turnOrder: # For each actor...
         if numBattlers < 8 and actor.getHP() > 0: # If they're conscious and the turn order box isn't already filled up...
             numBattlers += 1 # Increase the size of the box by one.
             actorList += actor.getColoredName()+"\n" # Add the battler to the list.
     self.turnOrderBox.setHeight(numBattlers+2) # Adjust the turn order box's size to match the amount of conscious battlers.
     self.turnOrderBox.draw(rl.white) # Draw the turn order box.
     rl.console_set_char(0, 42, 1, ">") # Draw the cursor in the turn order box. Purely aesthetic.
     rl.console_print(0, 44, 1, actorList) # Draw the list of conscious battlers in the turn order box.
     y = 11 # The line to draw the current log entry at.
     for msg in self.log: # Draw the lines of the log, advancing y as appropriate.
         rl.console_set_char(0, 24, y, ">") # Draw something to indicate when a log line starts. This ensures it is clear when one entry ends and a new one begins.
         rl.console_print_rect(0, 26, y, 31, 12, msg) # Draw the log line.
         y += rl.console_get_height_rect(0, 0, 0, 31, 12, msg) # Lower the y coordinate.
     # Once all that is drawn, draw the background image.
     rl.image_blit_rect(self.image, 0, 0, 0, 80, 24, rl.BKGND_SET) # Display the battle background image.
     rl.console_set_default_foreground(0, rl.white) # Sets the foreground (text) color to white.
     rl.console_set_default_background(0, rl.black) # Sets the background color to black.
     # However, only after that should the actual stats be drawn. This is so the life bar backgrounds can override the background image.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes.
         if not len(self.party) <= i and not self.party[i].isDead(): # Don't draw stats if party member is not present or dead (should still show if merely KO'd.
             rl.console_print(0, 2, i*6+1, self.party[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 2, i*6+2, self.party[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 2, i*6+3, self.party[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes.
         if not len(self.enemies) <= i and not self.enemies[i].getHP() <= 0: # Don't draw stats if enemy is not present or KO'd.
             rl.console_print(0, 61, i*4+1, self.enemies[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 67, i*4+1, self.enemies[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 73, i*4+1, self.enemies[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.moveBoxes): # Draw all the move boxes, the current one being yellow. Since this can overlap the enemy stats, this must be drawn after that.
         if i+1 == len(self.moveBoxes):
             box.draw(rl.yellow)
         else:
             box.draw(rl.white)
Ejemplo n.º 40
0
def _debug_region(current_map, screen_x, screen_y, pos):
    global _con
    libtcod.console_set_char(_con, screen_x, screen_y,
                             chr(65 + (current_map.region[pos.x][pos.y] % 26)))
Ejemplo n.º 41
0
def _debug_elevation(current_map, screen_x, screen_y, pos):
    global _con
    libtcod.console_set_char(
        _con, screen_x, screen_y,
        chr(48 +
            current_map.region_elevations[current_map.region[pos.x][pos.y]]))
Ejemplo n.º 42
0
	var.splatter = libtcod.console_new(var.window_size[0], var.window_size[1]-6)
	libtcod.console_set_key_color(var.splatter,libtcod.Color(0,0,0))
	libtcod.console_set_key_color(var.tree,libtcod.Color(0,0,0))
	var.log = libtcod.console_new(var.window_size[0], 6)
	libtcod.console_set_keyboard_repeat(100,1)
	libtcod.sys_set_fps(var.max_fps)
	
	_logofile = open(os.path.join('data','logo.txt'),'r')
	_y=18
	for line in _logofile.readlines():
		_i = 1
		for char in line:
			if char == '\n': continue
			libtcod.console_set_char_foreground(0,_i,_y,libtcod.Color(_y*6,_y*6,_y*6))
			#libtcod.console_print(0, _i, _y, char)
			libtcod.console_set_char(0, _i, _y, char)
			_i+=1
		_y+=1
	libtcod.console_print(0,(var.window_size[0]/2)-(len(__version__)/2),
		28,
		str(__version__))
	_logofile.close()
	libtcod.console_flush()

#Load dictionary files
logging.debug('Loading dictionaries')

_fnames = open(os.path.join('data','names_female.txt'),'r')
for line in _fnames.readlines():
	var.names_female.append(line)
_fnames.close()
Ejemplo n.º 43
0
 def display_char(self, console, x, y, char):
     libtcod.console_set_char(console, x, y, char)
Ejemplo n.º 44
0
def render_all(window, ui_panel, entities, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, ui_panel_width,
               ui_panel_height, ui_panel_y, mouse, colors, game_state):
    results = []

    # draw game map
    if fov_recompute or libtcod.map_is_in_fov(fov_map, mouse.cx, mouse.cy):
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            window, x, y, colors.get("light_wall"),
                            libtcod.BKGND_SET)
                        libtcod.console_set_char_foreground(
                            window, x, y, libtcod.white)
                        libtcod.console_set_char(window, x, y, '#')
                    else:
                        libtcod.console_set_char_background(
                            window, x, y, colors.get("light_ground"),
                            libtcod.BKGND_SET)
                        libtcod.console_set_char_foreground(
                            window, x, y, libtcod.white)
                        libtcod.console_set_char(window, x, y, '.')

                    if mouse.cx == x and mouse.cy == y:
                        libtcod.console_set_char_background(
                            window, x, y, libtcod.white,
                            libtcod.BKGND_ALPHA(0.5))

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            window, x, y, colors.get("dark_wall"),
                            libtcod.BKGND_SET)
                        libtcod.console_set_char_foreground(
                            window, x, y, libtcod.light_gray)
                        libtcod.console_set_char(window, x, y, '#')
                    else:
                        libtcod.console_set_char_background(
                            window, x, y, colors.get("dark_ground"),
                            libtcod.BKGND_SET)
                        libtcod.console_set_char_foreground(
                            window, x, y, libtcod.lighter_gray)
                        libtcod.console_set_char(window, x, y, '.')

    # Draw all entities in rendering order e.g. corpses should be below player.
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(window, entity, fov_map, game_map)

    # Blit offscreen window to main window
    libtcod.console_blit(window, 0, 0, screen_width, screen_height, 0, 0, 0)

    # Prepare offscreen UI panel for drawing
    player = entities[0]  # first entity is always player
    libtcod.console_set_default_background(ui_panel, libtcod.black)
    libtcod.console_clear(ui_panel)

    # Draw event message log to offscreen UI panel
    for y, message in enumerate(message_log.messages):  # Draw message log
        libtcod.console_set_default_foreground(ui_panel, message.color)
        libtcod.console_print_ex(ui_panel, message_log.x, y + 1,
                                 libtcod.BKGND_NONE, libtcod.LEFT,
                                 message.text)

    # Draw player info bar to offscreen UI panel
    render_bar(ui_panel, 1, 1, ui_panel_width, "HP", player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        ui_panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        "Dungeon level: {0}".format(game_map.dungeon_level))

    # Draw entity name at mouse position to offscreen UI panel
    libtcod.console_set_default_foreground(ui_panel, libtcod.light_gray)
    libtcod.console_print_ex(ui_panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    # Blit UI panel to main window
    libtcod.console_blit(ui_panel, 0, 0, screen_width, ui_panel_height, 0, 0,
                         ui_panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_header = "Press the key next to item to use it. Press Esc to cancel.\n"
        else:
            inventory_header = "Press the key next to item to drop it. Press Esc to cancel.\n"

        results.extend(
            inventory_menu(window, inventory_header, player, 50, screen_width,
                           screen_height, mouse))
    elif game_state == GameStates.LEVEL_UP:
        results.extend(
            level_up_menu(window, "Level up! Choose a stat to raise:", player,
                          40, screen_width, screen_height, mouse))
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen_menu(player, 30, 10, screen_width, screen_height)

    return results
Ejemplo n.º 45
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    libtcod.console_set_char_background(
                        con, x, y, libtcod.Color(15, 15, 15))
                    if wall:
                        libtcod.console_set_char_foreground(
                            con, x, y, colors.get('light_wall'))
                        libtcod.console_set_char(con, x, y, '#')
                    else:
                        libtcod.console_set_char_foreground(
                            con, x, y, colors.get('light_ground'))
                        libtcod.console_set_char(con, x, y, '.')

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    libtcod.console_set_char_background(
                        con, x, y, libtcod.Color(5, 10, 15))
                    if wall:
                        libtcod.console_set_char_foreground(
                            con, x, y, colors.get('dark_wall'))
                        libtcod.console_set_char(con, x, y, '#')
                    else:
                        libtcod.console_set_char_foreground(
                            con, x, y, colors.get('dark_ground'))
                        libtcod.console_set_char(con, x, y, '.')

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.message:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 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: {0}'.format(game_map.dungeon_level))
    if player.fighter.dodge_chance > 0:
        libtcod.console_print_ex(
            panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
            'Dodge Chance: {0}'.format(player.fighter.dodge_chance))

    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(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = ('Press the key next to an item to use it,' +
                               ' or Esc to cancel.\n')
        else:
            inventory_title = ('Press the key next to an item to drop it,' +
                               ' or Esc to cancel.\n')

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 46
0
def render_all():
    global cam_x, cam_y
    
    #clear the city locations using OLD cam position.
    for city in R.cities:
        loc = R.tiles[city.x][city.y]
        colour = loc.bg
        libtcod.console_set_char_background(con, cam_x+city.x, cam_y+city.y, colour, libtcod.BKGND_SET )
        libtcod.console_set_char(con, cam_x+city.x, cam_y+city.y, ord(' '))
        
    cam_x = scrolling_map(player.x, R.MAP_VIEW_WIDTH/2, R.MAP_VIEW_WIDTH, R.MAP_WIDTH)
    cam_y = scrolling_map(player.y, R.MAP_VIEW_HEIGHT/2, R.MAP_VIEW_HEIGHT, R.MAP_HEIGHT)
    #now draw the map!
    for y in range(min(R.MAP_VIEW_HEIGHT, len(R.world.tiles[0]))): #this refers to the SCREEN position. NOT map.
        for x in range(min(R.MAP_VIEW_WIDTH, len(R.world.tiles))):
            map_pos_x = x + cam_x
            map_pos_y = y + cam_y
            if map_pos_x >= R.MAP_WIDTH:
                map_pos_x = R.MAP_WIDTH -1
            if map_pos_y >= R.MAP_HEIGHT:
                map_pos_y = R.MAP_HEIGHT - 1
            
            tile = R.world.tiles[map_pos_x][map_pos_y]
            #===============================================================
            # try: 
            #    tile = map[map_pos_x][map_pos_y]
            # except: 
            #    print str(map_pos_x) + " or " + str(map_pos_y) + " is out of bounds."
            #    break
            #===============================================================
             
            #visible = libtcod.map_is_in_fov(fov_map, tile.x, tile.y)
            visible = True
            #wall = tile.block_sight
                
            if not visible:
                pass #TODO: re-do the visible/ not visible code.
                #if it"s not visible right now, the player can only see it if it"s explored
                #if tile.explored:
                    #if wall:
                    #    libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                    #    libtcod.console_set_char(con, x, y, " ")
                    #else:
                    #    libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                    #    libtcod.console_set_char(con, x, y, " ")
            else:
                #it"s visible
                if tile.POI is None:
                    if traffic: # for b&w image.
                        v = world.get_foot_traffic(map_pos_x,map_pos_y)
                        colour = libtcod.Color(v,v,v)
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET )
                        libtcod.console_set_char(con, x, y, " ")
                        
                    elif temperature: # for b&w image.
                        v = world.get_temperature(map_pos_x,map_pos_y)
                        v = int(v)
                        colour = libtcod.Color(v,v,v)
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET )
                        libtcod.console_set_char(con, x, y, " ")
                        
                    else:
                        colour = tile.bg
                        libtcod.console_set_char(con, x, y, " ")
                        libtcod.console_set_char_background(con, x, y, colour, libtcod.BKGND_SET )
                    #libtcod.console_set_char_foreground(con, x, y, libtcod.black)
                    #libtcod.console_set_char(con, x, y, libtcod.CHAR_BULLET)
                else:
                    libtcod.console_set_char_background(con, x, y, tile.POI.colour, libtcod.BKGND_SET )
                    libtcod.console_set_char_foreground(con, x, y, libtcod.white)
                    libtcod.console_set_char(con, x, y, tile.POI.char)
                #since it"s visible, explore it
                tile.explored = True
    
    
    #now draw the mini map
    for cell_x in range(len(world.mini_map)):
        for cell_y in range(len(world.mini_map[cell_x])):
            colour = world.mini_map[cell_x][cell_y].bg
            libtcod.console_set_char_background(minmap, cell_x, cell_y, colour, libtcod.BKGND_SET )
            #libtcod.console_set_char_foreground(con, x, y, libtcod.white)
                            
            
#    for char in R.world_obj:
#        if char != player:
#            char.draw(cam_x, cam_y)

    #now draw all the merchants
    for city in cities:
        for merchant in city.trade_house.caravans_out:
            merchant.draw(cam_x,cam_y)
    for objects in R.world_obj:
            if objects.ai:
                objects.clear(cam_x,cam_y)   
                objects.draw(cam_x,cam_y)        
    player.draw(cam_x, cam_y)
    
    libtcod.console_clear(message_bar)
    libtcod.console_set_default_foreground(message_bar, libtcod.white)
    libtcod.console_print_ex(message_bar, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, str(date[0]) + " " + str(date[1][2]) + " " + str(date[1][0]) + " " + str(date[2][0]))
    # print the messages, one line at a time.
    y = 2
    for (line, colour) in R.game_msgs:
        libtcod.console_set_default_foreground(message_bar, colour)
        libtcod.console_print_ex(message_bar, R.MSG_X, R.MSG_HEIGHT - y, libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1
    
#    y = 0
#    for y in range(R.MAP_HEIGHT):
#        for x in range(R.MAP_WIDTH):
#            libtcod.console_set_char_background(con, x, y, map_[x][y].bg, libtcod.BKGND_SET)
    
    #libtcod.console_print_ex(message_bar, R.SCREEN_WIDTH - R.INFO_BAR_WIDTH, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse())         
    
    libtcod.console_set_default_background(con, libtcod.white)
    libtcod.console_blit(con, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0)
    #libtcod.console_blit(con, mini_map_x, mini_map_y, mini_map_x+ mini_map_width, mini_map_y +mini_map_height, 0, 0, 0)
    libtcod.console_blit(con_char, 0, 0, R.MAP_VIEW_WIDTH, R.MAP_VIEW_HEIGHT, 0, 0, 0, 1.0, 0.0)
    libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0,R.MAP_VIEW_WIDTH,0)
    libtcod.console_blit(minmap, 0, 0, R.INFO_BAR_WIDTH, R.PANEL_HEIGHT, 0,R.MAP_VIEW_WIDTH,R.PANEL_Y)
    libtcod.console_blit(message_bar, 0, 0, R.PANEL_WIDTH, R.PANEL_HEIGHT, 0 , 0, R.PANEL_Y)
    libtcod.console_flush()
Ejemplo n.º 47
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
        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

                distance_light = TORCH_RADIUS + 1 - player.distance(x, y) #Make the light dimmer further from player
                distance_dark = SCREEN_WIDTH - player.distance(x, y)
                distance_light = abs(distance_light) ** 0.5 #Square root to make transition non linear
                distance_dark = abs(distance_dark) ** 0.5
     
                if not visible:
                    #If it's not visible right now, the player can only see it if it is already explored
                    if map[x][y].explored:
                        #It is out of FOV
                        if wall:
                            libtcod.console_set_char_background(con, x, y, 
                                    color_dark_wall * (0.075) * distance_dark, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, 
                                    color_dark_ground * (0.075) * distance_dark, libtcod.BKGND_SET)
                            libtcod.console_set_char(con, x, y, ' ')
                else:
                    #It's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, 
                                color_light_wall * (0.35) * distance_light, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, 
                                color_light_ground * (0.35) * distance_light, libtcod.BKGND_SET)
                        libtcod.console_set_char_foreground(con, x, y, libtcod.dark_orange)
                        libtcod.console_set_char(con, x, y, map[x][y].char)
                    #Since it is visible, explore it
                    map[x][y].explored = True

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

    #Blit to con
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

    #Prepare to render GUI panel
    libtcod.console_set_default_background(panel, libtcod.darkest_grey)
    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)
    
    level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
    render_bar(1, 2, BAR_WIDTH, 'XP', player.fighter.xp, level_up_xp,
            libtcod.darker_green, libtcod.darkest_green)

    #Print dungeon level
    libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon Level: ' + str(dungeon_level))
    libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, 'Player Level: ' + str(player.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 root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Ejemplo n.º 48
0
 def draw(self, con, cam):
     libtcod.console_set_char_foreground(con, self.x - cam.x, self.y - cam.y, self.color)
     libtcod.console_set_char(con, self.x - cam.x, self.y - cam.y, self.char)