コード例 #1
0
ファイル: dialog_box.py プロジェクト: GrishdaFish/Ascension
    def display_box(self):
##============================================================================
        input = -1
        while input == -1:
            input = self.run()
        libtcod.mouse_get_status()
        libtcod.console_check_for_keypress()
        return input
コード例 #2
0
 def display_box(self):
     ##============================================================================
     input = -1
     while input == -1:
         input = self.run()
     libtcod.mouse_get_status()
     libtcod.console_check_for_keypress()
     return input
コード例 #3
0
ファイル: menu.py プロジェクト: GrishdaFish/Ascension
def town_menu(con, header, game, width, screen_height, screen_width):
##============================================================================
    options =  ['The Helm and Buckler',
        "Johan's Weaporium",
        "Fizzilip's Magiteria",
        'Quests',
        'Finished',]
    path = os.path.join(sys.path[0], 'content')
    path = path.replace('core.exe','')
    backgrounds=[os.path.join(path, 'img', 'bg-arm.png'),
                os.path.join(path, 'img', 'bg-wep.png'),
                os.path.join(path, 'img', 'bg-magic.png'),]
    container=[]
    menus = []
    weapon,armor,consum,quest=[],[],[],[]
    
    for i in range(10):##Need to init objects and message in object creation
        item = game.build_objects.build_equipment(game,0,0,'melee')
        weapon.append(item)
        item = game.build_objects.build_equipment(game,0,0,'armor')
        armor.append(item)
    for i in range(5):
        consume = game.build_objects.build_potion(game,0,0)
        consum.append(consume)
        consume = game.build_objects.build_scroll(game,0,0)
        consum.append(consume)
        
    container.append(armor)    
    container.append(weapon)
    container.append(consum)
    container.append(quest)
    
    bg = os.path.join(path,'img','bg-town.png')
    t_menu = Menus(game,screen_height,screen_width,width,header,options,bg=bg) 
    
    while 1:
        t_menu.is_visible=True
        libtcod.mouse_get_status()
        index = t_menu.menu()    
        if index == len(options)-1 or index is None:
            t_menu.destroy_menu()
            break
            
        if index != (len(options)-1) and index is not None and index != -1:
            game.gEngine.console_clear(0)
            t_menu.is_visible = False
            if index < (len(backgrounds)):
                item = SHOP(0, game.player, game, container=container[index], bg=backgrounds[index], header=options[index])
                #item=shop(con,options[index],game,width,
                #    screen_height,screen_width,container[index],backgrounds[index])
            else:
                item = SHOP(0, game.player, game, container=container[index], header=options[index])
                #item=shop(con,options[index],game,width,
                #    screen_height,screen_width,container[index])
            if item is not None:
                container[index].pop(item)
            t_menu.last_input = 0
コード例 #4
0
ファイル: menu.py プロジェクト: GrishdaFish/Ascension
def shop(con, header, game, width, screen_height, screen_width, container, bg=None):
##============================================================================
    options=[]
    cl_options = []
    if bg:
        img = libtcod.image_load(bg)
        #libtcod.image_blit_2x(img, 0, 0, 0)
        
    for obj in container:
        obj_text = obj.name
        ob_value = obj.item.value
        opt = '[%s] - Price: (%s) gold'%(obj_text,ob_value)
        cl_options.append(opt)
        
        obj_text = color_text(obj.name,obj.color)
        ob_value = color_text(str(obj.item.value),libtcod.gold)
        opt = '[%s] - Price: (%s) gold'%(obj_text,ob_value)
        options.append(opt)
        
    header = header + ' (' + str(game.player.fighter.money) + ' gold left)'
    shop = Menus(game,screen_height,screen_width,width,header,options,bg=bg,cl_options=cl_options) 
    shop.is_visible=True
    
    while 1:
        shop.is_visible=True
        libtcod.mouse_get_status()#to prevent extra mouse clicks
        item = shop.menu()
        if item is not None and item is not -1:
            if game.player.fighter.money >= container[item].item.value:
                obj_text = color_text(container[item].name,container[item].color)
                ob_value = color_text(str(container[item].item.value),libtcod.gold)
                message = 'Purchase [%s] for (%s) gold?'%(obj_text,ob_value)
                w = len('Purchase ['+container[item].name+'] for ('+str(container[item].item.value)+') gold?')+2
                d_box = DialogBox(game,w,10,20,20,message,type='option',con=shop.window)
                shop.is_visible = False
                confirm = d_box.display_box()
                if confirm == 1:
                    game.logger.log.debug(container[item].objects)
                    game.player.fighter.money-=container[item].item.value
                    game.player.fighter.inventory.append(container[item])
                    d_box.destroy_box()
                    shop.destroy_menu()
                    #game.logger.log.debug(container[item])
                    return item
                else:
                    d_box.destroy_box()
            else:
                message = 'Not enough gold!'                
                d_box = DialogBox(game,len(message)+2,10,20,20,message,con=shop.window)
                confirm = d_box.display_box()
                d_box.destroy_box()
        if item is None:
            shop.destroy_menu()
            return None
コード例 #5
0
    def __init__(self,
                 game,
                 screen_height,
                 screen_width,
                 width,
                 header,
                 options,
                 con=None,
                 bg=None,
                 cl_options=None):
        ##============================================================================
        self.is_dragging = False
        self.in_drag_zone = False
        self.mouse_highlight = False
        self.game = game
        self.cl_options = cl_options
        self.img = None
        if bg:
            self.img = game.gEngine.image_load(bg)

        self.screen_height = screen_height
        self.screen_width = screen_width

        self.header = header
        #if len(self.header) == 0:
        #    self.header = '======='
        self.header_o = self.header

        self.options = options

        height = len(options)
        width += 5
        height += 2
        #self.header_pos = (width//2)-len(header)

        self.window = game.gEngine.console_new(width, height)

        self.game.gEngine.console_set_alignment(self.window, 2)

        self.width = width
        self.height = height
        self.w_pos = screen_width / 2 - width / 2
        self.h_pos = screen_height / 2 - height / 2

        self.is_visible = False
        self.can_drag = True

        self.last_input = 0
        libtcod.mouse_get_status()  #this is to pick up stray mouse input that
コード例 #6
0
ファイル: player.py プロジェクト: ludamad/7DayRL2013
    def print_stats(self):
        import gui
        from globals import panel, world

        if self.stats.hp > 0:
            gui.render_bar( Pos(3,3), 20, "HP", int(self.stats.hp), self.stats.max_hp, colors.RED, colors.DARK_GRAY )
            gui.render_bar( Pos(3,4), 20, "MP", int(self.stats.mp), self.stats.max_mp, colors.BLUE, colors.DARK_GRAY )
        gui.render_bar( Pos(3,5), 20, "Harvest", self.points, world.level.points_needed, colors.DARK_GREEN, colors.DARK_GRAY )

        self.stats.inventory.draw(panel, INVENTORY_LOCATION_IN_PANEL)
        self.stats.statuses.draw(panel, Pos(3, 6))

        item_slot = _get_mouse_item_slot(self, libtcod.mouse_get_status())

        print_colored(panel, Pos(3, 0), colors.BABY_BLUE, 'BUGHACK  ')
        level_msg = [colors.WHITE, 'Level ', colors.YELLOW, str(world.level.level_index+1)+" ", colors.WHITE, 'Rank ', colors.YELLOW, self.rank ]
        if world.level.level_index+1 == 6:
            level_msg = [colors.YELLOW, 'Final Level ', colors.WHITE, 'Rank ', colors.YELLOW, self.rank ]
        print_colored(panel, Pos(3, 2), 
                      *level_msg )

        print_colored(panel, Pos(3, 1), colors.GOLD, 'A', colors.WHITE, 'bilities')
        print_colored(panel, Pos(14, 1), colors.GOLD, 'C', colors.WHITE, 'ontrols')

        if not item_slot:
            world.messages.draw(panel, Pos(33, 0))
        else:
            print_colored(panel, Pos(33, 0), colors.MUTED_GREEN, item_slot.item_type.name)
            print_colored(panel, Pos(34, 1), colors.YELLOW, item_slot.item_type.summary)
            print_colored(panel, Pos(34, 3), colors.BABY_BLUE, "Left click to use")
            print_colored(panel, Pos(34, 4), colors.WHITE, "Right click to drop")
コード例 #7
0
ファイル: Main.py プロジェクト: g-jackson/RogueLike
def target_tile(max_range=None):
    #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked.
    while True:
        render_all(True)
        #render the screen. this erases the inventory and shows the names of objects under the mouse.
        libtcod.console_flush()
        
        for object in objects:
            object.draw()
 
        key = libtcod.console_check_for_keypress()
        mouse = libtcod.mouse_get_status()  #get mouse position and click status
        (x, y) = (mouse.cx, mouse.cy)
 
        if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
            for object in objects:
                object.clear()
            return (None, None)  #cancel if the player right-clicked or pressed Escape
 
        #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range
        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y) and
            (max_range is None or player.distance(x, y) <= max_range)):
            for object in objects:
                object.clear()

            return (x, y)
コード例 #8
0
ファイル: button.py プロジェクト: GrishdaFish/Ascension
    def mouse_input(self, mouse=None):
##============================================================================
        if not mouse:
            mouse = libtcod.mouse_get_status()
        mx = mouse.cx - (self.x_pos + self.dest_x)
        my = mouse.cy - (self.y_pos + self.dest_y)

        if mx >= 0 and mx <= self.width and my >= 0 and my <= self.height:
            self.label = color_text(self.label_o,libtcod.red)
            if mouse.lbutton:
                self.label = color_text(self.label_o,libtcod.green)
                if mouse.lbutton_pressed:
                    if self.type is True:
                        return 1
                    else:
                        return 0
            if mouse.lbutton_pressed:
                if self.type is True:
                    return 1
                else:
                    return 0
        else:
            self.label = color_text(self.label_o, libtcod.white)

        return -1
コード例 #9
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, "#")
コード例 #10
0
ファイル: worldMap.py プロジェクト: Lemmily/py-shopRL
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, "#")    
コード例 #11
0
ファイル: button.py プロジェクト: GrishdaFish/Ascension
    def mouse_input(self, mouse=None):
        ##============================================================================
        if not mouse:
            mouse = libtcod.mouse_get_status()
        mx = mouse.cx - (self.x_pos + self.dest_x)
        my = mouse.cy - (self.y_pos + self.dest_y)

        if mx >= 0 and mx <= self.width and my >= 0 and my <= self.height:
            self.label = color_text(self.label_o, libtcod.red)
            if mouse.lbutton:
                self.label = color_text(self.label_o, libtcod.green)
                if mouse.lbutton_pressed:
                    if self.type is True:
                        return 1
                    else:
                        return 0
            if mouse.lbutton_pressed:
                if self.type is True:
                    return 1
                else:
                    return 0
        else:
            self.label = color_text(self.label_o, libtcod.white)

        return -1
コード例 #12
0
ファイル: main.py プロジェクト: Lemmily/py-shopRL
def handle_mouse():
    global selected
    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

    #pressed = 0 #clearing generic output signal from any logic

    if mouse.lbutton_pressed:
        print "boop"
        found = False
        for city in R.cities:
            if city.x == x + cam_x and city.y == y + cam_y:
                selected = city
                update_info_bar()
                found = True
                
        for obj in R.world_obj:
            if obj.x == x and obj.y == y:
                selected = obj
                update_info_bar()
                found = True
        if found == False and R.world.w >= (x + cam_x) and R.world.h >= (y + cam_y):
            print str(R.world.tiles[x + cam_x][y + cam_y].temperature) + "/" + str(R.world.tiles[x + cam_x][y + cam_y].elevation)
コード例 #13
0
def get_mouse_input():
    #TODO: I can't get mouse input to work properly...
    _mouse = tcod.mouse_get_status()
    _old_x, _old_y = MOUSE_POS

    MOUSE_POS[0] = _mouse.cx
    MOUSE_POS[1] = _mouse.cy

    if not [_old_x, _old_y] == MOUSE_POS:
        if MOUSE_CALLBACKS['move']:
            MOUSE_CALLBACKS['move']()

    if not INPUT['m1'] and _mouse.lbutton_pressed:
        if MOUSE_CALLBACKS['m1_click']:
            MOUSE_CALLBACKS['m1_click']()

        INPUT['m1'] = True
    else:
        INPUT['m1'] = False

    if not INPUT['m2'] and _mouse.rbutton_pressed:
        if MOUSE_CALLBACKS['m2_click']:
            MOUSE_CALLBACKS['m2_click']()

        INPUT['m2'] = True
    else:
        INPUT['m2'] = False
コード例 #14
0
ファイル: inputs.py プロジェクト: athros/Reactor-3
def get_mouse_input():
	#TODO: I can't get mouse input to work properly...
	_mouse = tcod.mouse_get_status()
	_old_x, _old_y = MOUSE_POS
	
	MOUSE_POS[0] = _mouse.cx
	MOUSE_POS[1] = _mouse.cy
	
	if not [_old_x, _old_y] == MOUSE_POS:
		if MOUSE_CALLBACKS['move']:
			MOUSE_CALLBACKS['move']()
	
	if not INPUT['m1'] and _mouse.lbutton_pressed:
		if MOUSE_CALLBACKS['m1_click']:
			MOUSE_CALLBACKS['m1_click']()
		
		INPUT['m1'] = True
	else:
		INPUT['m1'] = False
	
	if not INPUT['m2'] and _mouse.rbutton_pressed:
		if MOUSE_CALLBACKS['m2_click']:
			MOUSE_CALLBACKS['m2_click']()
		
		INPUT['m2'] = True
	else:
		INPUT['m2'] = False
コード例 #15
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def get_names_under_mouse():
	mouse = libtcod.mouse_get_status()
	(x, y) = (mouse.cx, mouse.cy)

	names = [obj.name for obj in objects
		if obj.x == x and obj.y == y and libtcod.map_is_in_fov(fov_map, obj.x, obj.y)]

	names = ', '.join(names)
	return names.capitalize()
コード例 #16
0
ファイル: dev_mode.py プロジェクト: GrishdaFish/Ascension
    def run(self):
        path = os.path.join(sys.path[0], 'content', 'prefabs', 'Prefabs.xp')
        #print path
        data = prefab_generator.load_prefab(path)
        #print data
        level = self.Map.make_map(empty=True)
        level.draw_map = self.Map.set_draw_map_2x(level.map, self.gEngine)
        level.draw_map = self.Map.set_draw_map(level.map, self.gEngine)
        level.fov_map = self.gEngine.get_fov_map()
        run_fov = True
        self.gEngine.lightmask_set_size(self.Map.MAP_WIDTH * 2,
                                        self.Map.MAP_HEIGHT * 2)
        #self.gEngine.light_mask.set_intensity(18.0)
        #lightmask = light_mask.LightMask(self.Map.MAP_WIDTH, self.Map.MAP_HEIGHT)'''
        self.gEngine.set_map_2x(self.gEngine.get_map_2x())

        self.qmap = quick_convert(self.Map.map2x)
        while not libtcod.console_is_window_closed():
            self.gEngine.console_clear(0)
            key = libtcod.console_check_for_keypress()
            mouse = libtcod.mouse_get_status()
            (x, y) = (mouse.cx, mouse.cy)
            self.gEngine.light_mask.reset()

            if key.vk == libtcod.KEY_SPACE:
                run_fov = not run_fov

            if x < self.Map.MAP_WIDTH and y < self.Map.MAP_HEIGHT:
                self.gEngine.light_mask.add_light(x * 2, y * 2, 1.0)
                pass
            self.gEngine.particle_update(self.Map.map2x)

            #self.gEngine.light_mask.add_light(40, 21, 1.0)
            #self.gEngine.lightmask_compute(self.Map.map2x)
            self.gEngine.map_draw(0, 40, 21, self.gEngine.light_mask)
            #self.gEngine.map_draw_2x(0, 40, 21)

            if mouse.lbutton:
                #self.gEngine.particle_cone(15,40, 21, x, y)
                #self.gEngine.particle_cone_spray(15,40, 21, x, y)
                self.gEngine.particle_projectile(1, 40 * 2, 21 * 2, x * 2,
                                                 y * 2)
                #self.gEngine.particle_explosion(15, x, y)
                #self.gEngine.particle_nova(9,  x, y)
                pass

            self.gEngine.particle_draw(0)

            self.gEngine.console_print(0, 1, 5,
                                       "(%dfps)" % (libtcod.sys_get_fps()))
            self.gEngine.console_put_char_ex(0, 40, 21, '@', 255, 255, 255, 0,
                                             0, 0)
            self.gEngine.console_put_char_ex(0, x, y, "X", 255, 255, 255, 0, 0,
                                             0)

            self.gEngine.console_flush()
コード例 #17
0
ファイル: game.py プロジェクト: bricks42/BrutalRL
def start_menu():
    title.init_blood()
    libtcod.console_credits_reset()

    finished_libtcod_credits = False

    selection = 0
    while True:
        title.update()

        libtcod.console_clear(0)

        title.draw_blood()
        title.draw_title()

        libtcod.console_set_background_color(0, libtcod.dark_grey)
        libtcod.console_rect(0, 24, 14, 32, 7, False, libtcod.BKGND_MULTIPLY)

        libtcod.console_set_foreground_color(0, libtcod.red)
        libtcod.console_print_center(0, 40, 15, libtcod.BKGND_NONE, "Brutal RL: Slaves to Slaughter")

        libtcod.console_set_foreground_color(0, libtcod.white)
        libtcod.console_print_left(0, 35, 17, libtcod.BKGND_NONE, "New Game")
        libtcod.console_print_left(0, 35, 18, libtcod.BKGND_NONE, "Load Game")
        libtcod.console_print_left(0, 35, 19, libtcod.BKGND_NONE, "Quit")

        libtcod.console_print_left(0, 33, 17 + selection, libtcod.BKGND_NONE, ">")
        libtcod.console_print_left(0, 45, 17 + selection, libtcod.BKGND_NONE, "<")

        if not finished_libtcod_credits:
            finished_libtcod_credits = libtcod.console_credits_render(65, 43, True)

        libtcod.console_flush()

        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)

        if key.vk == libtcod.KEY_ESCAPE:
            if selection == 2:
                raise SetState("quit")

            else:
                selection = 2

        elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0:
            selection += DIRECTION_KEYS[key.vk][1]
            selection %= 3

        elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]:
            raise SetState([new_game, load_game, "quit"][selection])

        mouse = libtcod.mouse_get_status()
        if mouse.lbutton:
            title.set_full(mouse.cx, mouse.cy)

        elif mouse.rbutton:
            title.set_empty(mouse.cx, mouse.cy)
コード例 #18
0
ファイル: game.py プロジェクト: scgs/tbfch
def get_names_under_mouse():
    # return a string with the names of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    # create a list with the names of all objects at the mouse's coordinates and in FOV
    names = [obj.name for obj in objects if obj.x == x and obj.y == y and libtcod.map_is_in_fov(fov_map, obj.x, obj.y)]

    names = ", ".join(names)  # join the names, separated by commas
    return names.capitalize()
コード例 #19
0
ファイル: menu.py プロジェクト: GrishdaFish/Ascension
    def __init__(self,game,screen_height,screen_width,width,header,options,
        con=None,bg=None,cl_options=None):
##============================================================================
        self.is_dragging = False
        self.in_drag_zone = False
        self.mouse_highlight = False
        self.game = game
        self.cl_options = cl_options
        self.img = None
        if bg:
            self.img = game.gEngine.image_load(bg)
            
        self.screen_height = screen_height
        self.screen_width = screen_width
        
        self.header = header
        #if len(self.header) == 0:
        #    self.header = '======='
        self.header_o = self.header
        
        self.options = options
        
        height = len(options)
        width+=5
        height+=2
        #self.header_pos = (width//2)-len(header)
        
        self.window = game.gEngine.console_new(width, height)
        
        
        self.game.gEngine.console_set_alignment(self.window,2)
            
        self.width = width
        self.height = height
        self.w_pos = screen_width/2 - width/2
        self.h_pos = screen_height/2 - height/2
        
        self.is_visible = False
        self.can_drag = True
        
        self.last_input = 0
        libtcod.mouse_get_status()#this is to pick up stray mouse input that 
コード例 #20
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def get_names_under_mouse():
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    names = [
        obj.name for obj in objects if obj.x == x and obj.y == y
        and libtcod.map_is_in_fov(fov_map, obj.x, obj.y)
    ]

    names = ', '.join(names)
    return names.capitalize()
コード例 #21
0
ファイル: game.py プロジェクト: w5748/Untitled-Roguelike
def get_names_under_mouse():
    #return a string with the names of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)
 
    #THIS MATH IS ALL BROKEN
    names = [obj.name for obj in objects
        if player.x - obj.x + CAMERA_WIDTH / 2 == x and player.y - obj.y + CAMERA_HEIGHT / 2 == y and libtcod.map_is_in_fov(fov_map, obj.x, obj.y)]
 
    names = ', '.join(names)  #join the names, separated by commas
    return names.capitalize()
コード例 #22
0
ファイル: dialog_box.py プロジェクト: GrishdaFish/Ascension
    def __init__(self,game,width,height,x_pos,y_pos,body_text,type='dialog',
        option_labels=None,con=None):
##============================================================================
        self.game = game
        self.width = width
        self.con = 0#con
        #if con is None:
        #    self.con = 0
        self.height = height
        self.x_pos = x_pos
        self.y_pos = y_pos
        self.buttons = []
        self.body_text = body_text
        self.window = game.gEngine.console_new(self.width,self.height)
        self.body_height = game.gEngine.console_get_height_rect(self.window, 1, 1,
            self.width, self.height, body_text)

        if self.body_height > self.height-2:
            self.game.gEngine.console_remove_console(self.window)
            self.height = self.body_height+2
            self.window = game.gEngine.console_new(self.width,self.height)

        if type is None or type == 'dialog':
            self.run = self.dialog_box
            self.option_labels = option_labels
            if option_labels is None:
                self.option_labels = ['Ok']
            self.buttons.append(button.Button(parent=self,label=self.option_labels[0],
                x_pos=self.width//2-5,y_pos=self.height/2-1,type=True))

        elif type == 'option':
            self.run = self.option_box
            self.option_labels = option_labels
            if option_labels is None:
                self.option_labels = ['Yes', 'No']
            self.buttons.append(button.Button(parent=self,label=self.option_labels[0],
                x_pos=1 ,y_pos=self.height/2-1,type=True))
            self.buttons.append(button.Button(parent=self,label=self.option_labels[1],
                x_pos=self.width-7,y_pos=self.height/2-1,type=False))
        self.last_input=0
        libtcod.mouse_get_status()
コード例 #23
0
ファイル: game.py プロジェクト: GrishdaFish/Ascension
    def get_names_under_mouse(self):
##============================================================================
        #return a string with the names of all objects under the mouse
        mouse = libtcod.mouse_get_status()
        (x, y) = (mouse.cx, mouse.cy)
     
        #create a list with the names of all objects at the mouse's coordinates and in FOV
        names = [obj.name for obj in self.objects
            if obj.x == x and obj.y == y and libtcod.map_is_in_fov(self.fov_map, obj.x, obj.y)]
     
        names = ', '.join(names)  #join the names, separated by commas
        return names.capitalize()
コード例 #24
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
def get_names_under_mouse():
    #return a string with the names of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    #create a list with names of all objects at the mouse's coords and in FoV
    names = [
        obj.name for obj in objects if obj.x == x and obj.y == y
        and libtcod.map_is_in_fov(fov_map, obj.x, obj.y)
    ]

    names = ', '.join(names)
    return names.capitalize()
コード例 #25
0
def getNamesUnderMouse():
    #returns a tring with the name of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    #make a list with name of all objects under mouse and in FOV
    names = []
    for object in objects:
        if object.x == x and object.y == y and libtcod.map_is_in_fov(
                fovMap, object.x, object.y):
            names.append(object.name)

    #Join all the names in to one string
    names = ", ".join(names)
    return names.capitalize()
コード例 #26
0
ファイル: Jules-Quest.py プロジェクト: okiyama/Jules-Quest
def getNamesUnderMouse():
    #returns a tring with the name of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    #make a list with name of all objects under mouse and in FOV
    names =[]
    for object in objects:
        if object.x == x and object.y == y and libtcod.map_is_in_fov(fovMap,
            object.x, object.y):
            names.append(object.name)

    #Join all the names in to one string
    names = ", ".join(names)
    return names.capitalize()
コード例 #27
0
ファイル: Pythfinder.py プロジェクト: Vbitz/Pythfinder
def get_names_under_mouse():
    # return a string with the names of all objects under the mouse
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)
    # create a list with the names of all objects at the mouse's coordinates and in FOV
    names = []
    if x < MAP_WIDTH and y < MAP_HEIGHT and libtcod.map_is_in_fov(fov_map, x, y):
        names = [obj.name for obj in objects if obj.x == x and obj.y == y]
        names += [item.name for item in map[x][y].stash]
        if not len(names):
            if map[x][y].blocked:
                names.append('wall')
            else:
                names.append('floor')
    names = ', '.join(names)  #join the names, separated by commas
    return names.capitalize()
コード例 #28
0
ファイル: main.py プロジェクト: amelim/Pixel-Command
def main():

    libtcod.console_set_custom_font(FONT, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.sys_set_fps(20)
    libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Junta!', False)
    main_map.units.append(Unit(60,60, 'ship', 'Destroyer A-2', 1, 20, 5, main_map, libtcod.CHAR_ARROW2_N))
    main_map.units.append(Unit(169,150, 'infantry', 'Recon Platoon', 10, 4, 2, main_map, libtcod.CHAR_DARROW_V))
    main_map.units.append(Unit(173, 151, 'infantry', 'Weapons Team', 10, 3, 2, main_map, libtcod.CHAR_DARROW_V))


    while not libtcod.console_is_window_closed():
    	mouse = libtcod.mouse_get_status()
    	#print main_map.map_list[mouse.cx + cam.x][mouse.cy + cam.y].land_type
    	handle_keys(mouse)
    	update()
    	render(mouse)
    	libtcod.console_flush()
コード例 #29
0
ファイル: Jules-Quest.py プロジェクト: okiyama/Jules-Quest
def targetTile(maxRange=None):
    #Returns the position of the tile in player's FOV
    #Should be expanded to blink the radius of the spell with a given color
    while True:
        renderAll()
        libtcod.console_flush()

        key = libtcod.console_check_for_keypress()
        mouse = libtcod.mouse_get_status()
        (x, y) = mouse.cx, mouse.cy

        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fovMap, x, y)) and (maxRange == None or player.distance(x, y) <= maxRange):
            return (x, y)
        if mouse.rbutton_pressed:
            #cancel if they right click, might want to add more ways to cancel
            message("Spell canceled.", libtcod.white)
            return (None, None)
コード例 #30
0
ファイル: Pythfinder.py プロジェクト: Vbitz/Pythfinder
def render_all():
    global fov_recompute
    fov_recompute = True
    # go through all tiles, and set their background color according to the FOV
    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)
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = libtcod.map_is_in_fov(fov_map, x, y)
            wall = map[x][y].block_sight
            if not visible: # it's out of the player's FOV
                if map[x][y].explored:
                    libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(False))
            else: # it's visible
                libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(True))
                mouse = libtcod.mouse_get_status()
                if x == mouse.cx and y == mouse.cy:
                    libtcod.console_set_back(con, x, y, libtcod.yellow, libtcod.BKGND_SET)
                map[x][y].explored = True    
    for object in objects:
        if libtcod.map_is_in_fov(fov_map, object.x, object.y):
            object.draw()
    player.draw()
    # prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
    # print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1
    # show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.dark_green, libtcod.red)

    # display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())
    
    # Display on main console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
コード例 #31
0
ファイル: game.py プロジェクト: nrberens/Purge
def target_tile(max_range=None):
	global key, mouse
	#return the position of a tile libtcod.LEFT-clicked in config.player's FOV (optionally in a range), or (None, None) if right-clicked.
	while True:
		#render the screen. this erases the config.inventory and shows the names of config.objects under the mouse.
		gfx.render_all()
		libtcod.console_flush()
		
		key = libtcod.console_check_for_keypress()
		mouse = libtcod.mouse_get_status() #get mouse position and click status
		(x, y) = (mouse.cx, mouse.cy)
		
		if (mouse.lbutton_pressed and libtcod.map_is_in_fov(config.fov_map, x, y) and
			(max_range is None or config.player.distance(x, y) <= max_range)):
			return (x, y)
		
		if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
			return (None, None) #cancel if the config.player right-clicked or pressed escape
コード例 #32
0
ファイル: renderer.py プロジェクト: SkyMocha/ASCII-RougeLike
def renderSidePanel(console, entities, fov_map):
    mouse = tcod.mouse_get_status()

    x_zero = SCREEN_WIDTH + 1
    entitiesHighlighted = get_entity_under_mouse(mouse, entities, fov_map)

    if (entitiesHighlighted):
        for entity in entitiesHighlighted:
            # Prints name of entity
            tcod.console_set_default_background(console, tcod.white)
            tcod.console_print_ex(console, x_zero + 1, 1, tcod.BKGND_NONE,
                                  tcod.LEFT, entity.name)

            # Prints health bar of entity
            if (entity.ai):
                render_bar(console, x_zero + 1, 3, 20, 'HP', entity._class.hp,
                           entity._class.max_hp, tcod.light_red,
                           tcod.darker_red)
コード例 #33
0
ファイル: window.py プロジェクト: Alberdi/rogueforce
    def loop(self):
        turn = 0
        turn_time = 0.1
        key = libtcod.Key()
        mouse = libtcod.Mouse()
        while not self.game_over:
            start = time.time()
            if turn > 0:
                if self.network:
                    received = self.network.recv()
                else:
                    ai = self.ai_action(turn)
                    if ai:
                        received = str(turn) + "#" + ai
                    else:
                        received = "D"
                split = received.split("#")
                if len(split) == 2:
                    self.messages[not self.side][int(split[0])] = split[1]

            while time.time() - start < turn_time:
                libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
                (x, y) = (mouse.cx - BG_OFFSET_X, mouse.cy - BG_OFFSET_Y)
                if key.vk == libtcod.KEY_ESCAPE:
                    return None
                s = self.check_input(key, libtcod.mouse_get_status(), x, y)
                if s is not None:
                    self.messages[self.side][turn] = s

            if self.network:
                if turn in self.messages[self.side]:
                    self.network.send(
                        str(turn) + "#" + self.messages[self.side][turn])
                else:
                    self.network.send("D")
            self.process_messages(turn - TURN_LAG)
            self.update_all()
            winner = self.check_winner()
            if (turn % 100) == 0: self.clean_all()
            self.do_hover(x, y)
            turn += 1
            self.render_all(x, y)

        return winner
コード例 #34
0
def handle_input():
	global MOUSE_POS, LAST_MOUSE_POS
	
	_mouse = tcod.mouse_get_status()
	_event = tcod.sys_check_for_event(tcod.EVENT_ANY, KEY, MOUSE)
	
	if KEY.c:
		_key_code = KEY.c
	else:
		_key_code = KEY.vk
	
	if _event == tcod.KEY_PRESSED:
		if not _key_code in INPUT:
			INPUT[_key_code] = 1
		else:
			INPUT[_key_code] += 1

		if '--keyout' in sys.argv and INPUT[_key_code] == 1:
			print KEY.c, KEY.vk, INPUT[_key_code]

	elif _event == tcod.KEY_RELEASED:
		INPUT[_key_code] = 0
	
	LAST_MOUSE_POS = MOUSE_POS[:]
	MOUSE_POS = [int(round(i)) for i in numbers.interp_velocity(LAST_MOUSE_POS, (_mouse.cx, _mouse.cy), .8)]
	
	if not MOUSE_POS == LAST_MOUSE_POS:
		events.trigger_event('mouse_moved',
		                     x=MOUSE_POS[0],
		                     y=MOUSE_POS[1],
		                     dx=MOUSE_POS[0]-LAST_MOUSE_POS[0],
		                     dy=MOUSE_POS[1]-LAST_MOUSE_POS[1])
	
	if _mouse.lbutton_pressed:
		events.trigger_event('mouse_pressed', x=MOUSE_POS[0], y=MOUSE_POS[1], button=1)
	
	if _mouse.rbutton_pressed:
		events.trigger_event('mouse_pressed', x=MOUSE_POS[0], y=MOUSE_POS[1], button=2)
	
	if _mouse.lbutton:
		events.trigger_event('mouse_held', x=MOUSE_POS[0], y=MOUSE_POS[1], button=1)
	
	if _mouse.rbutton:
		events.trigger_event('mouse_held', x=MOUSE_POS[0], y=MOUSE_POS[1], button=2)
コード例 #35
0
def targetTile(maxRange=None):
    #Returns the position of the tile in player's FOV
    #Should be expanded to blink the radius of the spell with a given color
    while True:
        renderAll()
        libtcod.console_flush()

        key = libtcod.console_check_for_keypress()
        mouse = libtcod.mouse_get_status()
        (x, y) = mouse.cx, mouse.cy

        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(
                fovMap, x, y)) and (maxRange == None
                                    or player.distance(x, y) <= maxRange):
            return (x, y)
        if mouse.rbutton_pressed:
            #cancel if they right click, might want to add more ways to cancel
            message("Spell canceled.", libtcod.white)
            return (None, None)
コード例 #36
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
def target_tile(max_range=None):
    #return the position of a left-cliked in player's FoV, and optionally in a range, or (none, none) if right-clicked
    while True:
        render_all()
        libtcod.console_flush()

        key = libtcod.console_check_for_keypress()
        mouse = libtcod.mouse_get_status()
        (x, y) = (mouse.cx, mouse.cy)

        #Returns the mouse position
        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y)
                and max_range is None
                or player.distance_to_coords(x, y) <= max_range):
            return (x, y)

        #Cancel if the player presses the right mouse or escape
        if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
            return (None, None)
コード例 #37
0
ファイル: window.py プロジェクト: Alberdi/rogueforce
  def loop(self):
    turn = 0
    turn_time = 0.1
    key = libtcod.Key()
    mouse = libtcod.Mouse()
    while not self.game_over:
      start = time.time()
      if turn > 0:
        if self.network:
          received = self.network.recv()
        else:
          ai = self.ai_action(turn)
          if ai:
            received = str(turn) + "#" + ai
          else:
            received = "D"
        split = received.split("#")
        if len(split) == 2:
          self.messages[not self.side][int(split[0])] = split[1]

      while time.time() - start < turn_time:
        libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
        (x, y) = (mouse.cx-BG_OFFSET_X, mouse.cy-BG_OFFSET_Y)
        if key.vk == libtcod.KEY_ESCAPE:
          return None
        s = self.check_input(key, libtcod.mouse_get_status(), x, y)
        if s is not None:
          self.messages[self.side][turn] = s

      if self.network:
        if turn in self.messages[self.side]:
          self.network.send(str(turn) + "#"  + self.messages[self.side][turn])
        else:
          self.network.send("D")
      self.process_messages(turn - TURN_LAG)
      self.update_all()
      winner = self.check_winner()
      if (turn % 100) == 0: self.clean_all()
      self.do_hover(x, y)
      turn +=1
      self.render_all(x, y)

    return winner
コード例 #38
0
ファイル: spells.py プロジェクト: GrishdaFish/Ascension
def target_tile(game, max_range=None):
    #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked.
    while True:
        #render the screen. this erases the inventory and shows the names of objects under the mouse.
        game.render_all()
        libtcod.console_flush()

        key = libtcod.console_check_for_keypress()
        mouse = libtcod.mouse_get_status(
        )  #get mouse position and click status
        (x, y) = (mouse.cx, mouse.cy)

        if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
            return (None, None
                    )  #cancel if the player right-clicked or pressed Escape

        #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range
        if (mouse.lbutton_pressed
                and libtcod.map_is_in_fov(game.fov_map, x, y) and
            (max_range is None or game.player.distance(x, y) <= max_range)):
            return (x, y)
コード例 #39
0
def handle_mouse():
    global selected
    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

    #pressed = 0 #clearing generic output signal from any logic

    if mouse.lbutton_pressed:
        print "boop"
        found = False
        for city in R.cities:
            if city.x == x + cam_x and city.y == y + cam_y:
                selected = city
                update_info_bar()
                found = True

        for obj in R.world_obj:
            if obj.x == x and obj.y == y:
                selected = obj
                update_info_bar()
                found = True
        if found == False and R.world.w >= (x + cam_x) and R.world.h >= (
                y + cam_y):
            print str(
                R.world.tiles[x + cam_x][y + cam_y].temperature) + "/" + str(
                    R.world.tiles[x + cam_x][y + cam_y].elevation)
コード例 #40
0
def handle_mouse():
    global selected
    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 mouse.lbutton_pressed:
        selected = []
        print "mouse", x, y, "world", x + cam_x, y + cam_y
        found = False
        for poi in R.pois:
            if poi.x == x + cam_x and poi.y == y + cam_y:
                selected.append(poi)
                update_info_bar()
                found = True
                #
                #        for city in R.cities:
                #            if city.x == x + cam_x and city.y == y + cam_y:
                #                selected = city
                #                update_info_bar()
                #                found = True

        for obj in R.world_obj:
            if obj.x == cam_x + x and obj.y == cam_y + y:
                selected.append(obj)
                update_info_bar()
                found = True
コード例 #41
0
def handle_keys(game):

    libtcod.console_flush()

    event = libtcod.sys_check_for_event(1 | 4 | 8 | 16, key, mouse)
    mousestatus = libtcod.mouse_get_status()

    (a, b) = game.upper_left_of_map()
    (x, y) = (mousestatus.cx + a, mousestatus.cy + b)

    #If the player clicks an acceptable tile, build a path to that location and start pathing toward it.

    if mousestatus.lbutton_pressed and game.map[x][y].explored:
        game.state = 'pathing'
        fov_pathing_map = map.new_fov_pathing_map(game.map)
        game.player.mover.path = libtcod.path_new_using_map(
            fov_pathing_map, 1.41)
        libtcod.path_compute(game.player.mover.path, game.player.x,
                             game.player.y, x, y)

    # Full screen / window switching
    if key.vk == libtcod.KEY_ENTER and (key.lalt | key.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    # This is a catch-all for situations where one needs to 'back out' of wherever one is.
    # An obvious one is to quit the game.
    if key.vk == libtcod.KEY_ESCAPE:
        return 'exit'

    # Movement keys - used if actually playing.
    if game.state == 'playing':

        dx = dy = 0

        key_char = chr(key.c)

        if key_char in ('q', 'w', 'e'):
            dy = -1

        if key_char in ('q', 'a', 'z'):
            dx = -1

        if key_char in ('z', 'x', 'c'):
            dy = 1

        if key_char in ('c', 'd', 'e'):
            dx = 1

        if key.vk == libtcod.KEY_UP:
            dy = -1

        elif key.vk == libtcod.KEY_DOWN:
            dy = 1

        elif key.vk == libtcod.KEY_LEFT:
            dx = -1

        elif key.vk == libtcod.KEY_RIGHT:
            dx = 1

        elif key_char in ('1'):
            game.debug_showexplored = not (game.debug_showexplored)

        elif key_char in ('2'):
            game.debug_troubletiles = not (game.debug_troubletiles)

        # Eventually, need keys for working with inventory and items.

        if (dx | dy):
            action = actors.player_move(game, dx, dy)
            if action is not 'blocked':
                game.map_movement = True
                return 'tookturn'

    elif game.state == 'in menu':
        pass

    else:
        return 'no action'
コード例 #42
0
def test_mouse(console):
    libtcodpy.mouse_show_cursor(True)
    libtcodpy.mouse_is_cursor_visible()
    mouse = libtcodpy.mouse_get_status()
    repr(mouse)
    libtcodpy.mouse_move(0, 0)
コード例 #43
0
ファイル: main.py プロジェクト: orodley/stalker-rl
def play_arena(ui_con):
    console_buffer = tcod.ConsoleBuffer(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT)

    map_size = (constant.SCREEN_WIDTH * 1, constant.SCREEN_HEIGHT * 1)
    the_map = game_map.make_map(*map_size)
    fov_map = tcod.map_new(*map_size)

    player = entity.Entity(map_size[0] / 2, map_size[1] / 2, "@", tcod.black)
    player.inventory_component = item.Inventory(player, constant.INENTORY_SIZE[0],
                                constant.INENTORY_SIZE[1], constant.WEIGHT_LIMIT)


    blah = "Makarov PM"
    test_makarov = item.Item(blah, item_types.firearms[blah][-1])
    test_makarov.gun_component = item.Gun(test_makarov, *item_types.firearms[blah][:-1])
    makarov_entity = entity.Entity(map_size[0] / 2 + 1, map_size[1] / 2 + 1, "]",
                                   tcod.dark_grey, item_component=test_makarov,
                                   is_walkable=True)

    entity_list = [player, makarov_entity]

    camera_x, camera_y = (player.x, player.y)

    fov_map = fov.update_fov_map(the_map, fov_map)
    tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC)
    fov_recompute = True

    in_menu = False
    selected_inv_square = None

    test = tcod.image_load(os.path.join("images", "weapons", "Makarov PM.png"))
    tcod.image_set_key_color(test, tcod.pink)

    # Set initial values for key and mouse event; required to pass into sys_check_for_event
    key = tcod.console_check_for_keypress(tcod.KEY_PRESSED)
    mouse_status = tcod.mouse_get_status()
    
    while True:
        # Get input
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse_status)

        if not in_menu:
            # Update camera. This must be done before rendering
            (center_x, center_y) = geometry.get_point_ahead(player.x, player.y, mouse_status.cx + camera_x,
                                                   mouse_status.cy + camera_y, constant.CAMERA_DISTANCE)
            (camera_x, camera_y) = geometry.update_camera(center_x, center_y, the_map.width, the_map.height)
            player_facing_point = (mouse_status.cx, mouse_status.cy)

        # Update FOV
        if fov_recompute:
            tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC)
        fov.update_entity_fov(entity_list, the_map, fov_map)

        # Render the map and entities
        the_map.render(console_buffer, fov_map, camera_x, camera_y, player.x, player.y, *player_facing_point)
        console_buffer.blit(0)
        
        # Only entities in the player's line of sight should be drawn
        for _entity in reversed(entity_list):
            if fov.in_player_fov(_entity.x, _entity.y, player.x, player.y, mouse_status.cx + camera_x,
                                 mouse_status.cy + camera_y, fov_map):
                _entity.render(0, camera_x, camera_y)

        # fps display
        tcod.console_print_ex(0, constant.SCREEN_WIDTH - 1, 0, tcod.BKGND_NONE, tcod.RIGHT, str(tcod.sys_get_fps()))
        

        # If in inventory, draw inventory grid
        if in_menu == "inventory":
            tcod.mouse_show_cursor(True)
            tcod.console_clear(ui_con)
            ui.draw_checkerboard(ui_con, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1],
                                 constant.SQUARE_SIZE, tcod.grey, tcod.dark_grey)
            ui.draw_inventory_items(ui_con, player.inventory_component)
            if selected_inv_square is not None:
                tcod.console_print_frame(ui_con, selected_inv_square[0] * constant.SQUARE_SIZE,
                                                 selected_inv_square[1] * constant.SQUARE_SIZE,
                                                 constant.SQUARE_SIZE, constant.SQUARE_SIZE, False, tcod.BKGND_NONE, False)
            tcod.console_blit(ui_con, 0, 0, constant.INENTORY_SIZE[0] * constant.SQUARE_SIZE,
                              constant.INENTORY_SIZE[1] * constant.SQUARE_SIZE, 0, constant.INVENTORY_X, constant.INVENTORY_Y)

        tcod.console_flush()
        fov_recompute = False

        # Handle input
        if not in_menu:
            if key.vk == tcod.KEY_LEFT: # Move left
                if not entity.check_collision(player.x - 1, player.y, the_map, entity_list):
                    player.x -= 0 if player.x == 0 else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_RIGHT: # Move right
                if not entity.check_collision(player.x + 1, player.y, the_map, entity_list):
                    player.x += 0 if player.x == the_map.width else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_UP: # Move up
                if not entity.check_collision(player.x, player.y - 1, the_map, entity_list):
                    player.y -= 0 if player.y == 0 else 1
                    fov_recompute = True
            elif key.vk == tcod.KEY_DOWN: # Move down
                if not entity.check_collision(player.x, player.y + 1, the_map, entity_list):
                    player.y += 0 if player.y == the_map.height else 1
                    fov_recompute = True
            elif key.c == ord("i"):
                in_menu = "inventory"
            elif key.c == ord(","):
                for _entity in entity_list:
                    if (_entity.item_component is not None and
                            _entity.x == player.x and
                            _entity.y == player.y):
                        player.inventory_component.add(_entity.item_component)
                        entity_list.remove(_entity)
                        
                                                              
            elif key.vk == tcod.KEY_ESCAPE: # Quit back to main menu
                break
        elif in_menu == "inventory":
            if mouse_status.lbutton_pressed:
                prev_square = selected_inv_square
                selected_inv_square = ((mouse_status.cx - constant.INVENTORY_X) / constant.SQUARE_SIZE,
                                       (mouse_status.cy - constant.INVENTORY_Y) / constant.SQUARE_SIZE)
                if selected_inv_square == prev_square:
                    selected_inv_square = None
                elif not ((0 <= selected_inv_square[0] < constant.INENTORY_SIZE[0]) and
                          (0 <= selected_inv_square[1] < constant.INENTORY_SIZE[1])):
                    selected_inv_square = prev_square
            elif key.c == ord("i"):
                tcod.mouse_show_cursor(False)
                in_menu = ""
コード例 #44
0
ファイル: input.py プロジェクト: GeorgeShannon/Destard
def handle_keys(game):

    libtcod.console_flush()

    event = libtcod.sys_check_for_event(1|4|8|16, key, mouse)
    mousestatus = libtcod.mouse_get_status()

    (a, b) = game.upper_left_of_map()
    (x, y) = (mousestatus.cx + a, mousestatus.cy + b)

    #If the player clicks an acceptable tile, build a path to that location and start pathing toward it.

    if mousestatus.lbutton_pressed and game.map[x][y].explored:
        game.state = 'pathing'
        fov_pathing_map = map.new_fov_pathing_map(game.map)
        game.player.mover.path = libtcod.path_new_using_map(fov_pathing_map, 1.41)
        libtcod.path_compute(game.player.mover.path, game.player.x, game.player.y, x, y)

    # Full screen / window switching
    if key.vk == libtcod.KEY_ENTER and (key.lalt | key.ralt): libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    # This is a catch-all for situations where one needs to 'back out' of wherever one is.
    # An obvious one is to quit the game.
    if key.vk == libtcod.KEY_ESCAPE:
        return 'exit'

    # Movement keys - used if actually playing.
    if game.state == 'playing':

        dx=dy=0

        key_char = chr(key.c)

        if key_char in ('q','w','e'):
            dy = -1

        if key_char in ('q','a','z'):
            dx = -1

        if key_char in ('z','x','c'):
            dy = 1

        if key_char in ('c','d','e'):
            dx = 1

        if key.vk == libtcod.KEY_UP:
            dy = -1

        elif key.vk == libtcod.KEY_DOWN:
            dy = 1

        elif key.vk == libtcod.KEY_LEFT:
            dx = -1

        elif key.vk == libtcod.KEY_RIGHT:
            dx = 1

        elif key_char in ('1'):
            game.debug_showexplored = not(game.debug_showexplored)

        elif key_char in ('2'):
            game.debug_troubletiles = not(game.debug_troubletiles)

        # Eventually, need keys for working with inventory and items.

        if (dx | dy):
            action = actors.player_move(game, dx, dy)
            if action is not 'blocked':
                game.map_movement = True
                return 'tookturn'

    elif game.state == 'in menu': pass

    else: return 'no action'
コード例 #45
0
def menu(con,
         header,
         options,
         width,
         SCREEN_HEIGHT,
         SCREEN_WIDTH,
         bg=None,
         game=None,
         under=None):
    ##============================================================================
    ##for menus that dont need to have positions tracked
    if len(options) > 26:
        if game:
            game.logger.error('Cannot have a menu with more than 26 options.')
        raise ValueError('Cannot have a menu with more than 26 options.')

    if header == '':
        header = '======='
    if bg:
        img = game.gEngine.image_load(bg)
        game.gEngine.image_blit_2x(img, 0, 0, 0)

    height = len(options)
    width += 5
    height += 2
    header_pos = (width // 2) - len(header)

    window = game.gEngine.console_new(width, height)

    current_pick = 0
    y = 0
    letter_index = ord('a')
    w_pos = SCREEN_WIDTH / 2 - width / 2
    h_pos = SCREEN_HEIGHT / 2 - height / 2

    r, g, b = libtcod.white
    game.gEngine.console_set_default_foreground(window, r, g, b)
    original_header = header
    is_dragging = False
    in_drag_zone = False
    mouse_highlight = False
    mouse = None
    key = libtcod.console_check_for_keypress()
    first_run = True

    while key.vk is not libtcod.KEY_NONE:
        key = libtcod.console_check_for_keypress(True)

    while not libtcod.console_is_window_closed():
        game.gEngine.console_flush()
        game.gEngine.console_blit(window, 0, 0, width, height, 0, w_pos, h_pos,
                                  1.0, 1.0)

        game.gEngine.console_clear(window)

        game.gEngine.console_print_frame(window, 0, 0, width, height, False)

        game.gEngine.console_print(window, header_pos, 0, header)
        game.gEngine.console_print(window, 0, 0, chr(254))
        game.gEngine.console_print(window, width - 1, 0, chr(158))

        for i in range(len(options)):
            text = '(' + chr(letter_index) + ') ' + options[i]
            game.gEngine.console_print(window, 1, y + 1, text)
            y += 1
            letter_index += 1
        y = 0
        letter_index = ord('a')

        ##Menu Mouse Input
        mouse = libtcod.mouse_get_status()
        mx = mouse.cx - w_pos
        my = mouse.cy - h_pos

        ##for dragging
        if mouse.cx >= w_pos + header_pos and mouse.cx <= w_pos + header_pos + len(
                original_header) - 1 and mouse.cy == h_pos:
            in_drag_zone = True
            if not is_dragging:
                header = color_text(original_header, libtcod.red)
        else:
            header = color_text(original_header, libtcod.white)
            in_drag_zone = False

        if mouse.lbutton and not is_dragging and in_drag_zone:
            is_dragging = True
            header = color_text(original_header, libtcod.green)
            dragx = mx
            dragy = my

        elif not mouse.lbutton and is_dragging:
            is_dragging = False

        elif is_dragging:
            w_pos = mouse.cx - dragx
            h_pos = mouse.cy - dragy

        ##For Close button
        if mouse.cx == w_pos + width - 1 and mouse.cy == h_pos:
            t = color_text('X', libtcod.red)
            game.gEngine.console_print(window, width - 1, 0, t)
            if mouse.lbutton_pressed:
                if bg:
                    game.gEngine.image_delete(img)
                libtcod.mouse_get_status()
                return None

        ##For Menu Options
        if mouse.cx >= w_pos and mouse.cx <= w_pos + width:
            for i in range(len(options)):
                if my == i + 1:
                    t = '(' + chr(letter_index +
                                  i) + ') ' + options[i].capitalize()
                    text = color_text(t, color_f=libtcod.red)
                    game.gEngine.console_print(window, 1, i + 1, text)
                    mouse_highlight = True
                    mouse_choice = i
                    break
                else:
                    mouse_highlight = False

        ##bug here, after selecting a choice, the next menu gets "clicked" as well.
        ##if set to lbutton, only the last option in a list seems to work
        if mouse.lbutton and mouse_highlight:
            if bg:
                game.gEngine.image_delete(img)
            libtcod.mouse_get_status()
            return mouse_choice

        ##Menu Keyboard Input
        key = libtcod.console_check_for_keypress(True)

        index = key.c - ord('a')

        if key.vk == libtcod.KEY_ENTER and key.lalt:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        if key.vk == libtcod.KEY_ESCAPE:
            game.gEngine.console_remove_console(window)
            if bg:
                game.gEngine.image_delete(img)
            libtcod.console_check_for_keypress()
            return None

        if key:
            if index >= 0 and index < len(options):
                game.gEngine.console_remove_console(window)
                if bg:
                    game.gEngine.image_delete(img)
                libtcod.console_check_for_keypress()
                return index

        if key.vk == libtcod.KEY_DOWN:
            current_pick = (current_pick + 1) % len(options)

        if key.vk == libtcod.KEY_UP:
            current_pick = (current_pick - 1) % len(options)

        if key.vk == libtcod.KEY_ENTER:
            game.gEngine.console_remove_console(window)
            if bg:
                game.gEngine.image_delete(img)
            libtcod.console_check_for_keypress()
            return current_pick

        first_run = False
コード例 #46
0
def shop(con,
         player,
         game,
         container=None,
         bg=None,
         header=None,
         width=80,
         height=50,
         splash=False):
    """
    TODO:
        Make sure you cannot buy items if it were to put you over inventory limit - Done
        Attach this to a shopkeeper to control splash and inventory.
        Add a buyback screen to buy back things sold by accident

    :param con: Destination Console (not used atm)
    :param player: The Player Object
    :param game: The main game object
    :param container: The contents of the store
    :param bg: The background image to use
    :param header: The title of the store
    :param width: width of the shop
    :param height: height of the shop
    :param splash: Whether or not to display the splash screen
    :return: Nothing
    """
    if bg:
        dark_bg = game.gEngine.image_load(bg)
        bg = game.gEngine.image_load(bg)
        w, h = game.gEngine.image_get_size(dark_bg)
        for y in range(w):
            for x in range(h):
                col = game.gEngine.image_get_pixel(dark_bg, y, x)
                col = libtcod.color_lerp(col, libtcod.black, 0.9)
                #col = libtcod.color_lerp(col, libtcod.light_azure, 0.2)
                r, g, b = col
                game.gEngine.image_put_pixel(dark_bg, y, x, r, g, b)

    shop_height = 28
    compare_height = height - shop_height
    s_options = []
    s_gold = []
    s_size = 0
    if container:
        for obj in container:
            obj_text = color_text(obj.name.capitalize(), obj.color)
            ob_value = color_text(obj.item.value, libtcod.gold)
            ob_value = '(%s)' % ob_value
            s_gold.append(ob_value)
            opt = '[%s] ' % obj_text
            s_options.append(opt)
            if len(obj.name) + 2 > s_size:
                s_size = len(obj.name) + 2
    r, g, b = libtcod.white
    compare_y = shop_height

    inventory_window = game.gEngine.console_new(width / 2, height)
    game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
    game.gEngine.console_print_frame(inventory_window, 0, 0, width / 2, height,
                                     True)

    shop_window = game.gEngine.console_new(width / 2, shop_height)
    game.gEngine.console_set_default_foreground(shop_window, r, g, b)
    game.gEngine.console_print_frame(shop_window, 0, 0, width / 2, shop_height,
                                     True)

    compare_window = game.gEngine.console_new(width / 2, compare_height)
    game.gEngine.console_set_default_foreground(compare_window, r, g, b)
    game.gEngine.console_print_frame(compare_window, 0, 0, width / 2,
                                     compare_height, True)

    i_check_boxes = []
    s_check_boxes = []

    exit_button = Button(label='Exit',
                         game=game,
                         x_pos=(width / 2) - 9,
                         y_pos=height - 6,
                         window=inventory_window,
                         dest_x=width / 2,
                         dest_y=0)

    sell_button = Button(label='Sell',
                         game=game,
                         x_pos=1,
                         y_pos=height - 6,
                         window=inventory_window,
                         dest_x=width / 2,
                         dest_y=0)

    buy_button = Button(label='Buy',
                        game=game,
                        x_pos=1,
                        y_pos=compare_height - 6,
                        window=compare_window,
                        dest_x=0,
                        dest_y=compare_y)

    if len(player.fighter.inventory) == 0:
        inventory_items = ['Inventory is empty.']
    else:
        inventory_items = []
        for x in range(len(player.fighter.inventory)):
            i_check_boxes.append(CheckBox(x=1, y=x + 1))
            i = color_text(player.fighter.inventory[x].name.capitalize(),
                           player.fighter.inventory[x].color)
            if player.fighter.inventory[x].item.check_stackable:
                i += ' (%d)' % player.fighter.inventory[x].item.qty
            inventory_items.append(i)
    for x in range(len(container)):
        s_check_boxes.append(CheckBox(x=1, y=x + 1))

    i_header = 'Inventory'
    i_header_size = len(i_header)
    i_header_pos = (width / 4) - (i_header_size / 2)

    if header:
        s_header = header
    else:
        s_header = 'Shop'
    s_header_size = len(s_header)
    s_header_pos = (width / 4) - (s_header_size / 2)

    c_header = 'Compare/Examine'
    c_header_size = len(c_header)
    c_header_pos = (width / 4) - (c_header_size / 2)

    key = libtcod.console_check_for_keypress()
    mouse = libtcod.mouse_get_status()
    current_selection = 0
    s_current_selection = 0
    i_master_check = CheckBox(1, 30, "Check/Uncheck All")
    s_master_check = CheckBox(1, 26, "Check/Uncheck All")
    fade = 1
    if splash:
        splash_screen = game.gEngine.console_new(width, height)
    while key.vk != libtcod.KEY_ESCAPE:
        game.gEngine.console_flush()
        # get input just after flush
        key = libtcod.console_check_for_keypress(True)
        mouse = libtcod.mouse_get_status()
        exit_input = exit_button.display(mouse)
        sell_input = sell_button.display(mouse)
        buy_input = buy_button.display(mouse)

        game.gEngine.console_blit(inventory_window, 0, 0, width / 2, height, 0,
                                  (width / 2), 0, 1.0, 1.0)
        game.gEngine.console_blit(shop_window, 0, 0, width / 2, shop_height, 0,
                                  0, 0, 1.0, 1.0)
        game.gEngine.console_blit(compare_window, 0, 0, width / 2,
                                  compare_height, 0, 0, compare_y, 1.0, 1.0)
        if splash:
            if bg:
                if fade > 0:
                    game.gEngine.console_blit(splash_screen, 0, 0, width,
                                              height, 0, 0, 0, fade, fade)
                    game.gEngine.image_blit_2x(bg, splash_screen, 0, 0, 0, 0)
                    fade -= 0.045
                else:
                    fade = 0
        game.gEngine.console_clear(inventory_window)
        game.gEngine.console_clear(shop_window)
        game.gEngine.console_clear(compare_window)

        # set up draw screen
        r, g, b = libtcod.white

        # ========================================================================
        # print inventory
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg, inventory_window, 0, 0, width,
                                       0)
        game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
        game.gEngine.console_print_frame(inventory_window, 0, 0, width / 2,
                                         height, False)
        game.gEngine.console_print(inventory_window, i_header_pos, 0, i_header)
        if len(player.fighter.inventory) > 0:
            letter_index = ord('a')
            y = 1
            for i in range(len(inventory_items)):
                text = '  (' + chr(letter_index) + ') ' + inventory_items[i]
                if current_selection == y - 1:
                    r, g, b = libtcod.color_lerp(
                        player.fighter.inventory[i].color, libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(
                        inventory_window, r, g, b)
                else:
                    game.gEngine.console_set_default_background(
                        inventory_window, 0, 0, 0)
                game.gEngine.console_print_ex(inventory_window, 1, y,
                                              libtcod.BKGND_SET, libtcod.LEFT,
                                              text)
                y += 1
                letter_index += 1
        game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        game.gEngine.console_print(
            inventory_window, 1, 31,
            'Gold: ' + color_text(str(player.fighter.money), libtcod.gold))
        r, g, b = libtcod.white

        # ========================================================================
        # Print Shop Window
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg, shop_window, 0, 0)
        game.gEngine.console_set_default_foreground(shop_window, r, g, b)
        game.gEngine.console_print_frame(shop_window, 0, 0, width / 2,
                                         shop_height, False)
        game.gEngine.console_print(shop_window, s_header_pos, 0, s_header)
        if len(s_options) > 0:
            letter_index = ord('0')
            y = 1
            for i in range(len(s_options)):
                text = '  (' + chr(letter_index) + ') ' + s_options[i]
                if s_current_selection == y - 1:
                    rr, gg, bb = libtcod.color_lerp(container[i].color,
                                                    libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(
                        shop_window, rr, gg, bb)
                else:
                    game.gEngine.console_set_default_background(
                        shop_window, 0, 0, 0)
                game.gEngine.console_print_ex(shop_window, 1, y,
                                              libtcod.BKGND_SET, libtcod.LEFT,
                                              text)
                game.gEngine.console_print_ex(shop_window, s_size + 10, y,
                                              libtcod.BKGND_SET, libtcod.RIGHT,
                                              s_gold[i])
                y += 1
                letter_index += 1
            game.gEngine.console_set_default_background(
                inventory_window, 0, 0, 0)
            r, g, b = libtcod.white

        # ========================================================================
        # Print Compare Window
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg,
                                       compare_window,
                                       0,
                                       0,
                                       sx=0,
                                       sy=compare_y * 2)
        game.gEngine.console_set_default_foreground(compare_window, r, g, b)
        game.gEngine.console_print_frame(compare_window, 0, 0, width / 2,
                                         compare_height, False)
        game.gEngine.console_print(compare_window, c_header_pos, 0, c_header)

        # ========================================================================
        # handle mouse input
        # ========================================================================
        #Render check boxes
        #inventory check boxes
        i_mc = i_master_check.update(mouse, width)
        i_master_check.render(inventory_window, game)
        sell_value = 0
        if not i_mc:
            for box in i_check_boxes:
                box.update(mouse, width)
                box.render(inventory_window, game)
                if box.get_checked():
                    sell_value += player.fighter.inventory[box.y -
                                                           1].item.value / 2
        else:
            for box in i_check_boxes:
                box.set_checked(i_master_check.get_checked())
                box.render(inventory_window, game)
                if box.get_checked():
                    sell_value += player.fighter.inventory[box.y -
                                                           1].item.value / 2
        game.gEngine.console_print(
            inventory_window, 1, 32,
            'Sell Value: ' + color_text(str(sell_value), libtcod.gold))

        #Shop check boxes
        s_mc = s_master_check.update(mouse)
        s_master_check.render(shop_window, game)
        buy_value = 0
        if not s_mc:
            for box in s_check_boxes:
                box.update(mouse)
                box.render(shop_window, game)
                if box.get_checked():
                    buy_value += container[box.y - 1].item.value
        else:
            for box in s_check_boxes:
                box.set_checked(s_master_check.get_checked())
                box.render(shop_window, game)
                if box.get_checked():
                    buy_value += container[box.y - 1].item.value
        game.gEngine.console_print(
            shop_window, 1, 25,
            'Buy Value: ' + color_text(str(buy_value), libtcod.gold))

        # Inventory input
        if mouse.cx >= width / 2 + 3 and mouse.cx < width - 2:  # inventory screen dims
            if (mouse.cy - 1) < len(
                    player.fighter.inventory) and mouse.cy - 1 >= 0:
                item = player.fighter.inventory[mouse.cy - 1]
                current_selection = mouse.cy - 1
                game.gEngine.console_set_default_background(
                    compare_window, 0, 0, 0)
                if item.item.equipment:
                    game.gEngine.console_print_ex(
                        compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT,
                        'Name    : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT,
                        'Type    : ' + item.item.equipment.type.capitalize())
                    if item.item.equipment.type == 'melee':
                        damage = '%dd%d+%d' % (
                            item.item.equipment.damage.nb_dices,
                            item.item.equipment.damage.nb_faces,
                            item.item.equipment.damage.addsub)
                        game.gEngine.console_print_ex(compare_window, 1, 4,
                                                      libtcod.BKGND_SET,
                                                      libtcod.LEFT,
                                                      'Damage  : ' + damage)
                        game.gEngine.console_print_ex(
                            compare_window, 1, 5, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 7, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Skill   : ' + item.item.equipment.damage_type)
                    else:
                        game.gEngine.console_print_ex(
                            compare_window, 1, 4, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 5, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 7, libtcod.BKGND_SET,
                            libtcod.LEFT, 'Location: ' +
                            item.item.equipment.location.capitalize())
                    game.gEngine.console_print_ex(
                        compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT,
                        'Value   : ' + str(item.item.value))
                if item.item.spell:
                    game.gEngine.console_print_ex(
                        compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT,
                        'Name  : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT,
                        'Type  : ' + item.item.spell.type.capitalize())
                    game.gEngine.console_print_ex(
                        compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT,
                        'Power : ' + str(item.item.spell.min) + '-' +
                        str(item.item.spell.max))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT,
                        'Range : ' + str(item.item.spell.range))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT,
                        'Radius: ' + str(item.item.spell.radius))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT,
                        'Value : ' + str(item.item.value))
                if mouse.lbutton_pressed:
                    i_n = color_text(item.name.capitalize(), item.color)
                    price = color_text(item.item.value / 2, libtcod.gold)
                    message = 'Sell %s for %s?' % (i_n, price)
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 4,
                                      height / 2,
                                      message,
                                      type='option',
                                      con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:
                        player.fighter.money += item.item.value / 2
                        player.fighter.inventory.remove(item)
                        inventory_items = []
                        i_check_boxes = []
                        for x in range(len(player.fighter.inventory)):
                            i_check_boxes.append(CheckBox(x=1, y=x + 1))
                            i = color_text(
                                player.fighter.inventory[x].name.capitalize(),
                                player.fighter.inventory[x].color)
                            if player.fighter.inventory[
                                    x].item.check_stackable:
                                i += ' (%d)' % player.fighter.inventory[
                                    x].item.qty
                            inventory_items.append(i)

        # shop input
        if mouse.cx >= 0 and mouse.cx < width / 2 - 2:  # shop screen dims
            if (mouse.cy - 1) < len(container) and mouse.cy - 1 >= 0:
                item = container[mouse.cy - 1]
                s_current_selection = mouse.cy - 1
                game.gEngine.console_set_default_background(
                    compare_window, 0, 0, 0)
                if item.item.equipment:
                    game.gEngine.console_print_ex(
                        compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT,
                        'Name    : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT,
                        'Type    : ' + item.item.equipment.type.capitalize())
                    if item.item.equipment.type == 'melee':
                        damage = '%dd%d+%d' % (
                            item.item.equipment.damage.nb_dices,
                            item.item.equipment.damage.nb_faces,
                            item.item.equipment.damage.addsub)
                        game.gEngine.console_print_ex(compare_window, 1, 4,
                                                      libtcod.BKGND_SET,
                                                      libtcod.LEFT,
                                                      'Damage  : ' + damage)
                        game.gEngine.console_print_ex(
                            compare_window, 1, 5, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 7, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Skill   : ' + item.item.equipment.damage_type)
                    else:
                        game.gEngine.console_print_ex(
                            compare_window, 1, 4, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 5, libtcod.BKGND_SET,
                            libtcod.LEFT,
                            'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print_ex(
                            compare_window, 1, 7, libtcod.BKGND_SET,
                            libtcod.LEFT, 'Location: ' +
                            item.item.equipment.location.capitalize())
                    game.gEngine.console_print_ex(
                        compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT,
                        'Value   : ' + str(item.item.value))

                if item.item.spell:
                    game.gEngine.console_print_ex(
                        compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT,
                        'Name  : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT,
                        'Type  : ' + item.item.spell.type.capitalize())
                    game.gEngine.console_print_ex(
                        compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT,
                        'Power : ' + str(item.item.spell.min) + '-' +
                        str(item.item.spell.max))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT,
                        'Range : ' + str(item.item.spell.range))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT,
                        'Radius: ' + str(item.item.spell.radius))
                    game.gEngine.console_print_ex(
                        compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT,
                        'Value : ' + str(item.item.value))

                if mouse.lbutton_pressed and mouse.cx >= 3:
                    if len(player.fighter.inventory) >= 26:
                        if not item.item.check_stackable():
                            message = 'Not enough inventory space!'
                            w = len(message) + 2
                            d_box = DialogBox(game,
                                              w,
                                              10,
                                              width / 2 - w / 2,
                                              height / 2 - 5,
                                              message,
                                              type='dialog',
                                              con=inventory_window)
                            d_box.display_box()
                        else:
                            pass
                    elif item.item.value > player.fighter.money:
                        message = 'Not enough money!'
                        w = len(message) + 2
                        d_box = DialogBox(game,
                                          w,
                                          10,
                                          width / 2 - w / 2,
                                          height / 2 - 5,
                                          message,
                                          type='dialog',
                                          con=inventory_window)
                        d_box.display_box()
                        s_master_check.set_checked(False)
                        for box in s_check_boxes:
                            box.set_checked(s_master_check.get_checked())
                    else:
                        i_n = color_text(item.name.capitalize(), item.color)
                        price = color_text(item.item.value, libtcod.gold)
                        message = 'Buy %s for %s?' % (i_n, price)
                        w = len(message) + 2
                        d_box = DialogBox(game,
                                          w,
                                          10,
                                          width / 4,
                                          height / 2,
                                          message,
                                          type='option',
                                          con=inventory_window)
                        confirm = d_box.display_box()
                        if confirm == 1:
                            player.fighter.money -= item.item.value
                            #player.fighter.inventory.append(item)
                            item.item.pick_up(player.fighter.inventory)
                            container.remove(item)
                            inventory_items = []
                            i_check_boxes = []
                            for x in range(len(player.fighter.inventory)):
                                i_check_boxes.append(CheckBox(x=1, y=x + 1))
                                i = color_text(
                                    player.fighter.inventory[x].name.
                                    capitalize(),
                                    player.fighter.inventory[x].color)
                                if player.fighter.inventory[
                                        x].item.check_stackable:
                                    i += ' (%d)' % player.fighter.inventory[
                                        x].item.qty
                                inventory_items.append(i)
                            s_check_boxes = []
                            s_options = []
                            if container:
                                for obj in container:
                                    obj_text = color_text(
                                        obj.name.capitalize(), obj.color)
                                    ob_value = color_text(
                                        obj.item.value, libtcod.gold)
                                    ob_value = '(%s)' % ob_value
                                    s_gold.append(ob_value)
                                    opt = '[%s] ' % obj_text
                                    s_options.append(opt)
                                    if len(obj.name) + 2 > s_size:
                                        s_size = len(obj.name) + 2
                            for x in range(len(container)):
                                s_check_boxes.append(CheckBox(x=1, y=x + 1))

        # keyboard input
        index = key.c - ord('a')
        if key:
            if key.vk == libtcod.KEY_DOWN:
                if current_selection is None:
                    current_selection = 0
                current_selection += 1
                if current_selection > len(inventory_items):
                    current_selection = 0
            if key.vk == libtcod.KEY_UP:
                if current_selection is None:
                    current_selection = 0
                current_selection -= 1
                if current_selection < 0:
                    current_selection = len(inventory_items)
        # ========================================================================
        # handle buttons
        # ========================================================================

        # ========================================================================
        # Sell Button
        # ========================================================================
        for i in sell_input:
            if i != -1:
                message = 'Sell all selected items?'
                w = len(message) + 2
                d_box = DialogBox(game,
                                  w,
                                  10,
                                  width / 2 - w / 2,
                                  height / 2 - 5,
                                  message,
                                  type='option',
                                  con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    d_box.destroy_box()
                    i_master_check.set_checked(False)
                    items_to_sell = []
                    for box in i_check_boxes:
                        if box.get_checked():
                            items_to_sell.append(
                                player.fighter.inventory[box.y - 1])
                    for item_to_sell in items_to_sell:
                        if item_to_sell:
                            player.fighter.money += item_to_sell.item.value / 2
                            player.fighter.inventory.remove(item_to_sell)
                    i_check_boxes = []
                    inventory_items = []
                    for x in range(len(player.fighter.inventory)):
                        i_check_boxes.append(CheckBox(x=1, y=x + 1))
                        inventory_items.append(
                            color_text(
                                player.fighter.inventory[x].name.capitalize(),
                                player.fighter.inventory[x].color))
                else:
                    d_box.destroy_box()

        # ========================================================================
        # buy button
        # ========================================================================
        for i in buy_input:
            if i != -1:
                n = 0
                for box in s_check_boxes:
                    if box.get_checked():
                        n += 1
                if len(player.fighter.inventory) + n > 26:
                    message = 'Not enough inventory space!'
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 2 - w / 2,
                                      height / 2 - 5,
                                      message,
                                      type='dialog',
                                      con=inventory_window)
                    d_box.display_box()
                elif buy_value > player.fighter.money:
                    message = 'Not enough money!'
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 2 - w / 2,
                                      height / 2 - 5,
                                      message,
                                      type='dialog',
                                      con=inventory_window)
                    d_box.display_box()
                    s_master_check.set_checked(False)
                    for box in s_check_boxes:
                        box.set_checked(s_master_check.get_checked())
                else:
                    message = 'Buy all selected items?'
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 2 - w / 2,
                                      height / 2 - 5,
                                      message,
                                      type='option',
                                      con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:
                        #d_box.destroy_box()
                        s_master_check.set_checked(False)
                        items_to_buy = []
                        for box in s_check_boxes:
                            if box.get_checked():
                                items_to_buy.append(container[box.y - 1])
                        for item_to_buy in items_to_buy:
                            if item_to_buy:
                                container.remove(item_to_buy)
                                player.fighter.money -= item_to_buy.item.value
                                #player.fighter.inventory.append(item_to_buy)
                                item_to_buy.item.pick_up(
                                    player.fighter.inventory)

                        s_check_boxes = []
                        s_options = []
                        if container:
                            for obj in container:
                                obj_text = color_text(obj.name.capitalize(),
                                                      obj.color)
                                ob_value = color_text(obj.item.value,
                                                      libtcod.gold)
                                ob_value = '(%s)' % ob_value
                                s_gold.append(ob_value)
                                opt = '[%s] ' % obj_text
                                s_options.append(opt)
                                if len(obj.name) + 2 > s_size:
                                    s_size = len(obj.name) + 2
                        for x in range(len(container)):
                            s_check_boxes.append(CheckBox(x=1, y=x + 1))

                        i_check_boxes = []
                        inventory_items = []
                        for x in range(len(player.fighter.inventory)):
                            i_check_boxes.append(CheckBox(x=1, y=x + 1))
                            i = color_text(
                                player.fighter.inventory[x].name.capitalize(),
                                player.fighter.inventory[x].color)
                            if player.fighter.inventory[
                                    x].item.check_stackable:
                                i += ' (%d)' % player.fighter.inventory[
                                    x].item.qty
                            inventory_items.append(i)
            #else:
                    d_box.destroy_box()

        # ========================================================================
        # handle exit button
        # ========================================================================

        for i in exit_input:
            if i != -1:
                key.vk = libtcod.KEY_ESCAPE
                break
    # Remember to remove consoles in reverse order of creation to avoid OOB errors
    if splash:
        game.gEngine.console_remove_console(splash_screen)
    buy_button.destroy_button()
    sell_button.destroy_button()
    exit_button.destroy_button()
    game.gEngine.console_remove_console(compare_window)
    game.gEngine.console_remove_console(shop_window)
    game.gEngine.console_remove_console(inventory_window)

    return
コード例 #47
0
def town_menu(con, header, game, width, screen_height, screen_width):
    ##============================================================================
    options = [
        'The Helm and Buckler',
        "Johan's Weaporium",
        "Fizzilip's Magiteria",
        'Quests',
        'Finished',
    ]
    path = os.path.join(sys.path[0], 'content')
    path = path.replace('core.exe', '')
    backgrounds = [
        os.path.join(path, 'img', 'bg-arm.png'),
        os.path.join(path, 'img', 'bg-wep.png'),
        os.path.join(path, 'img', 'bg-magic.png'),
    ]
    container = []
    menus = []
    weapon, armor, consum, quest = [], [], [], []

    for i in range(10):  ##Need to init objects and message in object creation
        item = game.build_objects.build_equipment(game, 0, 0, 'melee')
        weapon.append(item)
        item = game.build_objects.build_equipment(game, 0, 0, 'armor')
        armor.append(item)
    for i in range(5):
        consume = game.build_objects.build_potion(game, 0, 0)
        consum.append(consume)
        consume = game.build_objects.build_scroll(game, 0, 0)
        consum.append(consume)

    container.append(armor)
    container.append(weapon)
    container.append(consum)
    container.append(quest)

    bg = os.path.join(path, 'img', 'bg-town.png')
    t_menu = Menus(game,
                   screen_height,
                   screen_width,
                   width,
                   header,
                   options,
                   bg=bg)

    while 1:
        t_menu.is_visible = True
        libtcod.mouse_get_status()
        index = t_menu.menu()
        if index == len(options) - 1 or index is None:
            t_menu.destroy_menu()
            break

        if index != (len(options) - 1) and index is not None and index != -1:
            game.gEngine.console_clear(0)
            t_menu.is_visible = False
            if index < (len(backgrounds)):
                item = SHOP(0,
                            game.player,
                            game,
                            container=container[index],
                            bg=backgrounds[index],
                            header=options[index])
                #item=shop(con,options[index],game,width,
                #    screen_height,screen_width,container[index],backgrounds[index])
            else:
                item = SHOP(0,
                            game.player,
                            game,
                            container=container[index],
                            header=options[index])
                #item=shop(con,options[index],game,width,
                #    screen_height,screen_width,container[index])
            if item is not None:
                container[index].pop(item)
            t_menu.last_input = 0
コード例 #48
0
ファイル: dialog_box.py プロジェクト: GrishdaFish/Ascension
    def mouse_input(self):
##============================================================================
        mouse = libtcod.mouse_get_status()
        mx = mouse.cx -self.x_pos
        my = mouse.cy -self.y_pos
コード例 #49
0
def shop(con,
         header,
         game,
         width,
         screen_height,
         screen_width,
         container,
         bg=None):
    ##============================================================================
    options = []
    cl_options = []
    if bg:
        img = libtcod.image_load(bg)
        #libtcod.image_blit_2x(img, 0, 0, 0)

    for obj in container:
        obj_text = obj.name
        ob_value = obj.item.value
        opt = '[%s] - Price: (%s) gold' % (obj_text, ob_value)
        cl_options.append(opt)

        obj_text = color_text(obj.name, obj.color)
        ob_value = color_text(str(obj.item.value), libtcod.gold)
        opt = '[%s] - Price: (%s) gold' % (obj_text, ob_value)
        options.append(opt)

    header = header + ' (' + str(game.player.fighter.money) + ' gold left)'
    shop = Menus(game,
                 screen_height,
                 screen_width,
                 width,
                 header,
                 options,
                 bg=bg,
                 cl_options=cl_options)
    shop.is_visible = True

    while 1:
        shop.is_visible = True
        libtcod.mouse_get_status()  #to prevent extra mouse clicks
        item = shop.menu()
        if item is not None and item is not -1:
            if game.player.fighter.money >= container[item].item.value:
                obj_text = color_text(container[item].name,
                                      container[item].color)
                ob_value = color_text(str(container[item].item.value),
                                      libtcod.gold)
                message = 'Purchase [%s] for (%s) gold?' % (obj_text, ob_value)
                w = len('Purchase [' + container[item].name + '] for (' +
                        str(container[item].item.value) + ') gold?') + 2
                d_box = DialogBox(game,
                                  w,
                                  10,
                                  20,
                                  20,
                                  message,
                                  type='option',
                                  con=shop.window)
                shop.is_visible = False
                confirm = d_box.display_box()
                if confirm == 1:
                    game.logger.log.debug(container[item].objects)
                    game.player.fighter.money -= container[item].item.value
                    game.player.fighter.inventory.append(container[item])
                    d_box.destroy_box()
                    shop.destroy_menu()
                    #game.logger.log.debug(container[item])
                    return item
                else:
                    d_box.destroy_box()
            else:
                message = 'Not enough gold!'
                d_box = DialogBox(game,
                                  len(message) + 2,
                                  10,
                                  20,
                                  20,
                                  message,
                                  con=shop.window)
                confirm = d_box.display_box()
                d_box.destroy_box()
        if item is None:
            shop.destroy_menu()
            return None
コード例 #50
0
    def mouse_input(self):
        ##============================================================================
        ##Menu Mouse Input
        mouse = libtcod.mouse_get_status()
        mx = mouse.cx - self.w_pos
        my = mouse.cy - self.h_pos

        ##for dragging
        if mx >= 2 and mx <= self.width - 2 and my == 0:
            self.in_drag_zone = True
            if not self.is_dragging:
                self.header = color_text(self.header_o, libtcod.red)
        else:
            if not self.is_dragging:
                self.header = color_text(self.header_o, libtcod.white)
                self.in_drag_zone = False

        if mouse.lbutton and not self.is_dragging and self.in_drag_zone:
            self.is_dragging = True
            self.header = color_text(self.header_o, libtcod.green)
            self.dragx = mx
            self.dragy = my

        elif not mouse.lbutton and self.is_dragging:
            self.is_dragging = False

        elif self.is_dragging and self.can_drag:
            self.w_pos = mouse.cx - self.dragx
            self.h_pos = mouse.cy - self.dragy

        ##For Close button
        if mouse.cx == self.w_pos + self.width - 1 and mouse.cy == self.h_pos and not self.is_dragging:
            t = color_text('X', libtcod.red)
            self.game.gEngine.console_print(self.window, self.width - 1, 0, t)
            if mouse.lbutton_pressed:
                libtcod.mouse_get_status()
                return 'close'

        ##For Menu Options
        letter_index = ord('a')
        if mouse.cx >= self.w_pos and mouse.cx <= self.w_pos + self.width and not self.is_dragging:
            for i in range(len(self.options)):
                if my == i + 1:
                    if self.cl_options is not None:
                        t = '(' + chr(
                            letter_index +
                            i) + ') ' + self.cl_options[i].capitalize()
                    else:
                        t = '(' + chr(letter_index +
                                      i) + ') ' + self.options[i].capitalize()
                    text = color_text(t, color_f=libtcod.red)
                    self.game.gEngine.console_print(self.window,
                                                    self.width / 2, i + 1,
                                                    text)
                    self.mouse_highlight = True
                    mouse_choice = i
                    break
                else:
                    self.mouse_highlight = False

        ##bug here, after selecting a choice, the next menu gets "clicked" as well.
        ##FIXED. Just called mouse_get_status() on __init__ and before a return
        ##to pick up unwanted input
        if mouse.lbutton_pressed and self.mouse_highlight and not self.is_dragging:
            if not mouse.lbutton:
                libtcod.mouse_get_status()
                return mouse_choice
        return -1
コード例 #51
0
    def __init__(self,
                 game,
                 width,
                 height,
                 x_pos,
                 y_pos,
                 body_text,
                 type='dialog',
                 option_labels=None,
                 con=None):
        ##============================================================================
        self.game = game
        self.width = width
        self.con = 0  #con
        #if con is None:
        #    self.con = 0
        self.height = height
        self.x_pos = x_pos
        self.y_pos = y_pos
        self.buttons = []
        self.body_text = body_text
        self.window = game.gEngine.console_new(self.width, self.height)
        self.body_height = game.gEngine.console_get_height_rect(
            self.window, 1, 1, self.width, self.height, body_text)

        if self.body_height > self.height - 2:
            self.game.gEngine.console_remove_console(self.window)
            self.height = self.body_height + 2
            self.window = game.gEngine.console_new(self.width, self.height)

        if type is None or type == 'dialog':
            self.run = self.dialog_box
            self.option_labels = option_labels
            if option_labels is None:
                self.option_labels = ['Ok']
            self.buttons.append(
                Button(parent=self,
                       label=self.option_labels[0],
                       x_pos=self.width // 2 - 5,
                       y_pos=self.height / 2 - 1,
                       type=True))

        elif type == 'option':
            self.run = self.option_box
            self.option_labels = option_labels
            if option_labels is None:
                self.option_labels = ['Yes', 'No']
            self.buttons.append(
                Button(parent=self,
                       label=self.option_labels[0],
                       x_pos=1,
                       y_pos=self.height / 2 - 1,
                       type=True))
            self.buttons.append(
                Button(parent=self,
                       label=self.option_labels[1],
                       x_pos=self.width - 7,
                       y_pos=self.height / 2 - 1,
                       type=False))
        self.last_input = 0
        libtcod.mouse_get_status()
コード例 #52
0
ファイル: shop.py プロジェクト: GrishdaFish/Ascension
def shop(con, player, game, container=None, bg=None, header=None, width=80, height=50, splash=False):
    """
    TODO:
        Make sure you cannot buy items if it were to put you over inventory limit - Done
        Attach this to a shopkeeper to control splash and inventory.
        Add a buyback screen to buy back things sold by accident

    :param con: Destination Console (not used atm)
    :param player: The Player Object
    :param game: The main game object
    :param container: The contents of the store
    :param bg: The background image to use
    :param header: The title of the store
    :param width: width of the shop
    :param height: height of the shop
    :param splash: Whether or not to display the splash screen
    :return: Nothing
    """
    if bg:
        dark_bg = game.gEngine.image_load(bg)
        bg = game.gEngine.image_load(bg)
        w, h = game.gEngine.image_get_size(dark_bg)
        for y in range(w):
            for x in range(h):
                col = game.gEngine.image_get_pixel(dark_bg, y, x)
                col = libtcod.color_lerp(col, libtcod.black, 0.9)
                #col = libtcod.color_lerp(col, libtcod.light_azure, 0.2)
                r, g, b = col
                game.gEngine.image_put_pixel(dark_bg, y, x, r, g, b)

    shop_height = 28
    compare_height = height - shop_height
    s_options = []
    s_gold = []
    s_size = 0
    if container:
        for obj in container:
            obj_text = color_text(obj.name.capitalize(), obj.color)
            ob_value = color_text(obj.item.value, libtcod.gold)
            ob_value = '(%s)' % ob_value
            s_gold.append(ob_value)
            opt = '[%s] ' % obj_text
            s_options.append(opt)
            if len(obj.name)+2 > s_size:
                s_size = len(obj.name)+2
    r, g, b = libtcod.white
    compare_y = shop_height

    inventory_window = game.gEngine.console_new(width/2, height)
    game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
    game.gEngine.console_print_frame(inventory_window, 0, 0, width/2, height, True)

    shop_window = game.gEngine.console_new(width/2, shop_height)
    game.gEngine.console_set_default_foreground(shop_window, r, g, b)
    game.gEngine.console_print_frame(shop_window, 0, 0, width/2, shop_height, True)

    compare_window = game.gEngine.console_new(width/2, compare_height)
    game.gEngine.console_set_default_foreground(compare_window, r, g, b)
    game.gEngine.console_print_frame(compare_window, 0, 0, width/2, compare_height, True)

    i_check_boxes = []
    s_check_boxes = []

    exit_button = Button(label='Exit', game=game, x_pos=(width/2)-9, y_pos=height-6,
                         window=inventory_window, dest_x=width/2, dest_y=0)

    sell_button = Button(label='Sell', game=game, x_pos=1, y_pos=height-6,
                         window=inventory_window, dest_x=width/2, dest_y=0)

    buy_button = Button(label='Buy', game=game, x_pos=1, y_pos=compare_height-6,
                        window=compare_window, dest_x=0, dest_y=compare_y)

    if len(player.fighter.inventory) == 0:
        inventory_items = ['Inventory is empty.']
    else:
        inventory_items = []
        for x in range(len(player.fighter.inventory)):
            i_check_boxes.append(CheckBox(x=1, y=x+1))
            i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
            if player.fighter.inventory[x].item.check_stackable:
                i += ' (%d)' % player.fighter.inventory[x].item.qty
            inventory_items.append(i)
    for x in range(len(container)):
        s_check_boxes.append(CheckBox(x=1, y=x+1))

    i_header = 'Inventory'
    i_header_size = len(i_header)
    i_header_pos = (width/4)-(i_header_size/2)

    if header:
        s_header = header
    else:
        s_header = 'Shop'
    s_header_size = len(s_header)
    s_header_pos = (width/4) - (s_header_size/2)

    c_header = 'Compare/Examine'
    c_header_size = len(c_header)
    c_header_pos = (width/4) - (c_header_size/2)

    key = libtcod.console_check_for_keypress()
    mouse = libtcod.mouse_get_status()
    current_selection = 0
    s_current_selection = 0
    i_master_check = CheckBox(1, 30, "Check/Uncheck All")
    s_master_check = CheckBox(1, 26, "Check/Uncheck All")
    fade = 1
    if splash:
        splash_screen = game.gEngine.console_new(width, height)
    while key.vk != libtcod.KEY_ESCAPE:
        game.gEngine.console_flush()
        # get input just after flush
        key = libtcod.console_check_for_keypress(True)
        mouse = libtcod.mouse_get_status()
        exit_input = exit_button.display(mouse)
        sell_input = sell_button.display(mouse)
        buy_input = buy_button.display(mouse)

        game.gEngine.console_blit(inventory_window, 0, 0, width/2, height, 0, (width/2), 0, 1.0, 1.0)
        game.gEngine.console_blit(shop_window, 0, 0, width/2, shop_height, 0, 0, 0, 1.0, 1.0)
        game.gEngine.console_blit(compare_window, 0, 0, width/2, compare_height, 0, 0, compare_y, 1.0, 1.0)
        if splash:
            if bg:
                if fade > 0:
                    game.gEngine.console_blit(splash_screen, 0, 0, width, height, 0, 0, 0, fade, fade)
                    game.gEngine.image_blit_2x(bg, splash_screen, 0, 0, 0, 0)
                    fade -= 0.045
                else:
                    fade = 0
        game.gEngine.console_clear(inventory_window)
        game.gEngine.console_clear(shop_window)
        game.gEngine.console_clear(compare_window)

        # set up draw screen
        r, g, b = libtcod.white

        # ========================================================================
        # print inventory
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg, inventory_window, 0, 0, width, 0)
        game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
        game.gEngine.console_print_frame(inventory_window, 0, 0, width/2, height, False)
        game.gEngine.console_print(inventory_window, i_header_pos, 0, i_header)
        if len(player.fighter.inventory) > 0:
            letter_index = ord('a')
            y = 1
            for i in range(len(inventory_items)):
                text = '  (' + chr(letter_index) + ') ' + inventory_items[i]
                if current_selection == y - 1:
                    r, g, b = libtcod.color_lerp(player.fighter.inventory[i].color, libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(inventory_window, r, g, b)
                else:
                    game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
                game.gEngine.console_print_ex(inventory_window, 1, y, libtcod.BKGND_SET, libtcod.LEFT, text)
                y += 1
                letter_index += 1
        game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        game.gEngine.console_print(inventory_window, 1, 31, 'Gold: ' + color_text(str(player.fighter.money), libtcod.gold))
        r, g, b = libtcod.white

        # ========================================================================
        # Print Shop Window
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg, shop_window, 0, 0)
        game.gEngine.console_set_default_foreground(shop_window, r, g, b)
        game.gEngine.console_print_frame(shop_window, 0, 0, width/2, shop_height, False)
        game.gEngine.console_print(shop_window, s_header_pos, 0, s_header)
        if len(s_options) > 0:
            letter_index = ord('0')
            y = 1
            for i in range(len(s_options)):
                text = '  (' + chr(letter_index) + ') ' + s_options[i]
                if s_current_selection == y -1:
                    rr, gg, bb = libtcod.color_lerp(container[i].color, libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(shop_window, rr, gg, bb)
                else:
                    game.gEngine.console_set_default_background(shop_window, 0, 0, 0)
                game.gEngine.console_print_ex(shop_window, 1, y, libtcod.BKGND_SET, libtcod.LEFT, text)
                game.gEngine.console_print_ex(shop_window, s_size+10, y, libtcod.BKGND_SET, libtcod.RIGHT, s_gold[i])
                y += 1
                letter_index += 1
            game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
            r, g, b = libtcod.white

        # ========================================================================
        # Print Compare Window
        # ========================================================================
        if bg:
            game.gEngine.image_blit_2x(dark_bg, compare_window, 0, 0, sx=0, sy=compare_y*2)
        game.gEngine.console_set_default_foreground(compare_window, r, g, b)
        game.gEngine.console_print_frame(compare_window, 0, 0, width/2, compare_height, False)
        game.gEngine.console_print(compare_window, c_header_pos, 0, c_header)

        # ========================================================================
        # handle mouse input
        # ========================================================================
        #Render check boxes
        #inventory check boxes
        i_mc = i_master_check.update(mouse, width)
        i_master_check.render(inventory_window, game)
        sell_value = 0
        if not i_mc:
            for box in i_check_boxes:
                box.update(mouse, width)
                box.render(inventory_window, game)
                if box.get_checked():
                    sell_value += player.fighter.inventory[box.y-1].item.value/2
        else:
            for box in i_check_boxes:
                box.set_checked(i_master_check.get_checked())
                box.render(inventory_window, game)
                if box.get_checked():
                    sell_value += player.fighter.inventory[box.y-1].item.value/2
        game.gEngine.console_print(inventory_window, 1, 32, 'Sell Value: ' + color_text(str(sell_value), libtcod.gold))

        #Shop check boxes
        s_mc = s_master_check.update(mouse)
        s_master_check.render(shop_window, game)
        buy_value = 0
        if not s_mc:
            for box in s_check_boxes:
                box.update(mouse)
                box.render(shop_window, game)
                if box.get_checked():
                    buy_value += container[box.y-1].item.value
        else:
            for box in s_check_boxes:
                box.set_checked(s_master_check.get_checked())
                box.render(shop_window, game)
                if box.get_checked():
                    buy_value += container[box.y-1].item.value
        game.gEngine.console_print(shop_window, 1, 25, 'Buy Value: ' + color_text(str(buy_value), libtcod.gold))

        # Inventory input
        if mouse.cx >= width/2+3 and mouse.cx < width-2:  # inventory screen dims
            if (mouse.cy-1) < len(player.fighter.inventory) and mouse.cy-1 >= 0:
                item = player.fighter.inventory[mouse.cy-1]
                current_selection = mouse.cy-1
                game.gEngine.console_set_default_background(compare_window, 0, 0, 0)
                if item.item.equipment:
                    game.gEngine.console_print_ex(compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT, 'Name    : ' + color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT, 'Type    : ' + item.item.equipment.type.capitalize())
                    if item.item.equipment.type == 'melee':
                        damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices, item.item.equipment.damage.nb_faces, item.item.equipment.damage.addsub )
                        game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Damage  : ' + damage)
                        game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Skill   : ' + item.item.equipment.damage_type)
                    else:
                        game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Location: ' + item.item.equipment.location.capitalize())
                    game.gEngine.console_print_ex(compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT, 'Value   : ' + str(item.item.value))
                if item.item.spell:
                    game.gEngine.console_print_ex(compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT, 'Name  : ' + color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT, 'Type  : ' + item.item.spell.type.capitalize())
                    game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Power : ' + str(item.item.spell.min) + '-' + str(item.item.spell.max))
                    game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Range : ' + str(item.item.spell.range))
                    game.gEngine.console_print_ex(compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT, 'Radius: ' + str(item.item.spell.radius))
                    game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Value : ' + str(item.item.value))
                if mouse.lbutton_pressed:
                    i_n = color_text(item.name.capitalize(), item.color)
                    price = color_text(item.item.value/2, libtcod.gold)
                    message = 'Sell %s for %s?' % (i_n, price)
                    w = len(message)+2
                    d_box = DialogBox(game, w, 10, width/4, height/2, message, type='option', con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:
                        player.fighter.money += item.item.value/2
                        player.fighter.inventory.remove(item)
                        inventory_items = []
                        i_check_boxes = []
                        for x in range(len(player.fighter.inventory)):
                            i_check_boxes.append(CheckBox(x=1, y=x+1))
                            i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
                            if player.fighter.inventory[x].item.check_stackable:
                                i += ' (%d)' % player.fighter.inventory[x].item.qty
                            inventory_items.append(i)

        # shop input
        if mouse.cx >= 0 and mouse.cx < width/2-2:  # shop screen dims
            if (mouse.cy-1) < len(container) and mouse.cy-1 >= 0:
                item = container[mouse.cy-1]
                s_current_selection = mouse.cy-1
                game.gEngine.console_set_default_background(compare_window, 0, 0, 0)
                if item.item.equipment:
                    game.gEngine.console_print_ex(compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT, 'Name    : ' + color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT, 'Type    : ' + item.item.equipment.type.capitalize())
                    if item.item.equipment.type == 'melee':
                        damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices, item.item.equipment.damage.nb_faces, item.item.equipment.damage.addsub )
                        game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Damage  : ' + damage)
                        game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Skill   : ' + item.item.equipment.damage_type)
                    else:
                        game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Location: ' + item.item.equipment.location.capitalize())
                    game.gEngine.console_print_ex(compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT, 'Value   : ' + str(item.item.value))

                if item.item.spell:
                    game.gEngine.console_print_ex(compare_window, 1, 2, libtcod.BKGND_SET, libtcod.LEFT, 'Name  : ' + color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print_ex(compare_window, 1, 3, libtcod.BKGND_SET, libtcod.LEFT, 'Type  : ' + item.item.spell.type.capitalize())
                    game.gEngine.console_print_ex(compare_window, 1, 4, libtcod.BKGND_SET, libtcod.LEFT, 'Power : ' + str(item.item.spell.min) + '-' + str(item.item.spell.max))
                    game.gEngine.console_print_ex(compare_window, 1, 5, libtcod.BKGND_SET, libtcod.LEFT, 'Range : ' + str(item.item.spell.range))
                    game.gEngine.console_print_ex(compare_window, 1, 6, libtcod.BKGND_SET, libtcod.LEFT, 'Radius: ' + str(item.item.spell.radius))
                    game.gEngine.console_print_ex(compare_window, 1, 7, libtcod.BKGND_SET, libtcod.LEFT, 'Value : ' + str(item.item.value))
                    
                if mouse.lbutton_pressed and mouse.cx >= 3:
                    if len(player.fighter.inventory) >= 26:
                        if not item.item.check_stackable():
                            message = 'Not enough inventory space!'
                            w = len(message)+2
                            d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='dialog', con=inventory_window)
                            d_box.display_box()
                        else:
                            pass
                    elif item.item.value > player.fighter.money:
                        message = 'Not enough money!'
                        w = len(message)+2
                        d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='dialog', con=inventory_window)
                        d_box.display_box()
                        s_master_check.set_checked(False)
                        for box in s_check_boxes:
                            box.set_checked(s_master_check.get_checked())
                    else:
                        i_n = color_text(item.name.capitalize(), item.color)
                        price = color_text(item.item.value, libtcod.gold)
                        message = 'Buy %s for %s?' % (i_n, price)
                        w = len(message)+2
                        d_box = DialogBox(game, w, 10, width/4, height/2, message, type='option', con=inventory_window)
                        confirm = d_box.display_box()
                        if confirm == 1:
                            player.fighter.money -= item.item.value
                            #player.fighter.inventory.append(item)
                            item.item.pick_up(player.fighter.inventory)
                            container.remove(item)
                            inventory_items = []
                            i_check_boxes = []
                            for x in range(len(player.fighter.inventory)):
                                i_check_boxes.append(CheckBox(x=1, y=x+1))
                                i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
                                if player.fighter.inventory[x].item.check_stackable:
                                    i += ' (%d)' % player.fighter.inventory[x].item.qty
                                inventory_items.append(i)
                            s_check_boxes = []
                            s_options = []
                            if container:
                                for obj in container:
                                    obj_text = color_text(obj.name.capitalize(), obj.color)
                                    ob_value = color_text(obj.item.value, libtcod.gold)
                                    ob_value = '(%s)' % ob_value
                                    s_gold.append(ob_value)
                                    opt = '[%s] ' % obj_text
                                    s_options.append(opt)
                                    if len(obj.name)+2 > s_size:
                                        s_size = len(obj.name)+2
                            for x in range(len(container)):
                                s_check_boxes.append(CheckBox(x=1, y=x+1))

        # keyboard input
        index = key.c - ord('a')
        if key:
            if key.vk == libtcod.KEY_DOWN:
                if current_selection is None:
                    current_selection = 0
                current_selection += 1
                if current_selection > len(inventory_items):
                    current_selection = 0
            if key.vk == libtcod.KEY_UP:
                if current_selection is None:
                    current_selection = 0
                current_selection -= 1
                if current_selection < 0:
                    current_selection = len(inventory_items)
        # ========================================================================
        # handle buttons
        # ========================================================================

        # ========================================================================
        # Sell Button
        # ========================================================================
        for i in sell_input:
            if i != -1:
                message = 'Sell all selected items?'
                w = len(message)+2
                d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='option', con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    d_box.destroy_box()
                    i_master_check.set_checked(False)
                    items_to_sell = []
                    for box in i_check_boxes:
                        if box.get_checked():
                            items_to_sell.append(player.fighter.inventory[box.y-1])
                    for item_to_sell in items_to_sell:
                        if item_to_sell:
                            player.fighter.money += item_to_sell.item.value/2
                            player.fighter.inventory.remove(item_to_sell)
                    i_check_boxes = []
                    inventory_items = []
                    for x in range(len(player.fighter.inventory)):
                        i_check_boxes.append(CheckBox(x=1, y=x+1))
                        inventory_items.append(color_text(player.fighter.inventory[x].name.capitalize(),
                                                          player.fighter.inventory[x].color))
                else:
                    d_box.destroy_box()

        # ========================================================================
        # buy button
        # ========================================================================
        for i in buy_input:
            if i != -1:
                n = 0
                for box in s_check_boxes:
                    if box.get_checked():
                        n += 1
                if len(player.fighter.inventory)+n > 26:
                        message = 'Not enough inventory space!'
                        w = len(message)+2
                        d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='dialog', con=inventory_window)
                        d_box.display_box()
                elif buy_value > player.fighter.money:
                    message = 'Not enough money!'
                    w = len(message)+2
                    d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='dialog', con=inventory_window)
                    d_box.display_box()
                    s_master_check.set_checked(False)
                    for box in s_check_boxes:
                        box.set_checked(s_master_check.get_checked())
                else:
                    message = 'Buy all selected items?'
                    w = len(message)+2
                    d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='option', con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:
                        #d_box.destroy_box()
                        s_master_check.set_checked(False)
                        items_to_buy = []
                        for box in s_check_boxes:
                            if box.get_checked():
                                items_to_buy.append(container[box.y-1])
                        for item_to_buy in items_to_buy:
                            if item_to_buy:
                                container.remove(item_to_buy)
                                player.fighter.money -= item_to_buy.item.value
                                #player.fighter.inventory.append(item_to_buy)
                                item_to_buy.item.pick_up(player.fighter.inventory)

                        s_check_boxes = []
                        s_options = []
                        if container:
                            for obj in container:
                                obj_text = color_text(obj.name.capitalize(), obj.color)
                                ob_value = color_text(obj.item.value, libtcod.gold)
                                ob_value = '(%s)' % ob_value
                                s_gold.append(ob_value)
                                opt = '[%s] ' % obj_text
                                s_options.append(opt)
                                if len(obj.name)+2 > s_size:
                                    s_size = len(obj.name)+2
                        for x in range(len(container)):
                            s_check_boxes.append(CheckBox(x=1, y=x+1))

                        i_check_boxes = []
                        inventory_items = []
                        for x in range(len(player.fighter.inventory)):
                            i_check_boxes.append(CheckBox(x=1, y=x+1))
                            i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
                            if player.fighter.inventory[x].item.check_stackable:
                                i += ' (%d)' % player.fighter.inventory[x].item.qty
                            inventory_items.append(i)
            #else:
                    d_box.destroy_box()

        # ========================================================================
        # handle exit button
        # ========================================================================

        for i in exit_input:
            if i != -1:
                key.vk = libtcod.KEY_ESCAPE
                break
    # Remember to remove consoles in reverse order of creation to avoid OOB errors
    if splash:
        game.gEngine.console_remove_console(splash_screen)
    buy_button.destroy_button()
    sell_button.destroy_button()
    exit_button.destroy_button()
    game.gEngine.console_remove_console(compare_window)
    game.gEngine.console_remove_console(shop_window)
    game.gEngine.console_remove_console(inventory_window)

    return
コード例 #53
0
ファイル: inventory.py プロジェクト: GrishdaFish/Ascension
def inventory(con, player, game, width=80, height=43):
    """
    TODO:
        Add in highlighting for Weapons and Equipment consoles
        Add in keyboard arrow selection support
        Add in "drop" mode, drop items from inventory
        Fix Weapons and Equipment keyboard handling
        Fix duplication bug when equipping items (fixed)
        Fix take off weapon confirmation when equipping an item (fixed)
        2 handed code needs work (?)
        keyboard input is sluggish. Might have to update libtcod to fix

    :param con: Destination console (not used atm)
    :param player: The main player object
    :param game: The main game object
    :param width: width of the inventory screen
    :param height: height of the inventory screen
    :return: An item that has been used (potion, scroll, etc..)
    """
    equip_height = 14
    wield_height = 8
    compare_height = height - (equip_height - wield_height) - (wield_height *
                                                               2)

    r, g, b = libtcod.white
    equip_y = wield_height
    compare_y = equip_height + wield_height

    inventory_window = game.gEngine.console_new(width / 2, height)
    game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
    game.gEngine.console_print_frame(inventory_window, 0, 0, width / 2, height,
                                     True)
    game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)

    equipment_window = game.gEngine.console_new(width / 2, equip_height)
    game.gEngine.console_set_default_foreground(equipment_window, r, g, b)
    game.gEngine.console_print_frame(equipment_window, 0, 0, width / 2,
                                     equip_height, True)
    game.gEngine.console_set_default_background(equipment_window, 0, 0, 0)

    wielded_window = game.gEngine.console_new(width / 2, wield_height)
    game.gEngine.console_set_default_foreground(wielded_window, r, g, b)
    game.gEngine.console_print_frame(wielded_window, 0, 0, width / 2,
                                     wield_height, True)
    game.gEngine.console_set_default_background(wielded_window, 0, 0, 0)

    compare_window = game.gEngine.console_new(width / 2, compare_height)
    game.gEngine.console_set_default_foreground(compare_window, r, g, b)
    game.gEngine.console_print_frame(compare_window, 0, 0, width / 2,
                                     compare_height, True)
    game.gEngine.console_set_default_background(compare_window, 0, 0, 0)

    check_boxes = []
    slots = [
        'Torso    ', 'Head     ', 'Hands    ', 'Legs     ', 'Feet     ',
        'Arms     ', 'Shoulders', 'Back     '
    ]
    #self.buttons.append(Button(self, self.option_labels[0], self.width//6-5, self.height/2-1, True))
    exit_button = Button(label='Exit',
                         game=game,
                         x_pos=(width / 2) - 9,
                         y_pos=height - 6,
                         window=inventory_window,
                         dest_x=width / 2,
                         dest_y=0)
    drop_button = Button(label='Drop',
                         game=game,
                         x_pos=1,
                         y_pos=height - 6,
                         window=inventory_window,
                         dest_x=width / 2,
                         dest_y=0)
    if len(player.fighter.inventory) == 0:
        inventory_items = ['Inventory is empty.']
    else:
        inventory_items = []
        for x in range(len(player.fighter.inventory)):
            check_boxes.append(CheckBox(x=1, y=x + 3))
            i = color_text(player.fighter.inventory[x].name.capitalize(),
                           player.fighter.inventory[x].color)
            if player.fighter.inventory[x].item.check_stackable:
                i += ' (%d)' % player.fighter.inventory[x].item.qty
            inventory_items.append(i)
    i_header = 'Inventory'
    i_header_size = len(i_header)
    i_header_pos = (width / 4) - (i_header_size / 2)

    w_header = 'Weapons'
    w_header_size = len(w_header)
    w_header_pos = (width / 8) - (w_header_size / 2)

    e_header = 'Equipment'
    e_header_size = len(e_header)
    e_header_pos = (width / 8) - (e_header_size / 2)

    c_header = 'Compare/Examine'
    c_header_size = len(c_header)
    c_header_pos = (width / 8) - (c_header_size / 2)

    return_item = None
    key = libtcod.console_check_for_keypress()
    current_selection = 0
    master_check = CheckBox(1, 30, "Check/Uncheck All")
    while key.vk != libtcod.KEY_ESCAPE:
        game.gEngine.console_flush()
        # get input just after flush
        key = libtcod.console_check_for_keypress(True)
        mouse = libtcod.mouse_get_status()
        exit_input = exit_button.display(mouse)
        drop_input = drop_button.display(mouse)

        game.gEngine.console_blit(inventory_window, 0, 0, width / 2, height, 0,
                                  (width / 2), 0, 1.0, 1.0)
        game.gEngine.console_blit(wielded_window, 0, 0, width / 2, height, 0,
                                  0, 0, 1.0, 1.0)
        game.gEngine.console_blit(equipment_window, 0, 0, width / 2, height, 0,
                                  0, equip_y, 1.0, 1.0)
        game.gEngine.console_blit(compare_window, 0, 0, width / 2, height, 0,
                                  0, compare_y, 1.0, 1.0)

        game.gEngine.console_clear(inventory_window)
        game.gEngine.console_clear(wielded_window)
        game.gEngine.console_clear(equipment_window)
        game.gEngine.console_clear(compare_window)

        # set up draw screen
        r, g, b = libtcod.white
        game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
        game.gEngine.console_print_frame(inventory_window, 0, 0, width / 2,
                                         height, True)

        game.gEngine.console_set_default_foreground(equipment_window, r, g, b)
        game.gEngine.console_print_frame(equipment_window, 0, 0, width / 2,
                                         equip_height, True)

        game.gEngine.console_set_default_foreground(wielded_window, r, g, b)
        game.gEngine.console_print_frame(wielded_window, 0, 0, width / 2,
                                         wield_height, True)

        game.gEngine.console_set_default_foreground(compare_window, r, g, b)
        game.gEngine.console_print_frame(compare_window, 0, 0, width / 2,
                                         compare_height, True)

        # ========================================================================
        # print inventory
        # ========================================================================
        game.gEngine.console_print(inventory_window, i_header_pos, 0, i_header)
        letter_index = ord('a')
        if len(player.fighter.inventory) > 0:
            y = 1
            for i in range(len(inventory_items)):
                text = '  (' + chr(letter_index) + ') ' + inventory_items[i]
                if current_selection == y - 1:
                    r, g, b = libtcod.color_lerp(
                        player.fighter.inventory[i].color, libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(
                        inventory_window, r, g, b)
                else:
                    game.gEngine.console_set_default_background(
                        inventory_window, 0, 0, 0)
                game.gEngine.console_print_ex(inventory_window, 1, y + 2,
                                              libtcod.BKGND_SET, libtcod.LEFT,
                                              text)
                y += 1
                letter_index += 1
        game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        game.gEngine.console_print(
            inventory_window, 1, 31,
            'Gold: ' + color_text(str(player.fighter.money), libtcod.gold))

        # ========================================================================
        # print equipped weapons
        # ========================================================================
        game.gEngine.console_print(wielded_window, w_header_pos, 0, w_header)
        index = ord('1')
        if player.fighter.wielded[0] is None:
            text = '(' + chr(index) + ') ' + 'Left Hand : ' + color_text(
                'Empty', libtcod.darker_gray)
        else:
            t = color_text(player.fighter.wielded[0].name.capitalize(),
                           player.fighter.wielded[0].color)
            text = '(' + chr(index) + ') ' + 'Left Hand : ' + t
        index += 1
        game.gEngine.console_print(wielded_window, 1, 2, text)
        if player.fighter.wielded[1] is None:
            text = '(' + chr(index) + ') ' + 'Right Hand: ' + color_text(
                'Empty', libtcod.darker_gray)
        else:
            t = color_text(player.fighter.wielded[1].name.capitalize(),
                           player.fighter.wielded[1].color)
            text = '(' + chr(index) + ') ' + 'Right Hand: ' + t
        index += 1
        game.gEngine.console_print(wielded_window, 1, 3, text)

        item = player.fighter.wielded[0]
        if item:
            damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices,
                                   item.item.equipment.damage.nb_faces,
                                   item.item.equipment.damage.addsub)
            text = 'Damage   (total): ' + color_text(damage, libtcod.green)
            game.gEngine.console_print(wielded_window, 1, 4, text)
            accuracy = item.item.equipment.accuracy
            accuracy += game.player.fighter.get_skill(
                item.item.equipment.damage_type).get_bonus()
            text = 'Accuracy (total): ' + color_text(str(accuracy),
                                                     libtcod.green)
            game.gEngine.console_print(wielded_window, 1, 5, text)

        # ========================================================================
        # print equipped armor
        # ========================================================================
        game.gEngine.console_print(equipment_window, e_header_pos, 0, e_header)
        i = 0
        game.gEngine.console_set_alignment(equipment_window, libtcod.LEFT)
        armor_bonus = 0
        armor_penalty = 0
        for item in player.fighter.equipment:
            text = '(' + chr(index) + ') ' + slots[i] + ': '
            if item is None:
                text += color_text('Empty', libtcod.darker_gray)
            else:
                text += color_text(item.name.capitalize(), item.color)
                armor_bonus += item.item.equipment.bonus
                armor_penalty += item.item.equipment.penalty
            game.gEngine.console_print(equipment_window, 1, i + 2, text)
            i += 1
            index += 1
        c = color_text(str(armor_bonus), libtcod.green)
        text = 'Total Armor Bonus  :  ' + c
        game.gEngine.console_print(equipment_window, 1, i + 2, text)
        c = color_text(str(armor_penalty), libtcod.red)
        text = 'Total Armor Penalty: -' + c
        game.gEngine.console_print(equipment_window, 1, i + 3, text)
        game.gEngine.console_print(compare_window, c_header_pos, 0, c_header)

        # ========================================================================
        # handle mouse input
        # ========================================================================
        mc = master_check.update(mouse, width)
        master_check.render(inventory_window, game)
        if not mc:
            for box in check_boxes:
                box.update(mouse, width)
                box.render(inventory_window, game)
        else:
            for box in check_boxes:
                box.set_checked(master_check.get_checked())
                box.render(inventory_window, game)

        # Inventory input
        if mouse.cx >= width / 2 + 3 and mouse.cx < width - 2:  # inventory screen dims
            if (mouse.cy - 3) < len(
                    player.fighter.inventory) and mouse.cy - 3 >= 0:
                #if mouse.cy-3 <= len(player.fighter.inventory):
                item = player.fighter.inventory[mouse.cy - 3]
                current_selection = mouse.cy - 3
                if item.item.equipment:
                    game.gEngine.console_print(
                        compare_window, 1, 2, 'Name    : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print(
                        compare_window, 1, 3,
                        'Type    : ' + item.item.equipment.type.capitalize())
                    if item.item.equipment.type == 'melee':
                        damage = '%dd%d+%d' % (
                            item.item.equipment.damage.nb_dices,
                            item.item.equipment.damage.nb_faces,
                            item.item.equipment.damage.addsub)
                        game.gEngine.console_print(compare_window, 1, 4,
                                                   'Damage  : ' + damage)
                        game.gEngine.console_print(
                            compare_window, 1, 5,
                            'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print(
                            compare_window, 1, 7,
                            'Skill   : ' + item.item.equipment.damage_type)
                    else:
                        game.gEngine.console_print(
                            compare_window, 1, 4,
                            'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print(
                            compare_window, 1, 5,
                            'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print(
                            compare_window, 1, 7, 'Location: ' +
                            item.item.equipment.location.capitalize())
                    game.gEngine.console_print(
                        compare_window, 1, 6,
                        'Value   : ' + str(item.item.value))
                if item.item.spell:
                    game.gEngine.console_print(
                        compare_window, 1, 2, 'Name  : ' +
                        color_text(item.name.capitalize(), item.color))
                    game.gEngine.console_print(
                        compare_window, 1, 3,
                        'Type  : ' + item.item.spell.type.capitalize())
                    game.gEngine.console_print(
                        compare_window, 1, 4,
                        'Power : ' + str(item.item.spell.min) + '-' +
                        str(item.item.spell.max))
                    game.gEngine.console_print(
                        compare_window, 1, 5,
                        'Range : ' + str(item.item.spell.range))
                    game.gEngine.console_print(
                        compare_window, 1, 6,
                        'Radius: ' + str(item.item.spell.radius))
                    game.gEngine.console_print(
                        compare_window, 1, 7,
                        'Value : ' + str(item.item.value))
                if mouse.lbutton_pressed and item.item.spell:
                    i_n = color_text(item.name.capitalize(), item.color)
                    message = 'Do you want to use %s?' % i_n
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 4,
                                      height / 2,
                                      message,
                                      type='option',
                                      con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:  # make sure if the player uses a scroll or potion, we exit inventory
                        d_box.destroy_box()
                        # Remember to remove consoles in reverse order of creation to avoid OOB errors
                        return_item = item
                        break
                    else:
                        d_box.destroy_box()
                if mouse.lbutton_pressed and item.item.equipment:
                    i_n = color_text(item.name.capitalize(), item.color)
                    message = 'Do you want to put %s on?' % i_n
                    w = len(message) + 2
                    d_box = DialogBox(game,
                                      w,
                                      10,
                                      width / 4,
                                      height / 2,
                                      message,
                                      type='option',
                                      con=inventory_window)
                    confirm = d_box.display_box()
                    if confirm == 1:
                        item.item.use(game.player.fighter.inventory,
                                      game.player, game)
                        d_box.destroy_box()
                        inventory_items = []
                        check_boxes = []
                        for x in range(len(player.fighter.inventory)):
                            check_boxes.append(CheckBox(x=1, y=x + 3))
                            i = color_text(
                                player.fighter.inventory[x].name.capitalize(),
                                player.fighter.inventory[x].color)
                            if player.fighter.inventory[
                                    x].item.check_stackable:
                                i += ' (%d)' % player.fighter.inventory[
                                    x].item.qty
                            inventory_items.append(i)
            else:
                current_selection = None
        # game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        # Wielded
        elif mouse.cx >= 0 and mouse.cx <= (
            (width / 2) - 2):  # inventory screen dims
            if (mouse.cy - 2) < len(player.fighter.wielded):
                item = player.fighter.wielded[mouse.cy - 2]
                if item is not None:
                    if item.item.equipment:
                        game.gEngine.console_print(
                            compare_window, 1, 2, 'Name    : ' +
                            color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(
                            compare_window, 1, 3, 'Type    : ' +
                            item.item.equipment.type.capitalize())
                        damage = '%dd%d+%d' % (
                            item.item.equipment.damage.nb_dices,
                            item.item.equipment.damage.nb_faces,
                            item.item.equipment.damage.addsub)
                        game.gEngine.console_print(compare_window, 1, 4,
                                                   'Damage  : ' + damage)
                        game.gEngine.console_print(
                            compare_window, 1, 5,
                            'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print(
                            compare_window, 1, 6,
                            'Value   : ' + str(item.item.value))

        # Equipment
            elif (mouse.cy - 2) - equip_y < len(player.fighter.equipment):
                item = player.fighter.equipment[mouse.cy - 2 - equip_y]
                if item is not None:
                    if item.item.equipment:
                        game.gEngine.console_print(
                            compare_window, 1, 2, 'Name    : ' +
                            color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(
                            compare_window, 1, 3, 'Type    : ' +
                            item.item.equipment.type.capitalize())
                        game.gEngine.console_print(
                            compare_window, 1, 4,
                            'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print(
                            compare_window, 1, 5,
                            'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print(
                            compare_window, 1, 6,
                            'Value   : ' + str(item.item.value))
            if mouse.lbutton_pressed and item is not None:
                i_n = color_text(item.name.capitalize(), item.color)
                message = 'Do you want to take %s off?' % i_n
                w = len(message) + 2
                d_box = DialogBox(game,
                                  w,
                                  10,
                                  width / 4,
                                  height / 2,
                                  message,
                                  type='option',
                                  con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    item.item.equipment.un_equip(game.player, item)
                    d_box.destroy_box()
                    inventory_items = []
                    check_boxes = []
                    for x in range(len(player.fighter.inventory)):
                        check_boxes.append(CheckBox(x=1, y=x + 3))
                        i = color_text(
                            player.fighter.inventory[x].name.capitalize(),
                            player.fighter.inventory[x].color)
                        if player.fighter.inventory[x].item.check_stackable:
                            i += ' (%d)' % player.fighter.inventory[x].item.qty
                        inventory_items.append(i)
                    i = 0
                    for x in player.fighter.wielded:
                        if x == item:
                            player.fighter.wielded[i] = None
                        i += 1
                    i = 0
                    for x in player.fighter.equipment:
                        if x == item:
                            player.fighter.equipment[i] = None
                        i += 1

        # keyboard input
        # keeps similar feel to old inventory if using the keys
        # keyboard input is sluggish as balls for some reason, need to look into it more
        index = key.c - ord('a')
        if key:
            if index >= 0 and index < len(inventory_items):
                return_item = player.fighter.inventory[index]
                break
            index = key.c - ord('1')
            if index >= 0 and index <= 1:
                return_item = player.fighter.wielded[index]
                break
            elif index >= 2 and index <= 10:
                return_item = player.fighter.equipment[index - 2]
                break
            if key.vk == libtcod.KEY_DOWN:
                if current_selection is None:
                    current_selection = 0
                current_selection += 1
                if current_selection > len(inventory_items):
                    current_selection = 0
            if key.vk == libtcod.KEY_UP:
                if current_selection is None:
                    current_selection = 0
                current_selection -= 1
                if current_selection < 0:
                    current_selection = len(inventory_items)
        # ========================================================================
        # handle buttons
        # ========================================================================
        for i in drop_input:
            if i != -1:
                message = 'Drop all selected items?'
                w = len(message) + 2
                d_box = DialogBox(game,
                                  w,
                                  10,
                                  width / 2 - w / 2,
                                  height / 2 - 5,
                                  message,
                                  type='option',
                                  con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    d_box.destroy_box()
                    master_check.set_checked(False)
                    items_to_drop = []
                    for box in check_boxes:
                        if box.get_checked():
                            items_to_drop.append(
                                player.fighter.inventory[box.y - 3])
                    for item_to_drop in items_to_drop:
                        if item_to_drop:
                            item_to_drop.objects = game.objects
                            item_to_drop.item.drop(player.fighter.inventory,
                                                   player, False)
                            item_to_drop.send_to_back()
                    check_boxes = []
                    inventory_items = []
                    for x in range(len(player.fighter.inventory)):
                        check_boxes.append(CheckBox(x=1, y=x + 3))
                        inventory_items.append(
                            color_text(
                                player.fighter.inventory[x].name.capitalize(),
                                player.fighter.inventory[x].color))
                else:
                    d_box.destroy_box()
        # ========================================================================
        # handle exit button
        # ========================================================================

        for i in exit_input:
            if i != -1:
                key.vk = libtcod.KEY_ESCAPE
                break
    # Remember to remove consoles in reverse order of creation to avoid OOB errors
    drop_button.destroy_button()
    exit_button.destroy_button()
    game.gEngine.console_remove_console(compare_window)
    game.gEngine.console_remove_console(wielded_window)
    game.gEngine.console_remove_console(equipment_window)
    game.gEngine.console_remove_console(inventory_window)

    return return_item
コード例 #54
0
ファイル: character.py プロジェクト: GrishdaFish/Ascension
def character_info(con, width, height, game, x=0, y=0):
    skill_window = game.gEngine.console_new(width / 2, height)
    skill_window_y_pos = width / 2
    s_header, s_pos = get_centered_text("Skills", width / 4)

    char_window = game.gEngine.console_new(width / 2, height / 2)
    c_header, c_pos = get_centered_text(
        ("%s's Skills and Abilities" % game.player.name), width / 4)

    skill_desc_window = game.gEngine.console_new(width / 2, height / 2)
    skill_desc_pos = height / 2
    d_header, d_pos = get_centered_text("Description", width / 4)

    exit_button = Button(label='Exit',
                         game=game,
                         x_pos=(width / 2) - 9,
                         y_pos=height - 6,
                         window=skill_window,
                         dest_x=width / 2,
                         dest_y=0)
    current_selection = 0
    key = libtcod.console_check_for_keypress()
    while key.vk != libtcod.KEY_ESCAPE:
        game.gEngine.console_flush()
        # get input just after flush
        key = libtcod.console_check_for_keypress(True)
        mouse = libtcod.mouse_get_status()
        exit_input = exit_button.display(mouse)

        game.gEngine.console_blit(char_window, 0, 0, width / 2, height / 2, 0,
                                  0, 0, 1.0, 1.0)
        game.gEngine.console_blit(skill_window, 0, 0, width / 2, height, 0,
                                  skill_window_y_pos, 0, 1.0, 1.0)
        game.gEngine.console_blit(skill_desc_window, 0, 0, width / 2,
                                  height / 2, 0, 0, skill_desc_pos, 1.0, 1.0)

        game.gEngine.console_clear(char_window)
        game.gEngine.console_clear(skill_desc_window)
        game.gEngine.console_clear(skill_window)

        #Draw Character info
        r, g, b = libtcod.white
        game.gEngine.console_set_default_foreground(char_window, r, g, b)
        game.gEngine.console_print_frame(char_window, 0, 0, width / 2,
                                         height / 2, True)
        game.gEngine.console_print(char_window, c_pos, 0, c_header)
        game.gEngine.console_print(char_window, 1, 1,
                                   'Name: %s' % game.player.name)
        game.gEngine.console_print(
            char_window, 1, 2, 'Hit Points: %d/%d' %
            (game.player.fighter.hp, game.player.fighter.max_hp))

        game.gEngine.console_print(char_window, 1, 4,
                                   'Level: %d' % game.player.fighter.level)
        game.gEngine.console_print(
            char_window, 1, 5,
            'To Next Level: %d' % game.player.fighter.xp_to_next_level)

        s = color_text(str(game.player.fighter.stats[0]), libtcod.light_gray)
        d = color_text(str(game.player.fighter.stats[1]), libtcod.light_gray)
        i = color_text(str(game.player.fighter.stats[2]), libtcod.light_gray)
        c = color_text(str(game.player.fighter.stats[3]), libtcod.light_gray)
        game.gEngine.console_print(char_window, 1, 7,
                                   'Stats: Str [%s], Dex [%s]' % (s, d))
        game.gEngine.console_print(char_window, 1, 8,
                                   '       Int [%s], Con [%s]' % (i, c))

        bonus = color_text(str(game.player.fighter.armor_bonus), libtcod.green)
        bonus2 = color_text('10 +%d' % game.player.fighter.armor_bonus,
                            libtcod.green)
        game.gEngine.console_print(
            char_window, 1, 10,
            'Bonus to Armor Roll  : [%s](%s) ' % (bonus, bonus2))

        penalty = color_text(str(game.player.fighter.armor_penalty),
                             libtcod.red)
        penalty2 = color_text('1d20 -%d' % game.player.fighter.armor_penalty,
                              libtcod.red)
        game.gEngine.console_print(
            char_window, 1, 11,
            'Penalty to Dodge Roll: [%s](%s)' % (penalty, penalty2))

        speed = color_text(str(game.player.fighter.speed), libtcod.light_gray)
        game.gEngine.console_print(char_window, 1, 13,
                                   'Turn Speed: [%s]' % speed)

        r, g, b = libtcod.white
        game.gEngine.console_set_default_foreground(skill_window, r, g, b)
        game.gEngine.console_print_frame(skill_window, 0, 0, width / 2, height,
                                         True)
        game.gEngine.console_print(skill_window, s_pos, 0, s_header)
        t, p = get_centered_text(
            'Unspent Skill Points: [%d]' %
            game.player.fighter.unused_skill_points, width / 4)
        game.gEngine.console_print(skill_window, p, 1, t)

        y = 2
        letter_index = ord('a')
        skill_max = 5
        for skill in game.player.fighter.skills:
            s_name = skill.get_name()
            s_bonus = skill.get_bonus()
            s_index = chr(letter_index)
            col = libtcod.white
            if s_bonus == skill_max:
                s_name = color_text(s_name, libtcod.green)
                s_bonus = color_text(str(s_bonus), libtcod.green)
                s_index = color_text(s_index, libtcod.green)
                col = libtcod.green
            elif s_bonus < skill_max and s_bonus > 0:
                s_name = color_text(s_name, libtcod.light_gray)
                s_bonus = color_text(str(s_bonus), libtcod.lighter_gray)
                s_index = color_text(s_index, libtcod.lighter_gray)
                col = libtcod.lighter_gray
            elif s_bonus == 0:
                s_name = color_text(s_name, libtcod.dark_gray)
                s_bonus = color_text(str(s_bonus), libtcod.dark_gray)
                s_index = color_text(s_index, libtcod.dark_gray)
                col = libtcod.dark_gray
            else:
                s_name = color_text(s_name, libtcod.red)
                s_bonus = color_text(str(s_bonus), libtcod.red)
                s_index = color_text(s_index, libtcod.red)
                col = libtcod.red
            text = '(%s) %s: [%s]' % (s_index, s_name, s_bonus)
            game.gEngine.console_print(skill_window, 1, y, text)
            if current_selection == y - 2:
                r, g, b = libtcod.color_lerp(col, libtcod.blue, 0.5)
                game.gEngine.console_set_default_background(
                    skill_window, r, g, b)
            else:
                game.gEngine.console_set_default_background(
                    skill_window, 0, 0, 0)

            game.gEngine.console_print_ex(skill_window, 1, y,
                                          libtcod.BKGND_SET, libtcod.LEFT,
                                          text)
            y += 1
            letter_index += 1
        game.gEngine.console_set_default_background(skill_window, 0, 0, 0)

        r, g, b = libtcod.white
        game.gEngine.console_set_default_foreground(skill_desc_window, r, g, b)
        game.gEngine.console_print_frame(skill_desc_window, 0, 0, width / 2,
                                         height / 2, True)
        game.gEngine.console_print(skill_desc_window, d_pos, 0, d_header)

        #mouse input
        if mouse.cx >= width / 2 + 3:
            if mouse.cy - 2 < len(
                    game.player.fighter.skills) and mouse.cy >= 0:
                current_selection = mouse.cy - 2
                skill = game.player.fighter.skills[current_selection]
                desc = color_text(skill.get_description(), libtcod.light_gray)
                desc = "Skill Description: %s" % desc
                cat = color_text(skill.get_category(), libtcod.light_gray)
                cat = "Skill Category   : %s" % cat
                bonus = skill.get_bonus()
                name = skill.get_name()
                if bonus == skill_max:
                    bonus = color_text(str(bonus), libtcod.green)
                    name = color_text(name, libtcod.green)
                elif bonus < skill_max and bonus > 0:
                    bonus = color_text(str(bonus), libtcod.lighter_gray)
                    name = color_text(name, libtcod.lighter_gray)
                elif bonus == 0:
                    bonus = color_text(str(bonus), libtcod.dark_gray)
                    name = color_text(name, libtcod.dark_gray)
                else:
                    bonus = color_text(str(bonus), libtcod.red)
                    name = color_text(name, libtcod.red)
                if skill.get_category() == 'Discipline':
                    bonus = 'Increases your (%s) to-hit rolls by [%s].' % (
                        name, bonus)
                elif skill.get_category() == 'Weapon':
                    bonus = 'Increases your (%s) damage by [%s].' % (name,
                                                                     bonus)

                game.gEngine.console_print_rect(skill_desc_window, 1, 1,
                                                width / 2 - 2, 3, desc)
                game.gEngine.console_print(skill_desc_window, 1, 5, cat)
                game.gEngine.console_print_rect(skill_desc_window, 1, 7,
                                                width / 2 - 2, 3, bonus)
                if mouse.lbutton_pressed:
                    game.player.fighter.apply_skill_points(
                        game.player.fighter.skills[current_selection]
                    )  # use unused player skill points

        for i in exit_input:
            if i != -1:
                key.vk = libtcod.KEY_ESCAPE
                break

    exit_button.destroy_button()
    game.gEngine.console_remove_console(skill_desc_window)
    game.gEngine.console_remove_console(char_window)
    game.gEngine.console_remove_console(skill_window)

    return None
コード例 #55
0
ファイル: title.py プロジェクト: bricks42/BrutalRL
		MAP[x, y] = 0

if __name__ == '__main__':
	
	init_blood()
	
	libtcod.console_set_custom_font('courier12x12_aa_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	libtcod.console_init_root(WIDTH, HEIGHT, 'title screen sim', False)
	libtcod.sys_set_fps(60)
	libtcod.console_set_background_color(0, libtcod.black)
	
	while True:

		update()

		draw_blood()

		draw_title()

		libtcod.console_flush()

		key = libtcod.console_check_for_keypress()

		if key.vk == libtcod.KEY_ESCAPE:
			break

		mouse = libtcod.mouse_get_status()
		if mouse.lbutton:
			set_full(mouse.cx, mouse.cy)
		elif mouse.rbutton:
			set_empty(mouse.cx, mouse.cy)
コード例 #56
0
ファイル: test.py プロジェクト: aash29/pyLogistics
        y = j / GLOBALMAP_HEIGHT
        if pnpoly.pnpoly2(x, y, vx, vy):
            traversalMap[i, j] = 1

end = time.time()
print(end - start)

while not libtcod.console_is_window_closed():

    # render the screen
    libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE,
                                key, mouse)

    #libtcod.image_blit(pix, con, player.x, player.y, libtcod.BKGND_SET, 0.5, 0.5, 0)

    mouseStatus = libtcod.mouse_get_status()

    currentCell['x'] = player.x - MAP_WIDTH2 + mouseStatus.cx
    currentCell['y'] = player.y - MAP_HEIGHT2 + mouseStatus.cy

    render_all()

    for i in range(max(player.x - MAP_WIDTH2, 0),
                   min(player.x + MAP_WIDTH2, GLOBALMAP_WIDTH)):
        for j in range(max(player.y - MAP_HEIGHT2, 0),
                       min(player.y + MAP_HEIGHT2, GLOBALMAP_HEIGHT)):
            if traversalMap[i, j] == 1:
                libtcod.console_set_char_background(con,
                                                    i - player.x + MAP_WIDTH2,
                                                    j - player.y + MAP_HEIGHT2,
                                                    libtcod.white)
コード例 #57
0
ファイル: inventory.py プロジェクト: GrishdaFish/Ascension
def inventory(con, player, game, width=80, height=43):
    """
    TODO:
        Add in highlighting for Weapons and Equipment consoles
        Add in keyboard arrow selection support
        Add in "drop" mode, drop items from inventory
        Fix Weapons and Equipment keyboard handling
        Fix duplication bug when equipping items (fixed)
        Fix take off weapon confirmation when equipping an item (fixed)
        2 handed code needs work (?)
        keyboard input is sluggish. Might have to update libtcod to fix

    :param con: Destination console (not used atm)
    :param player: The main player object
    :param game: The main game object
    :param width: width of the inventory screen
    :param height: height of the inventory screen
    :return: An item that has been used (potion, scroll, etc..)
    """
    equip_height = 14
    wield_height = 8
    compare_height = height - (equip_height - wield_height)-(wield_height*2)

    r, g, b = libtcod.white
    equip_y = wield_height
    compare_y = equip_height + wield_height

    inventory_window = game.gEngine.console_new(width/2, height)
    game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
    game.gEngine.console_print_frame(inventory_window, 0, 0, width/2, height, True)
    game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)

    equipment_window = game.gEngine.console_new(width/2, equip_height)
    game.gEngine.console_set_default_foreground(equipment_window, r, g, b)
    game.gEngine.console_print_frame(equipment_window, 0, 0, width/2, equip_height, True)
    game.gEngine.console_set_default_background(equipment_window, 0, 0, 0)

    wielded_window = game.gEngine.console_new(width/2, wield_height)
    game.gEngine.console_set_default_foreground(wielded_window, r, g, b)
    game.gEngine.console_print_frame(wielded_window, 0, 0, width/2, wield_height, True)
    game.gEngine.console_set_default_background(wielded_window, 0, 0, 0)

    compare_window = game.gEngine.console_new(width/2, compare_height)
    game.gEngine.console_set_default_foreground(compare_window, r, g, b)
    game.gEngine.console_print_frame(compare_window, 0, 0, width/2, compare_height, True)
    game.gEngine.console_set_default_background(compare_window, 0, 0, 0)

    check_boxes = []
    slots = ['Torso    ',
             'Head     ',
             'Hands    ',
             'Legs     ',
             'Feet     ',
             'Arms     ',
             'Shoulders',
             'Back     ']
    #self.buttons.append(Button(self, self.option_labels[0], self.width//6-5, self.height/2-1, True))
    exit_button = Button(label='Exit', game=game, x_pos=(width/2)-9, y_pos=height-6,
                         window=inventory_window, dest_x=width/2, dest_y=0)
    drop_button = Button(label='Drop', game=game, x_pos=1, y_pos=height-6,
                         window=inventory_window, dest_x=width/2, dest_y=0)
    if len(player.fighter.inventory) == 0:
        inventory_items = ['Inventory is empty.']
    else:
        inventory_items = []
        for x in range(len(player.fighter.inventory)):
            check_boxes.append(CheckBox(x=1, y=x+3))
            i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
            if player.fighter.inventory[x].item.check_stackable:
                i += ' (%d)' % player.fighter.inventory[x].item.qty
            inventory_items.append(i)
    i_header = 'Inventory'
    i_header_size = len(i_header)
    i_header_pos = (width/4)-(i_header_size/2)

    w_header = 'Weapons'
    w_header_size = len(w_header)
    w_header_pos = (width/8) - (w_header_size/2)

    e_header = 'Equipment'
    e_header_size = len(e_header)
    e_header_pos = (width/8) - (e_header_size/2)

    c_header = 'Compare/Examine'
    c_header_size = len(c_header)
    c_header_pos = (width/8) - (c_header_size/2)

    return_item = None
    key = libtcod.console_check_for_keypress()
    current_selection = 0
    master_check = CheckBox(1, 30, "Check/Uncheck All")
    while key.vk != libtcod.KEY_ESCAPE:
        game.gEngine.console_flush()
        # get input just after flush
        key = libtcod.console_check_for_keypress(True)
        mouse = libtcod.mouse_get_status()
        exit_input = exit_button.display(mouse)
        drop_input = drop_button.display(mouse)

        game.gEngine.console_blit(inventory_window, 0, 0, width/2, height, 0, (width/2), 0, 1.0, 1.0)
        game.gEngine.console_blit(wielded_window, 0, 0, width/2, height, 0, 0, 0, 1.0, 1.0)
        game.gEngine.console_blit(equipment_window, 0, 0, width/2, height, 0, 0, equip_y, 1.0, 1.0)
        game.gEngine.console_blit(compare_window, 0, 0, width/2, height, 0, 0, compare_y, 1.0, 1.0)

        game.gEngine.console_clear(inventory_window)
        game.gEngine.console_clear(wielded_window)
        game.gEngine.console_clear(equipment_window)
        game.gEngine.console_clear(compare_window)

        # set up draw screen
        r, g, b = libtcod.white
        game.gEngine.console_set_default_foreground(inventory_window, r, g, b)
        game.gEngine.console_print_frame(inventory_window, 0, 0, width/2, height, True)

        game.gEngine.console_set_default_foreground(equipment_window, r, g, b)
        game.gEngine.console_print_frame(equipment_window, 0, 0, width/2, equip_height, True)

        game.gEngine.console_set_default_foreground(wielded_window, r, g, b)
        game.gEngine.console_print_frame(wielded_window, 0, 0, width/2, wield_height, True)

        game.gEngine.console_set_default_foreground(compare_window, r, g, b)
        game.gEngine.console_print_frame(compare_window, 0, 0, width/2, compare_height, True)

        # ========================================================================
        # print inventory
        # ========================================================================
        game.gEngine.console_print(inventory_window, i_header_pos, 0, i_header)
        letter_index = ord('a')
        if len(player.fighter.inventory) > 0:
            y = 1
            for i in range(len(inventory_items)):
                text = '  (' + chr(letter_index) + ') ' + inventory_items[i]
                if current_selection == y - 1:
                    r, g, b = libtcod.color_lerp(player.fighter.inventory[i].color, libtcod.blue, 0.5)
                    game.gEngine.console_set_default_background(inventory_window, r, g, b)
                else:
                    game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
                game.gEngine.console_print_ex(inventory_window, 1, y+2, libtcod.BKGND_SET, libtcod.LEFT, text)
                y += 1
                letter_index += 1
        game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        game.gEngine.console_print(inventory_window, 1, 31, 'Gold: ' + color_text(str(player.fighter.money), libtcod.gold))

        # ========================================================================
        # print equipped weapons
        # ========================================================================
        game.gEngine.console_print(wielded_window, w_header_pos, 0, w_header)
        index = ord('1')
        if player.fighter.wielded[0] is None:
            text = '(' + chr(index) + ') ' + 'Left Hand : ' + color_text('Empty', libtcod.darker_gray)
        else:
            t = color_text(player.fighter.wielded[0].name.capitalize(), player.fighter.wielded[0].color)
            text = '(' + chr(index) + ') ' + 'Left Hand : ' + t
        index += 1
        game.gEngine.console_print(wielded_window, 1, 2, text)
        if player.fighter.wielded[1] is None:
            text = '(' + chr(index) + ') ' + 'Right Hand: ' + color_text('Empty', libtcod.darker_gray)
        else:
            t = color_text(player.fighter.wielded[1].name.capitalize(), player.fighter.wielded[1].color)
            text = '(' + chr(index) + ') ' + 'Right Hand: ' + t
        index += 1
        game.gEngine.console_print(wielded_window, 1, 3, text)

        item = player.fighter.wielded[0]
        if item:
            damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices, item.item.equipment.damage.nb_faces, item.item.equipment.damage.addsub)
            text = 'Damage   (total): ' + color_text(damage, libtcod.green)
            game.gEngine.console_print(wielded_window, 1, 4, text)
            accuracy = item.item.equipment.accuracy
            accuracy += game.player.fighter.get_skill(item.item.equipment.damage_type).get_bonus()
            text = 'Accuracy (total): ' + color_text(str(accuracy), libtcod.green)
            game.gEngine.console_print(wielded_window, 1, 5, text)

        # ========================================================================
        # print equipped armor
        # ========================================================================
        game.gEngine.console_print(equipment_window, e_header_pos, 0, e_header)
        i = 0
        game.gEngine.console_set_alignment(equipment_window, libtcod.LEFT)
        armor_bonus = 0
        armor_penalty = 0
        for item in player.fighter.equipment:
            text = '(' + chr(index) + ') ' + slots[i] + ': '
            if item is None:
                text += color_text('Empty', libtcod.darker_gray)
            else:
                text += color_text(item.name.capitalize(), item.color)
                armor_bonus += item.item.equipment.bonus
                armor_penalty += item.item.equipment.penalty
            game.gEngine.console_print(equipment_window, 1, i+2, text)
            i += 1
            index += 1
        c = color_text(str(armor_bonus), libtcod.green)
        text = 'Total Armor Bonus  :  ' + c
        game.gEngine.console_print(equipment_window, 1, i+2, text)
        c = color_text(str(armor_penalty), libtcod.red)
        text = 'Total Armor Penalty: -' + c
        game.gEngine.console_print(equipment_window, 1, i+3, text)
        game.gEngine.console_print(compare_window, c_header_pos, 0, c_header)

        # ========================================================================
        # handle mouse input
        # ========================================================================
        mc = master_check.update(mouse, width)
        master_check.render(inventory_window, game)
        if not mc:
            for box in check_boxes:
                box.update(mouse, width)
                box.render(inventory_window, game)
        else:
            for box in check_boxes:
                box.set_checked(master_check.get_checked())
                box.render(inventory_window, game)

        # Inventory input
        if mouse.cx >= width/2+3 and mouse.cx < width-2:  # inventory screen dims
            if (mouse.cy-3) < len(player.fighter.inventory) and mouse.cy-3 >= 0:
                #if mouse.cy-3 <= len(player.fighter.inventory):
                    item = player.fighter.inventory[mouse.cy-3]
                    current_selection = mouse.cy-3
                    if item.item.equipment:
                        game.gEngine.console_print(compare_window, 1, 2, 'Name    : ' + color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(compare_window, 1, 3, 'Type    : ' + item.item.equipment.type.capitalize())
                        if item.item.equipment.type == 'melee':
                            damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices, item.item.equipment.damage.nb_faces, item.item.equipment.damage.addsub )
                            game.gEngine.console_print(compare_window, 1, 4, 'Damage  : ' + damage)
                            game.gEngine.console_print(compare_window, 1, 5, 'Accuracy: ' + str(item.item.equipment.accuracy))
                            game.gEngine.console_print(compare_window, 1, 7, 'Skill   : ' + item.item.equipment.damage_type)
                        else:
                            game.gEngine.console_print(compare_window, 1, 4, 'Armor   : ' + str(item.item.equipment.bonus))
                            game.gEngine.console_print(compare_window, 1, 5, 'Penalty : ' + str(item.item.equipment.penalty))
                            game.gEngine.console_print(compare_window, 1, 7, 'Location: ' + item.item.equipment.location.capitalize())
                        game.gEngine.console_print(compare_window, 1, 6, 'Value   : ' + str(item.item.value))
                    if item.item.spell:
                        game.gEngine.console_print(compare_window, 1, 2, 'Name  : ' + color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(compare_window, 1, 3, 'Type  : ' + item.item.spell.type.capitalize())
                        game.gEngine.console_print(compare_window, 1, 4, 'Power : ' + str(item.item.spell.min) + '-' + str(item.item.spell.max))
                        game.gEngine.console_print(compare_window, 1, 5, 'Range : ' + str(item.item.spell.range))
                        game.gEngine.console_print(compare_window, 1, 6, 'Radius: ' + str(item.item.spell.radius))
                        game.gEngine.console_print(compare_window, 1, 7, 'Value : ' + str(item.item.value))
                    if mouse.lbutton_pressed and item.item.spell:
                        i_n = color_text(item.name.capitalize(), item.color)
                        message = 'Do you want to use %s?' % i_n
                        w = len(message)+2
                        d_box = DialogBox(game, w, 10, width/4, height/2, message, type='option', con=inventory_window)
                        confirm = d_box.display_box()
                        if confirm == 1:  # make sure if the player uses a scroll or potion, we exit inventory
                            d_box.destroy_box()
                            # Remember to remove consoles in reverse order of creation to avoid OOB errors
                            return_item = item
                            break
                        else:
                            d_box.destroy_box()
                    if mouse.lbutton_pressed and item.item.equipment:
                        i_n = color_text(item.name.capitalize(), item.color)
                        message = 'Do you want to put %s on?' % i_n
                        w = len(message)+2
                        d_box = DialogBox(game, w, 10, width/4, height/2, message, type='option', con=inventory_window)
                        confirm = d_box.display_box()
                        if confirm == 1:
                            item.item.use(game.player.fighter.inventory, game.player, game)
                            d_box.destroy_box()
                            inventory_items = []
                            check_boxes = []
                            for x in range(len(player.fighter.inventory)):
                                check_boxes.append(CheckBox(x=1, y=x+3))
                                i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
                                if player.fighter.inventory[x].item.check_stackable:
                                    i += ' (%d)' % player.fighter.inventory[x].item.qty
                                inventory_items.append(i)
            else:
                current_selection = None
        # game.gEngine.console_set_default_background(inventory_window, 0, 0, 0)
        # Wielded
        elif mouse.cx >= 0 and mouse.cx <= ((width/2)-2):  # inventory screen dims
            if (mouse.cy-2) < len(player.fighter.wielded):
                item = player.fighter.wielded[mouse.cy-2]
                if item is not None:
                    if item.item.equipment:
                        game.gEngine.console_print(compare_window, 1, 2, 'Name    : ' + color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(compare_window, 1, 3, 'Type    : ' + item.item.equipment.type.capitalize())
                        damage = '%dd%d+%d' % (item.item.equipment.damage.nb_dices, item.item.equipment.damage.nb_faces, item.item.equipment.damage.addsub )
                        game.gEngine.console_print(compare_window, 1, 4, 'Damage  : ' + damage)
                        game.gEngine.console_print(compare_window, 1, 5, 'Accuracy: ' + str(item.item.equipment.accuracy))
                        game.gEngine.console_print(compare_window, 1, 6, 'Value   : ' + str(item.item.value))

        # Equipment
            elif (mouse.cy-2)-equip_y < len(player.fighter.equipment):
                item = player.fighter.equipment[mouse.cy-2-equip_y]
                if item is not None:
                    if item.item.equipment:
                        game.gEngine.console_print(compare_window, 1, 2, 'Name    : ' + color_text(item.name.capitalize(), item.color))
                        game.gEngine.console_print(compare_window, 1, 3, 'Type    : ' + item.item.equipment.type.capitalize())
                        game.gEngine.console_print(compare_window, 1, 4, 'Armor   : ' + str(item.item.equipment.bonus))
                        game.gEngine.console_print(compare_window, 1, 5, 'Penalty : ' + str(item.item.equipment.penalty))
                        game.gEngine.console_print(compare_window, 1, 6, 'Value   : ' + str(item.item.value))
            if mouse.lbutton_pressed and item is not None:
                i_n = color_text(item.name.capitalize(), item.color)
                message = 'Do you want to take %s off?' % i_n
                w = len(message)+2
                d_box = DialogBox(game, w, 10, width/4, height/2, message, type='option', con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    item.item.equipment.un_equip(game.player, item)
                    d_box.destroy_box()
                    inventory_items = []
                    check_boxes = []
                    for x in range(len(player.fighter.inventory)):
                        check_boxes.append(CheckBox(x=1, y=x+3))
                        i = color_text(player.fighter.inventory[x].name.capitalize(),player.fighter.inventory[x].color)
                        if player.fighter.inventory[x].item.check_stackable:
                            i += ' (%d)' % player.fighter.inventory[x].item.qty
                        inventory_items.append(i)
                    i = 0
                    for x in player.fighter.wielded:
                        if x == item:
                            player.fighter.wielded[i] = None
                        i += 1
                    i = 0
                    for x in player.fighter.equipment:
                        if x == item:
                            player.fighter.equipment[i] = None
                        i += 1

        # keyboard input
        # keeps similar feel to old inventory if using the keys
        # keyboard input is sluggish as balls for some reason, need to look into it more
        index = key.c - ord('a')
        if key:
            if index >= 0 and index < len(inventory_items):
                return_item = player.fighter.inventory[index]
                break
            index = key.c - ord('1')
            if index >= 0 and index <= 1:
                return_item = player.fighter.wielded[index]
                break
            elif index >= 2 and index <= 10:
                return_item = player.fighter.equipment[index-2]
                break
            if key.vk == libtcod.KEY_DOWN:
                if current_selection is None:
                    current_selection = 0
                current_selection += 1
                if current_selection > len(inventory_items):
                    current_selection = 0
            if key.vk == libtcod.KEY_UP:
                if current_selection is None:
                    current_selection = 0
                current_selection -= 1
                if current_selection < 0:
                    current_selection = len(inventory_items)
        # ========================================================================
        # handle buttons
        # ========================================================================
        for i in drop_input:
            if i != -1:
                message = 'Drop all selected items?'
                w = len(message)+2
                d_box = DialogBox(game, w, 10, width/2-w/2, height/2-5, message, type='option', con=inventory_window)
                confirm = d_box.display_box()
                if confirm == 1:
                    d_box.destroy_box()
                    master_check.set_checked(False)
                    items_to_drop = []
                    for box in check_boxes:
                        if box.get_checked():
                            items_to_drop.append(player.fighter.inventory[box.y-3])
                    for item_to_drop in items_to_drop:
                        if item_to_drop:
                            item_to_drop.objects = game.objects
                            item_to_drop.item.drop(player.fighter.inventory, player, False)
                            item_to_drop.send_to_back()
                    check_boxes = []
                    inventory_items = []
                    for x in range(len(player.fighter.inventory)):
                        check_boxes.append(CheckBox(x=1, y=x+3))
                        inventory_items.append(color_text(player.fighter.inventory[x].name.capitalize(),
                                                          player.fighter.inventory[x].color))
                else:
                    d_box.destroy_box()
        # ========================================================================
        # handle exit button
        # ========================================================================

        for i in exit_input:
            if i != -1:
                key.vk = libtcod.KEY_ESCAPE
                break
    # Remember to remove consoles in reverse order of creation to avoid OOB errors
    drop_button.destroy_button()
    exit_button.destroy_button()
    game.gEngine.console_remove_console(compare_window)
    game.gEngine.console_remove_console(wielded_window)
    game.gEngine.console_remove_console(equipment_window)
    game.gEngine.console_remove_console(inventory_window)

    return return_item
コード例 #58
0
 def mouse_input(self):
     ##============================================================================
     mouse = libtcod.mouse_get_status()
     mx = mouse.cx - self.x_pos
     my = mouse.cy - self.y_pos