Exemplo n.º 1
0
import gamelib.Utils as Utils

# First of all let's create a Game object
mygame = Game(name="Demo game")

# Set a message variable to display a message on selected menu item
message = None

# Now we want to create some menus to tell the player what to do, or to
# give some informations/directions
# IMPORTANT: Menu do absolutely nothing by themselves, they are just a
# structured display of informations.
# The syntaxe is game_object.add_menu_entry(category,shortcut,message)
option_red = "A cool menu in dim red"
option_magenta = "Another cool menu in bright magenta"
mygame.add_menu_entry("main_menu", None, "=" * 22)
mygame.add_menu_entry("main_menu", "h", "Show the help menu")
mygame.add_menu_entry("main_menu", None, "=" * 22)
mygame.add_menu_entry("main_menu", "1", Utils.red_dim(option_red))
mygame.add_menu_entry("main_menu", "2", Utils.magenta_bright(option_magenta))
mygame.add_menu_entry("main_menu", "q", "Quit game")

mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", None, "Help Menu")
mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", "j", "Random help menu")
mygame.add_menu_entry("help_menu", "b", "Back to main menu")

# let's set a variable that hold the current menu category (for navigation)
current_menu = "main_menu"
# Now let's make a loop to dynamically navigate in the menu
Exemplo n.º 2
0
    print('Looking for existing maps in selected directories...', end='')
    with open('directories.json') as paths:
        directories = json.load(paths)
        hmaps = []
        try:
            for directory in directories:
                files = [f'{directory}/{f}' for f in os.listdir(directory)]
                hmaps += files
            print(Utils.green('OK'))
        except FileNotFoundError as e:
            print(Utils.red('KO'))

    if len(hmaps) > 0:
        map_num = 0
        game.add_menu_entry('boards_list', None, "Choose a map to edit")
        for m in hmaps:
            print(f"{map_num} - edit {m}")
            game.add_menu_entry('boards_list', str(map_num), f"edit {m}",
                                f"{m}")
            map_num += 1
        game.add_menu_entry('boards_list', 'B', "Go Back to main menu")
    else:
        print('No pre-existing map found.')
    print('n - create a new map')
    print('q - Quit the editor')
    choice = input('Enter your choice (and hit ENTER): ')
    if choice == 'q':
        print('Good Bye!')
        exit()
    elif choice == 'n':
Exemplo n.º 3
0
        step=1,
    ), 7, 9)

lvl2.place_item(money_bag, 10, 35)
lvl2.place_item(portal1, 11, 35)

for k in range(0, 20, 1):
    game.add_npc(2, NPC(model=sprite_npc2, name=f'poopy_{k}', step=1))

# Now let's add a nice NPC, one we can talk to!
nice_npc = NPC(name='Unipici', model=Sprites.UNICORN_FACE,
               step=0)  # because of step=0 this NPC is static
game.add_npc(1, nice_npc, 18, 1)
# Now let's use the menu system to have the basis for a dialog
game.add_menu_entry(
    'unipici_dialog', None,
    'Hello! I am Unipici. Nice to meet you! What can I do for you?')
game.add_menu_entry('unipici_dialog', '1',
                    'Restore my life ' + Sprites.HEART_SPARKLING)
game.add_menu_entry('unipici_dialog', '2', 'Nearly kill me ' + Sprites.SKULL)
game.add_menu_entry('unipici_dialog', '3', 'Solve the Uni-riddle')
game.add_menu_entry('unipici_dialog', '4', 'Stop talking')

game.add_menu_entry('main_menu', 'w', 'Go up')
game.add_menu_entry('main_menu', 's', 'Go down')
game.add_menu_entry('main_menu', 'a', 'Go left')
game.add_menu_entry('main_menu', 'd', 'Go right')
game.add_menu_entry('main_menu', None, '-' * 17)
game.add_menu_entry('main_menu', 'v', 'Change game speed')
game.add_menu_entry('main_menu', 'k', 'Damage player (5 HP)')
game.add_menu_entry('main_menu', 'q', 'Quit game')
Exemplo n.º 4
0
import examples_includes
# For this example we need to import Game, Board, Utils and Player
from gamelib.Game import Game
import gamelib.Utils as Utils

# First of all let's create a Game object
mygame = Game(name='Demo game')

# Set a message variable to display a message on selected menu item
message = None

# Now we want to create some menus to tell the player what to do, or to give some informations/directions
# IMPORTANT: Menu do absolutely nothing by themselves, they are just a structured display of informations
# The syntaxe is game_object.add_menu_entry(category,shortcut,message)
mygame.add_menu_entry('main_menu', None, '=' * 22)
mygame.add_menu_entry('main_menu', 'h', 'Show the help menu')
mygame.add_menu_entry('main_menu', None, '=' * 22)
mygame.add_menu_entry('main_menu', '1',
                      Utils.red_dim('A cool menu in dim red'))
mygame.add_menu_entry(
    'main_menu', '2',
    Utils.magenta_bright('Another cool menu in bright magenta'))
mygame.add_menu_entry('main_menu', 'q', 'Quit game')

mygame.add_menu_entry('help_menu', None, '---------')
mygame.add_menu_entry('help_menu', None, 'Help Menu')
mygame.add_menu_entry('help_menu', None, '---------')
mygame.add_menu_entry('help_menu', 'j', 'Random help menu')
mygame.add_menu_entry('help_menu', 'b', 'Back to main menu')

# let's set a variable that hold the current menu category (for navigation)
Exemplo n.º 5
0
        item.action_parameters = [2]
        item.set_overlappable(True)
    # Set a higher score value to the money bags
    elif item.type == 'money':
        item.value = 100
    # Same thing with the Scroll of Wisdom.
    elif item.type == 'scroll':
        item.value = 1000
    # Finally, we set the fire walls to damage the player a bit
    elif item.type == 'fire_wall':
        item.action = damage_player
        item.action_parameters = [10]

# Now let's build the menus
# First the default menu with only one entry : the help menu.
g.add_menu_entry('default','h','Type the "h" key to display the help menu')
# Now the actual help menu
g.add_menu_entry('help','w','Move the player up')
g.add_menu_entry('help','s','Move the player down')
g.add_menu_entry('help','a','Move the player left')
g.add_menu_entry('help','d','Move the player right')
g.add_menu_entry('help','q','Quit the game')
g.add_menu_entry('help','b','Go back to the game')
# Let's take care of the portal fairy dialog now
update_fairy_dialog()
# We are going to need to add the options to give gold bags to the fairy only if the player collected the gold before going to the fairy.

# This variable is the input buffer.
key = None
# This one is going to be useful later
run = True
Exemplo n.º 6
0
        item.action_parameters = [2]
        item.set_overlappable(True)
    # Set a higher score value to the money bags
    elif item.type == "money":
        item.value = 100
    # Same thing with the Scroll of Wisdom.
    elif item.type == "scroll":
        item.value = 1000
    # Finally, we set the fire walls to damage the player a bit
    elif item.type == "fire_wall":
        item.action = damage_player
        item.action_parameters = [10]

# Now let's build the menus
# First the default menu with only one entry : the help menu.
g.add_menu_entry("default", "h", 'Type the "h" key to display the help menu')
# Now the actual help menu
g.add_menu_entry("help", "w", "Move the player up")
g.add_menu_entry("help", "s", "Move the player down")
g.add_menu_entry("help", "a", "Move the player left")
g.add_menu_entry("help", "d", "Move the player right")
g.add_menu_entry("help", "q", "Quit the game")
g.add_menu_entry("help", "b", "Go back to the game")
# Let's take care of the portal fairy dialog now
update_fairy_dialog()
# We are going to need to add the options to give gold bags to the fairy only if the
# player collected the gold before going to the fairy.

# This variable is the input buffer.
key = None
# This one is going to be useful later
Exemplo n.º 7
0
            for f in os.listdir(directory):
                if os.path.isabs(f):
                    hmaps.append(f)
                else:
                    if os.path.exists(f):
                        hmaps.append(f)
                    elif os.path.exists(os.path.join(directory, f)):
                        hmaps.append(os.path.join(directory, f))
    if len(hmaps) > 0:
        print(Utils.green("OK"))
    else:
        print(Utils.red_bright("KO"))

    if len(hmaps) > 0:
        map_num = 0
        game.add_menu_entry("boards_list", None, "Choose a map to edit")
        for m in hmaps:
            print(f"{map_num} - edit {m}")
            game.add_menu_entry("boards_list", str(map_num), f"edit {m}",
                                f"{m}")
            map_num += 1
        game.add_menu_entry("boards_list", "B", "Go Back to main menu")
    else:
        print("No pre-existing map found.")
    print("n - create a new map")
    print("q - Quit the editor")
    choice = input("Enter your choice (and hit ENTER): ")
    if choice == "q":
        print("Good Bye!")
        exit()
    elif choice == "n":