Пример #1
0
    def __init__(self, tilelist, fadetime, color1, color2):
        self.tilelist = tilelist
        self.color1 = color1
        self.color2 = color2
        allx = map(lambda tile: tile.x, self.tilelist)
        ally = map(lambda tile: tile.y, self.tilelist)
        minx = min(allx)
        maxx = max(allx)
        miny = min(ally)
        maxy = max(ally)
        self.blitx = minx
        self.blity = miny
        width = maxx - minx + 1
        height = maxy - miny + 1
        EffectCon.__init__(self, width, height, fadetime)

        libtcod.console_set_key_color(self.console, libtcod.silver)
        libtcod.console_set_default_background(self.console,
                                               libtcod.silver)  #key color

        idx = [0, self.maxduration]
        col = [self.color1, self.color2]
        self.colormap = libtcod.color_gen_map(col, idx)

        newcoordlist = []
        for tile in self.tilelist:
            newcoordlist.append((tile.x - minx, tile.y - miny))
        self.con_coords = newcoordlist

        activeeffects.append(self)
Пример #2
0
	def __init__(self, root_console_width, root_console_height, world_x_start, world_y_start, frame_manager):
		#TODO manage offset of code
		Frame.__init__(self, root_console_width, root_console_height, root_console_width - world_x_start, root_console_height - world_y_start, frame_manager)
		self.world_x_start = world_x_start
		self.world_y_start = world_y_start
		self.entity_manager = frame_manager.parent_menu.entity_manager
		self.actions = []
		libtcod.console_set_default_background(self.console, libtcod.Color(255, 0, 255))
		libtcod.console_set_key_color(self.console, libtcod.Color(255, 0, 255))
Пример #3
0
 def __init__(self, root_console_width, root_console_height, world_x_start,
              world_y_start, frame_manager):
     #TODO manage offset of code
     Frame.__init__(self, root_console_width, root_console_height,
                    root_console_width - world_x_start,
                    root_console_height - world_y_start, frame_manager)
     self.world_x_start = world_x_start
     self.world_y_start = world_y_start
     self.entity_manager = frame_manager.parent_menu.entity_manager
     self.actions = []
     libtcod.console_set_default_background(self.console,
                                            libtcod.Color(255, 0, 255))
     libtcod.console_set_key_color(self.console, libtcod.Color(255, 0, 255))
Пример #4
0
def create_view(x, y, w, h, dw, dh, alpha, name, lighting=False, layer=0, fore_opacity=1, back_opacity=1, transparent=False, require_refresh=False):
	if get_view_by_name(name):
		raise Exception('View with name \'%s\' already exists.' % name)
	
	dh = h
	dw = w
	
	_v_id = SETTINGS['viewid']
	_view = {'console': tcod.console_new(w, h),
	         'position': [x, y],
	         'draw_size': (dw, dh),
	         'view_size': (w, h),
	         'layer': layer,
	         'fade': [fore_opacity, back_opacity],
	         'transparent': transparent,
	         'name': name,
	         'light_buffer': None,
	         'char_buffer': [numpy.zeros((dh, dw), dtype=numpy.int16),
	                          numpy.zeros((dh, dw), dtype=numpy.int16)],
	         'col_buffer': [[numpy.zeros((dh, dw)),
	                         numpy.zeros((dh, dw)),
	                         numpy.zeros((dh, dw))],
	                        [numpy.zeros((dh, dw)),
	                         numpy.zeros((dh, dw)),
	                         numpy.zeros((dh, dw))]],
	         'require_refresh': require_refresh,
	         '_dirty': False,
	         'id': _v_id}
	
	if lighting:
		_view['light_buffer'] = [numpy.zeros((dh, dw), dtype=numpy.int16),
		                         numpy.zeros((dh, dw), dtype=numpy.int16)]
	
	if transparent:
		_view['fade'][1] = 0
		_view['col_buffer'][1][0] += 255
		_view['col_buffer'][1][2] += 255
		tcod.console_set_key_color(_view['console'], tcod.Color(255, 0, 255))
	
	SETTINGS['viewid'] += 1
	VIEWS[name] = _view
	
	logging.debug('Created view \'%s\'.' % name)
	
	#if not VIEW_SCENE:
	#	_add_view_to_scene(_view)
	#	set_active_view(name)
	
	return _view
Пример #5
0
def render_all():
    offset_row = player.loc.row - (MAP_WIDTH/2)
    offset_col = player.loc.col - (MAP_HEIGHT/2)

    lt.map_compute_fov(area.fov_map, player.loc.col, player.loc.row, SIGHT_RADIUS, True, FOV_ALGO)
    area.draw(offset_col, offset_row, MAP_WIDTH, MAP_HEIGHT)
    for item in area.items:
        item["loc"].draw(area)
    player.loc.draw(area)
    lt.console_set_key_color(area.con, lt.black)

    # Panel Rendering
    lt.console_clear(panel)
    lt.console_set_default_foreground(panel, lt.white)
    lt.console_print(panel, 1, 2, 'Overall:')
    text, color = injury_level(player.body.overall_health())
    lt.console_set_default_foreground(panel, color)
    lt.console_print(panel, 1, 3, text)

    lt.console_set_default_foreground(panel, lt.white)
    lt.console_print(panel, 1, 5, 'Chest:')
    text, color = injury_level(player.body.chest.health())
    lt.console_set_default_foreground(panel, color)
    lt.console_print(panel, 1, 6, text)

    lt.console_set_default_foreground(panel, lt.white)
    lt.console_print(panel, 1, 8, 'Head:')
    text, color = injury_level(player.body.head.health())
    lt.console_set_default_foreground(panel, color)
    lt.console_print(panel, 1, 9, text)

    # Fog background behind the map.
    lt.console_set_default_background(frame, area.fog)
    lt.console_rect(frame, 1, 1, MAP_WIDTH, MAP_HEIGHT, True, lt.BKGND_SET)
    # A frame around the map
    lt.console_set_default_foreground(frame, lt.desaturated_amber)
    lt.console_set_default_background(frame, lt.Color(70, 60, 0))
    for n in xrange(MAP_WIDTH + 2):
        lt.console_put_char(frame, n, 0, "+", lt.BKGND_SET)
        lt.console_put_char(frame, n, MAP_HEIGHT + 1, "+", lt.BKGND_SET)
        lt.console_put_char(frame, 0, n, "+", lt.BKGND_SET)
        lt.console_put_char(frame, MAP_WIDTH + 1, n, "+", lt.BKGND_SET)

    # Blit all
    lt.console_blit(frame, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    lt.console_blit(panel, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, MAP_WIDTH + 2, 1)
    lt.console_blit(area.con, offset_row, offset_col, MAP_WIDTH, MAP_HEIGHT, 0, 1, 1)
    lt.console_flush()
Пример #6
0
def init():
	global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY
	w = config.SCREEN_WIDTH
	h = config.SCREEN_HEIGHT
	ltc.sys_set_fps(config.FPS)
	
	#ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16)
	ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_TCOD | ltc.FONT_TYPE_GREYSCALE, 32, 8)	
	ltc.console_init_root(w, h, config.TITLE, False)
	
	KEYBOARD_MAP = dict([[v, k] for k, v in KEYBOARD_MAP.items()])
	CON = ltc.console_new(w, h)
	UI = ltc.console_new(w, h)
	ltc.console_set_key_color(UI, ltc.purple)
	MOUSE = ltc.Mouse()
	KEY = ltc.Key()
Пример #7
0
	def __init__(self, root_console_width, root_console_height, terminal_width, terminal_height, frame_manager):
		# constants and initialization
		self.prompt_string = "X:\\>"
		self.input_command = ""
		self.blinking_cursor = "_"
		self.cursor_blink_delay = 500
		self.cursor_timer = 0
		self.console_command_history = []
		self.console_max_history_length = terminal_height - 2
		self.input_enabled = True

		Frame.__init__(self, root_console_width, root_console_height, terminal_width, terminal_height, frame_manager)
		#-1 to account for border tile
		self.max_command_size = self.width - len(self.prompt_string) - 1 

		libtcod.console_set_key_color(self.console, libtcod.Color(255, 0, 255))
Пример #8
0
def init():
    global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY
    w = config.SCREEN_WIDTH
    h = config.SCREEN_HEIGHT
    ltc.sys_set_fps(config.FPS)

    #ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16)
    ltc.console_set_custom_font(config.TILE_SET,
                                ltc.FONT_LAYOUT_TCOD | ltc.FONT_TYPE_GREYSCALE,
                                32, 8)
    ltc.console_init_root(w, h, config.TITLE, False)

    KEYBOARD_MAP = dict([[v, k] for k, v in KEYBOARD_MAP.items()])
    CON = ltc.console_new(w, h)
    UI = ltc.console_new(w, h)
    ltc.console_set_key_color(UI, ltc.purple)
    MOUSE = ltc.Mouse()
    KEY = ltc.Key()
Пример #9
0
    def __init__(self, root_console_width, root_console_height, terminal_width,
                 terminal_height, frame_manager):
        # constants and initialization
        self.prompt_string = "X:\\>"
        self.input_command = ""
        self.blinking_cursor = "_"
        self.cursor_blink_delay = 500
        self.cursor_timer = 0
        self.console_command_history = []
        self.console_max_history_length = terminal_height - 2
        self.input_enabled = True

        Frame.__init__(self, root_console_width, root_console_height,
                       terminal_width, terminal_height, frame_manager)
        #-1 to account for border tile
        self.max_command_size = self.width - len(self.prompt_string) - 1

        libtcod.console_set_key_color(self.console, libtcod.Color(255, 0, 255))
Пример #10
0
                lt.console_clear(river_con)
                for river in area:
                    for tile in river.tiles:
                        y, x = tile
                        lt.console_set_char_background(river_con, x, y, lt.azure, lt.BKGND_SET)
                lt.console_blit(river_con, 0, 0, 0, 0, 0, 0, 0)

        lt.console_flush()

        if click:
            while True:
                key = lt.console_wait_for_keypress(False)
                if key.pressed:
                    break


if viz:
    lt.console_set_custom_font("data/fonts/arialtiny.png", lt.FONT_TYPE_GRAYSCALE | lt.FONT_LAYOUT_TCOD)
    lt.console_init_root(WORLD_SIZE, WORLD_SIZE, "Visualizer", False)
    con = lt.console_new(WORLD_SIZE, WORLD_SIZE)
    river_con = lt.console_new(WORLD_SIZE, WORLD_SIZE)
    lt.console_set_key_color(river_con, lt.black)

    controller()
    while True:
        key = lt.console_wait_for_keypress(False)
        if key.vk == lt.KEY_ESCAPE:
            break
        elif key.c:
            controller()
Пример #11
0
		libtcod.console_set_custom_font(os.path.join('data','terminal8x8_aa_tc.png'), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	elif '-font' in sys.argv:
		try:
			_font = sys.argv[sys.argv.index('-font')+1]
			libtcod.console_set_custom_font(_font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
		except:
			logging.error('Failed to load font!')
			sys.exit()
	else:
		var.window_size = (80,50)
		libtcod.console_set_custom_font(os.path.join('data','terminal16x16_aa_tc.png'), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	libtcod.console_init_root(var.window_size[0], var.window_size[1], 'Rogue Caves - %s' % __version__, False)
	var.view = libtcod.console_new(var.window_size[0], var.window_size[1]-6)
	var.tree = libtcod.console_new(var.window_size[0], var.window_size[1]-6)
	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
Пример #12
0
 def set_key_color(self, color):
     return libtcod.console_set_key_color(self.console_id, color)
Пример #13
0
def test_console_blit(console, offscreen):
    libtcodpy.console_print(offscreen, 0, 0, 'test')
    libtcodpy.console_blit(offscreen, 0, 0, 0, 0, console, 0, 0, 1, 1)
    assertConsolesEqual(console, offscreen)
    libtcodpy.console_set_key_color(offscreen, libtcodpy.black)
Пример #14
0
def blit_overlay():
    global _overlay
    libtcod.console_set_key_color(_overlay, libtcod.black)
    libtcod.console_blit(_overlay, 0, 0, config.MAP_PANEL_WIDTH,
                         config.MAP_PANEL_HEIGHT, 0, 0, 0, 0.4, 1.0)
Пример #15
0
def create_view(x,
                y,
                w,
                h,
                dw,
                dh,
                alpha,
                name,
                lighting=False,
                layer=0,
                fore_opacity=1,
                back_opacity=1,
                transparent=False,
                require_refresh=False):
    if get_view_by_name(name):
        raise Exception('View with name \'%s\' already exists.' % name)

    dh = h
    dw = w

    _v_id = SETTINGS['viewid']
    _view = {
        'console':
        tcod.console_new(w, h),
        'position': [x, y],
        'draw_size': (dw, dh),
        'view_size': (w, h),
        'layer':
        layer,
        'fade': [fore_opacity, back_opacity],
        'transparent':
        transparent,
        'name':
        name,
        'light_buffer':
        None,
        'char_buffer': [
            numpy.zeros((dh, dw), dtype=numpy.int16),
            numpy.zeros((dh, dw), dtype=numpy.int16)
        ],
        'col_buffer':
        [[numpy.zeros((dh, dw)),
          numpy.zeros((dh, dw)),
          numpy.zeros((dh, dw))],
         [numpy.zeros((dh, dw)),
          numpy.zeros((dh, dw)),
          numpy.zeros((dh, dw))]],
        'require_refresh':
        require_refresh,
        '_dirty':
        False,
        'id':
        _v_id
    }

    if lighting:
        _view['light_buffer'] = [
            numpy.zeros((dh, dw), dtype=numpy.int16),
            numpy.zeros((dh, dw), dtype=numpy.int16)
        ]

    if transparent:
        _view['fade'][1] = 0
        _view['col_buffer'][1][0] += 255
        _view['col_buffer'][1][2] += 255
        tcod.console_set_key_color(_view['console'], tcod.Color(255, 0, 255))

    SETTINGS['viewid'] += 1
    VIEWS[name] = _view

    logging.debug('Created view \'%s\'.' % name)

    #if not VIEW_SCENE:
    #	_add_view_to_scene(_view)
    #	set_active_view(name)

    return _view
Пример #16
0
####################

layer_0_console = libtcod.console_new(xp_data["layer_data"][0]["width"], xp_data["layer_data"][0]["height"])
layer_1_console = libtcod.console_new(xp_data["layer_data"][1]["width"], xp_data["layer_data"][1]["height"])

xp_loader.load_layer_to_console(layer_0_console, xp_data["layer_data"][0])
xp_loader.load_layer_to_console(layer_1_console, xp_data["layer_data"][1])

####################
# Sets the overlay layer transparency key to REXPaint's background transparency key. For completeness purposes, load_layer_to_console always writes every cell to the console -
# REXPaint format note - layer 0 background is written out as 0,0,0. If you're making .xp files for UI overlays or whatever, be absolutely sure to
####################

libtcod.console_set_key_color(
    layer_1_console,
    libtcod.Color(
        xp_loader.transparent_cell_back_r, xp_loader.transparent_cell_back_g, xp_loader.transparent_cell_back_b
    ),
)


####################
# libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod
####################

draw_layers = False

while not libtcod.console_is_window_closed():

    key = libtcod.console_check_for_keypress()
    if key.vk == libtcod.KEY_ESCAPE:
        break  # exit game
Пример #17
0
layer_0_console = libtcod.console_new(xp_data['layer_data'][0]['width'],
                                      xp_data['layer_data'][0]['height'])
layer_1_console = libtcod.console_new(xp_data['layer_data'][1]['width'],
                                      xp_data['layer_data'][1]['height'])

xp_loader.load_layer_to_console(layer_0_console, xp_data['layer_data'][0])
xp_loader.load_layer_to_console(layer_1_console, xp_data['layer_data'][1])

####################
# Sets the overlay layer transparency key to REXPaint's background transparency key. For completeness purposes, load_layer_to_console always writes every cell to the console -
# REXPaint format note - layer 0 background is written out as 0,0,0. If you're making .xp files for UI overlays or whatever, be absolutely sure to
####################

libtcod.console_set_key_color(
    layer_1_console,
    libtcod.Color(xp_loader.transparent_cell_back_r,
                  xp_loader.transparent_cell_back_g,
                  xp_loader.transparent_cell_back_b))

####################
# libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod
####################

draw_layers = False

while not libtcod.console_is_window_closed():

    key = libtcod.console_check_for_keypress()
    if key.vk == libtcod.KEY_ESCAPE:
        break  #exit game
Пример #18
0
def main():
    constants = get_constants()

    libtcod.tileset.set_default(
        libtcod.tileset.load_truetype_font('ngeb.ttf', 0, 16))
    #libtcod.console_set_custom_font('arial12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    animation_console = libtcod.console_new(constants['screen_width'],
                                            constants['screen_height'])
    libtcod.console_set_key_color(animation_console, (0, 0, 0))

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, constants['screen_width'],
                      constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, animation_console, constants)

            show_main_menu = True
Пример #19
0
 def console_set_key_color(self, con, r, g, b):
     col = libtcod.Color(r, g, b)
     if con == 0:
         libtcod.console_set_key_color(con, col)
     else:
         libtcod.console_set_key_color(self.mConsole[con-1], col)