Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - KM

Pages: [1]
1
Programming / Screen Not Refreshing upon Menu Close
« on: January 28, 2017, 10:39:39 PM »
I've been struggling lately with having my screen refresh upon the inventory or level-up menu being closed.  I'm going to put relevant parts of script here, any help is appreciated.  Other minor bugs;
1.  The screen, upon resizing, doesn't resize any of the menu bars to make them fit the new window size that bearlibterminal imparts.
2.  I'd like to be able to display names with just a mouse hover, rather than a mouse click, mouse-click I'd like to work into having a more full description come up.  Not sure where or if there are commands for these things.

Quote
def inventory_menu(header):
    global fov_recompute
    #show a menu with each item of the inventory as an option
    if len(inventory) == 0:
        options = ['Inventory is empty.']
    else:
        options = []
        for item in inventory:
            text = item.name
            #show additional info, in case it's equipped
            if item.equipment and item.equipment.is_equipped:
                text = text + ' (on ' + item.equipment.slot + ')'
            options.append(text)
        #options = [item.name for item in inventory]
    index = menu(header, options, INVENTORY_WIDTH)
    #if an item was chosen, return it
    if index is None or len(inventory) == 0: return None
    return inventory[index].item

    terminal.layer(6)
    terminal.clear_area(0, 0, MAP_WIDTH, MAP_HEIGHT)
    fov_recompute = True

Quote
def handle_keys():
    terminal.set('window.resizeable=true')
    global fov_recompute
    # Read keyboard input
    global key

    key = terminal.read()
    if key == terminal.TK_ESCAPE:
        # Close terminal
        return 'exit'
    if game_state == 'playing':
        #??? it was 'exit()'
        a = 'player moved'
        if key == terminal.TK_KP_2 or key == terminal.TK_DOWN:
            player_move_or_attack(0, 1)
            return a
        elif key == terminal.TK_KP_8 or key == terminal.TK_UP:
            player_move_or_attack(0, -1)
            return a
        elif key == terminal.TK_KP_6 or key == terminal.TK_RIGHT:
            player_move_or_attack(1, 0)
            return a
        elif key == terminal.TK_KP_4 or key == terminal.TK_LEFT:
            player_move_or_attack(-1, 0)
            return a
        elif key == terminal.TK_KP_7:
            player_move_or_attack(-1, -1)
            return a
        elif key == terminal.TK_KP_9:
            player_move_or_attack(1, -1)
            return a
        elif key == terminal.TK_KP_1:
            player_move_or_attack(-1, 1)
            return a
        elif key == terminal.TK_KP_3:
            player_move_or_attack(1, 1)
            return a
        elif key == terminal.TK_KP_5:
            return a
        else: #test for other keys
            if key == terminal.TK_G:
                #pick up an item
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break

            if key == terminal.TK_I:
                #show the inventory; if an item is selected, use it
                chosen_item = inventory_menu('Press the key next to an item to use it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.use()

            if key == terminal.TK_D:
                #show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu('Press the key next to an item to drop it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.drop()

            if key == terminal.TK_C:
                #show character info
                level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
                msgbox('Character Information\n\nLevel: ' + str(player.level) +
                       '\nExperience: ' + str(player.fighter.xp) + ' / ' + str(level_up_xp) +
                       '\n\nMaximum HP: ' + str(player.fighter.max_hp) +
                    '\nAttack: ' + str(player.fighter.power) + '\nDefense: ' + str(player.fighter.defense), CHARACTER_SCREEN_WIDTH)

            if key == terminal.TK_SHIFT:
                key = terminal.read()
                if key == terminal.TK_PERIOD and stairs.x == player.x and stairs.y == player.y:
                    #go down stairs, if the player is on them
                        next_level()
         
         key = terminal.read()
         if key == terminal.TK_RESIZED:
            new_columns = terminal.state(terminal.TK_WIDTH)
            new_rows = terminal.state(terminal.TK_HEIGHT)
         

    return 'didnt-take-turn'

2
Programming / Packaging a python script as an executable
« on: January 17, 2017, 04:11:41 AM »
Hi; I'm trying to package my python script as an executable, but am finding it very difficult.  I'm following the directions at py2exe.org, and am using bearlibterminal and libtcod, and am getting dependencies that I don't understand how to fix.  When I try to click the .exe file I created, it just crashes with no errors, but it runs fine when I launch it out of powershell.

Here's what powershell tells me when I'm trying to run the .exe from there:

Code: [Select]
PS C:\Python27\Grit\dist> .\gritandsteel.exe
Traceback (most recent call last):
  File "gritandsteel.py", line 6, in <module>
  File "zipextimporter.pyc", line 82, in load_module
  File "PyBearLibTerminal.pyc", line 58, in <module>
  File "PyBearLibTerminal.pyc", line 56, in _load_library
RuntimeError: BearLibTerminal library cannot be loaded (looked for BearLibTerminal.dll in C:\Python27\Grit\dist\gritandsteel.exe)
PS C:\Python27\Grit\dist>

I don't know why it's looking for the .dll IN the .exe, or how I would fix it.  BearLibTerminal.dll is in the same file directory as my .exe.

I created the .exe using the tutorial code here:
Code: [Select]
from distutils.core import setup
import py2exe
import os
import sys
 
sys.argv.append('py2exe')
 
# The filename of the script you use to start your program.
target_file = 'gritandsteel.py'
 
# The root directory containing your assets, libraries, etc.
assets_dir = '.\\'
 
# Filetypes not to be included in the above.
excluded_file_types = ['py','pyc','project','pydevproject']
 
def get_data_files(base_dir, target_dir, list=[]):
    """
    " * get_data_files
    " *    base_dir:    The full path to the current working directory.
    " *    target_dir:  The directory of assets to include.
    " *    list:        Current list of assets. Used for recursion.
    " *
    " *    returns:     A list of relative and full path pairs. This is
    " *                 specified by distutils.
    """
    for file in os.listdir(base_dir + target_dir):
 
        full_path = base_dir + target_dir + file
        if os.path.isdir(full_path):
            get_data_files(base_dir, target_dir + file + '\\', list)
        elif os.path.isfile(full_path):
            if (len(file.split('.')) == 2 and file.split('.')[1] not in excluded_file_types):
                list.append((target_dir, [full_path]))
 
    return list
 
# The directory of assets to include.
my_files = get_data_files(sys.path[0] + '\\', assets_dir)
 
# Build a dictionary of the options we want.
opts = { 'py2exe': {
                    'ascii':'True',
                    'excludes':['_ssl','_hashlib'],
                    'includes' : ['anydbm', 'dbhash'],
                    'bundle_files':'1',
                    'compressed':'True'}}
 
# Run the setup utility.
setup(console=[target_file],
      data_files=my_files,
      zipfile=None,
      options=opts)

Any help is appreciated as to why this isn't launching.  Thank you.

Pages: [1]