Exemplo n.º 1
0
def npc_death(npcc):
    npc = npcc.owner
    # npc death
    message(
        npc.name.upper() + ' is dead! You gain ' + str(npc.fighter.xp) + 'XP!',
        libtcod.cyan)
    npc.char = '%'
    npc.color = libtcod.dark_red
    npc.blocks = False
    npc.fighter = None
    npc.ai = None
    npc.name = 'remains of ' + npc.name.upper()
    gameconfig.npc_count -= 1
Exemplo n.º 2
0
def new_level():
    # go to next level
    # we should also consider storing the previous levels so you can return to previously explored ones
    message('You take a moment to rest and recover your strength.',
            libtcod.light_cyan)
    gameconfig.player.fighter.heal(gameconfig.player.fighter.max_hp / 2)
    message(
        'After a moment of peace, you descend deeper into the depths of horror.',
        libtcod.dark_red)
    gameconfig.game_level += 1

    # create new level
    clear_console(gameconfig.con)
    make_map()

    new_level = [
        gameconfig.objects, gameconfig.level_map, gameconfig.stairs_up,
        gameconfig.stairs_down, gameconfig.color_theme, gameconfig.fov_map
    ]
    gameconfig.game_levels.append(new_level)
Exemplo n.º 3
0
import libtcodpy as libtcod
import gameconfig
from interface.menus import main_menu
from interface.helpers import message, message_box
from game.states import new_game, play_game, save_game, load_game
from game import game_messages

choice = main_menu()

while not libtcod.console_is_window_closed():
    if choice == 0:
        new_game()
        message(game_messages.WELCOME_MESSAGE, libtcod.red)
        play_game()
        break
    if choice == 1:
        try:
            load_game()
        except:
            message_box(game_messages.NO_LOAD_DATA, 24)
            continue
        play_game()
    elif choice == 2:
        break
Exemplo n.º 4
0
def handle_keys():
    # primary game controls
    # exit
    _player = gameconfig.player
    _stairsU = gameconfig.stairs_up
    _stairsD = gameconfig.stairs_down
    if gameconfig.key.vk == libtcod.KEY_ESCAPE:
        choice = main_menu()
        if choice == 2:
            return 'exit'
        else:
            return 'no turn'

    # 8-D movement arrorw gameconfig.keys or numpad
    if gameconfig.key.vk == libtcod.KEY_UP or gameconfig.key.vk == libtcod.KEY_KP8:
        player_move_or_attack(0, -1)
    elif gameconfig.key.vk == libtcod.KEY_DOWN or gameconfig.key.vk == libtcod.KEY_KP2:
        player_move_or_attack(0, 1)
    elif gameconfig.key.vk == libtcod.KEY_LEFT or gameconfig.key.vk == libtcod.KEY_KP4:
        player_move_or_attack(-1, 0)
    elif gameconfig.key.vk == libtcod.KEY_RIGHT or gameconfig.key.vk == libtcod.KEY_KP6:
        player_move_or_attack(1, 0)
    elif gameconfig.key.vk == libtcod.KEY_KP7:
        player_move_or_attack(-1, -1)
    elif gameconfig.key.vk == libtcod.KEY_KP9:
        player_move_or_attack(1, -1)
    elif gameconfig.key.vk == libtcod.KEY_KP1:
        player_move_or_attack(-1, 1)
    elif gameconfig.key.vk == libtcod.KEY_KP3:
        player_move_or_attack(1, 1)
    elif gameconfig.key.vk == libtcod.KEY_KP5:
        #message('You wait a turn for the darkness to close in on you.', libtcod.white)
        pass

    else:
        # additional game commands
        gameconfig.key_char = chr(gameconfig.key.c)

        # pick up an item
        if gameconfig.key_char == 'g':
            for obj in gameconfig.objects:
                if obj.x == _player.x and obj.y == _player.y and obj.item:

                    if len(_player.player.inventory) >= 26:
                        return ('Your inventory is full, cannot pick up ' +
                                self.owner.name + '.', libtcod.pink)
                    else:
                        message(_player.player.add_item_inventory(obj.item))
                        gameconfig.objects.remove(obj.item.owner)
                        gameconfig.item_count -= 1

        # go up down stairs if player is on them
        if gameconfig.key_char == ',' or gameconfig.key_char == '.':
            if _stairsU.x == _player.x and _stairsU.y == _player.y:
                if gameconfig.game_level - 1 > 0:
                    return ('stairs up')
            if _stairsD.x == _player.x and _stairsD.y == _player.y:
                if gameconfig.game_level >= len(gameconfig.game_levels):
                    return ('stairs new')
                else:
                    return ('stairs down')

        # display inventory
        if gameconfig.key_char == 'i':
            selection = -1
            chosen_item = inventory_menu(
                'Press the key next to an item to use it, or ESC to cancel\n',
                _player.player.inventory)
            if chosen_item is not None:
                chosen_item.use(_player.fighter)

        # drop item
        if gameconfig.key_char == 'd':
            chosen_item = inventory_menu(
                'Press the key next to an item to drop it.\n')
            if chosen_item is not None:
                chosen_item.drop()

        # show character info
        if gameconfig.key_char == 'c':
            level_up_xp = gameconfig.LEVEL_UP_BASE + _player.player.level * gameconfig.LEVEL_UP_FACTOR
            message_box(
                'Character Information\n\nLevel: ' +
                str(_player.player.level) + '\nExperience: ' +
                str(_player.fighter.xp) + '\nExperience to level up: ' +
                str(level_up_xp) + '\n\nMaximum HP: ' +
                str(_player.fighter.max_hp) + '\nAttack: ' +
                str(_player.fighter.power) + '\nDefense: ' +
                str(_player.fighter.defense), 24)

        # toggle fullscreen
        if gameconfig.key_char == 'f':
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        return ('no turn')  # nothing valid happened
    return ('playing')  # carry on
Exemplo n.º 5
0
def player_death(player):
    # you ded
    message('You died!', libtcod.white)
    player.char = '%'
    player.color = libtcod.dark_red
    return 'dead'  #game_state