def switch_edit_mode(): global edit_mode edit_mode = not edit_mode if edit_mode: game.update_menu_entry( "main", Utils.white_bright("j/i/k/l"), Utils.green_bright("Place") + " the current object and then move cursor Left/Up/Down/Right", ) game.update_menu_entry( "main", Utils.white_bright("0 to 9"), Utils.green_bright("Select") + " an item in history to be the current item", ) else: game.update_menu_entry( "main", Utils.white_bright("j/i/k/l"), "Move cursor Left/Up/Down/Right and " + Utils.red_bright("Delete") + " anything that was at destination.", ) game.update_menu_entry( "main", Utils.white_bright("0 to 9"), Utils.red_bright("Remove") + " an item from history", )
def switch_edit_mode(): global edit_mode edit_mode = not edit_mode if edit_mode: game.update_menu_entry('main',Utils.white_bright('j/i/k/l'),Utils.green_bright('Place')+' the current object and then move cursor Left/Up/Down/Right') game.update_menu_entry('main',Utils.white_bright('0 to 9'),Utils.green_bright('Select')+' an item in history to be the current item') else: game.update_menu_entry('main',Utils.white_bright('j/i/k/l'),'Move cursor Left/Up/Down/Right and '+Utils.red_bright('Delete')+' anything that was at destination.') game.update_menu_entry('main',Utils.white_bright('0 to 9'),Utils.red_bright('Remove')+' an item from history')
def activate_portal(params): global g level = params[0] if level == 1: if g.current_board().item(3, 3).model == Sprites.CYCLONE: # That logic is just a placeholder for the moment, ultimately it will lead to the next level g.clear_screen() print(Utils.green_bright("CONGRATULATIONS\n\nYOU WIN!")) exit()
def activate_portal(params): global g level = params[0] if level == 1: if g.current_board().item(3,3).model == Sprites.CYCLONE: # That logic is just a placeholder for the moment, ultimately it will lead to the next level g.clear_screen() print( Utils.green_bright("CONGRATULATIONS\n\nYOU WIN!") ) exit() elif level == 2: g.clear_screen() print_animated(f"{Sprites.UNICORN_FACE}: Congratulations {g.player.name}, you found the entrance to a world of riches!\n{Sprites.UNICORN_FACE}: However, your time is limited and you will need to grab as much treasures as you can in 20 moves only!\n{Sprites.UNICORN_FACE}: Good luck!") input("\n\n(Hit ENTER when you are ready to enter the world of riches)") g.player.inventory.max_size += 1500 g.change_level(2)
def refresh_screen(): global g global notifications global current_menu global level_2_turns_left g.clear_screen() g.display_player_stats() g.display_board() if g.current_level == 2: print( Utils.cyan_bright(f"Inventory ({g.player.inventory.size()}/" f"{g.player.inventory.max_size}) ") + Utils.green_bright(f"Turns left: {level_2_turns_left} ")) else: print( Utils.cyan_bright((f"Inventory ({g.player.inventory.size()}/" f"{g.player.inventory.max_size}) "))) if g.player.inventory.size() > 0: # If inventory is not empty print it items_by_type = {} for item_name in g.player.inventory.items_name(): item = g.player.inventory.get_item(item_name) if item.type in items_by_type.keys(): items_by_type[item.type]["cumulated_size"] += item.size() else: items_by_type[item.type] = { "cumulated_size": item.size(), "model": item.model, "name": item.name, } count = 1 for k in items_by_type.keys(): print( f" {items_by_type[k]['model']} : {items_by_type[k]['cumulated_size']} ", end="", ) count += 1 if count == 5: count = 0 print("\n", end="") print("\n", end="") # Then we display the menu g.display_menu(current_menu, Constants.ORIENTATION_VERTICAL, 15) # And finally the notifications for n in notifications: print(n)
def create_wizard(): global game key = '' while True: game.clear_screen() print(Utils.green_bright("\t\tObject creation wizard")) print('What do you want to create: a NPC or a structure?') print('1 - NPC (Non Playable Character)') print('2 - Structure (Wall, Door, Treasure, Portal, Trees, etc.)') key = Utils.get_key() if key == '1' or key == '2': break if key == '1': game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.cyan_bright("NPC")) new_object = NPC() print("First give a name to your NPC. Default value: " + new_object.name) r = str(input('(Enter name)> ')) if len(r) > 0: new_object.name = r print( "Then give it a type. A type is important as it allows grouping.\nType is a string. Default value: " + new_object.type) r = str(input('(Enter type)> ')) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.cyan_bright("NPC") + f' - {new_object.model}') print( 'We now needs to go through some basic statistics. You can decide to go with default by simply hitting the "Enter" key.' ) r = input_digit( f'Number of cell crossed in one turn. Default: {new_object.step}(type: int) > ' ) if len(r) > 0: new_object.step = int(r) else: # If it's 0 it means it's going to be a static NPC so to prevent python to pass some random pre-initialized default, we explicitly set the Actuator to a static one new_object.actuator = SimpleActuators.RandomActuator(moveset=[]) r = input_digit( f'Max HP (Health Points). Default: {new_object.max_hp}(type: int) > ' ) if len(r) > 0: new_object.max_hp = int(r) new_object.hp = new_object.max_hp r = input_digit( f'Max MP (Mana Points). Default: {new_object.max_mp}(type: int) > ' ) if len(r) > 0: new_object.max_mp = int(r) new_object.mp = new_object.max_mp r = input_digit( f'Remaining lives (it is advised to set that to 1 for a standard NPC). Default: {new_object.remaining_lives}(type: int) > ' ) if len(r) > 0: new_object.remaining_lives = int(r) r = input_digit( f'AP (Attack Power). Default: {new_object.attack_power}(type: int) > ' ) if len(r) > 0: new_object.attack_power = int(r) r = input_digit( f'DP (Defense Power). Default: {new_object.defense_power}(type: int) > ' ) if len(r) > 0: new_object.defense_power = int(r) r = input_digit( f'Strength. Default: {new_object.strength}(type: int) > ') if len(r) > 0: new_object.strength = int(r) r = input_digit( f'Intelligence. Default: {new_object.intelligence}(type: int) > ') if len(r) > 0: new_object.intelligence = int(r) r = input_digit( f'Agility. Default: {new_object.agility}(type: int) > ') if len(r) > 0: new_object.agility = int(r) game.clear_screen() print( "We now need to give some life to that NPC. What kind of movement should it have:" ) print("1 - Randomly chosen from a preset of directions") print("2 - Following a predetermined path") r = Utils.get_key() if r == '1': new_object.actuator = SimpleActuators.RandomActuator(moveset=[]) print( 'Random it is! Now choose from which preset of movements should we give it:' ) print('1 - UP,DOWN,LEFT, RIGHT') print('2 - UP,DOWN') print('3 - LEFT, RIGHT') print('4 - UP,DOWN,LEFT, RIGHT + all DIAGONALES') print( '5 - DIAGONALES (DIAG UP LEFT, DIAG UP RIGHT, etc.) but NO straight UP, DOWN, LEFT and RIGHT' ) print('6 - No movement') r = Utils.get_key() if r == '1': new_object.actuator.moveset = [ Constants.UP, Constants.DOWN, Constants.LEFT, Constants.RIGHT ] elif r == '2': new_object.actuator.moveset = [Constants.UP, Constants.DOWN] elif r == '3': new_object.actuator.moveset = [Constants.RIGHT, Constants.LEFT] elif r == '4': new_object.actuator.moveset = [ Constants.UP, Constants.DOWN, Constants.LEFT, Constants.RIGHT, Constants.DLDOWN, Constants.DLUP, Constants.DRDOWN, Constants.DRUP ] elif r == '5': new_object.actuator.moveset = [ Constants.DLDOWN, Constants.DLUP, Constants.DRDOWN, Constants.DRUP ] elif r == '6': new_object.actuator.moveset = [] else: Utils.warn( f'"{r}" is not a valid choice. Movement set is now empty.') new_object.actuator.moveset = [] elif r == '2': new_object.actuator = SimpleActuators.PathActuator(path=[]) print("Great, so what path this NPC should take:") print('1 - UP/DOWN patrol') print('2 - DOWN/UP patrol') print('3 - LEFT/RIGHT patrol') print('4 - RIGHT/LEFT patrol') print('5 - Circle patrol: LEFT, DOWN, RIGHT, UP') print('6 - Circle patrol: LEFT, UP, RIGHT, DOWN') print('7 - Circle patrol: RIGHT, DOWN, LEFT, UP') print('8 - Circle patrol: RIGHT, UP, LEFT, DOWN') print('9 - Write your own path') r = Utils.get_key() if r == '1': print( "How many steps should the NPC go in one direction before turning back ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == '2': print( "How many steps should the NPC go in one direction before turning back ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == '3': print( "How many steps should the NPC go in one direction before turning back ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] elif r == '3': print( "How many steps should the NPC go in one direction before turning back ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] elif r == '4': print( "How many steps should the NPC go in one direction before turning back ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == '5': print( "How many steps should the NPC go in EACH direction before changing ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == '6': print( "How many steps should the NPC go in EACH direction before changing ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == '7': print( "How many steps should the NPC go in EACH direction before changing ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == '8': print( "How many steps should the NPC go in EACH direction before changing ?" ) r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == '9': print( "Write your own path using only words from this list: UP, DOWN, LEFT, RIGHT, DLDOWN, DLUP, DRDOWN, DRUP." ) print('Each direction has to be separated by a coma.') r = str(input('Write your path: ')).upper() new_object.actuator.path = r.split(',') else: Utils.warn(f'"{r}" is not a valid choice. Path is now empty.') new_object.actuator.path = [] return new_object elif key == '2': while True: game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.magenta_bright("Structure")) print("What kind of structure do you want to create:") print( '1 - A wall like structure (an object that cannot be picked-up and is not overlappable). Ex: walls, trees, non moving elephant (try to go through an elephant or to pick it up in your backpack...)' ) print('2 - A door (player and/or NPC can go through)') print( '3 - A treasure (can be picked up, take space in the inventory, give points to the player)' ) print( '4 - A generic object (you can set the properties to make it pickable or overlappable)' ) print( '5 - A generic actionable object (to make portals, heart to replenish life, etc.)' ) key = Utils.get_key() new_object = None if key == '1': new_object = Structures.Wall() new_object.name = str(uuid.uuid1()) new_object.model = model_picker() break elif key == '2': new_object = Structures.Door() new_object.name = str(uuid.uuid1()) new_object.model = model_picker() break elif key == '3': new_object = Structures.Treasure() print("First give a name to your Treasure. Default value: " + new_object.name) r = str(input('(Enter name)> ')) if len(r) > 0: new_object.name = r print( "Then give it a type. A type is important as it allows grouping (in this case probably in the inventory).\nType is a string. Default value: " + new_object.type) r = str(input('(Enter type)> ')) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() break elif key == '4' or key == '5': if key == '4': new_object = Structures.GenericStructure() else: new_object = Structures.GenericActionableStructure() new_object.set_overlappable(False) new_object.set_pickable(False) print("First give a name to your structure. Default value: " + new_object.name) r = str(input('(Enter name)> ')) if len(r) > 0: new_object.name = r print( "Then give it a type. \nType is a string. Default value: " + new_object.type) r = str(input('(Enter type)> ')) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() print( 'Is this object pickable? (can it be picked up by the player)?' ) print('0 - No') print('1 - Yes') r = Utils.get_key() if r == '1': new_object.set_pickable(True) print( 'Is this object overlappable? (can it be walked over by player?' ) print('0 - No') print('1 - Yes') r = Utils.get_key() if r == '1': new_object.set_overlappable(True) break return new_object #Placeholder return BoardItemVoid()
'"' + getattr(Utils, sp) + '"', getattr(Utils, sp)) i += 1 i = 0 for sp in dir(Sprites): if not sp.startswith('__'): game.add_menu_entry('graphics_sprites', str(i), getattr(Sprites, sp), getattr(Sprites, sp)) i += 1 game.add_menu_entry('main', None, '\n=== Menu (' + menu_mode + ') ===') game.add_menu_entry('main', Utils.white_bright('Space'), 'Switch between edit/delete mode') game.add_menu_entry( 'main', Utils.white_bright('0 to 9'), Utils.green_bright('Select') + ' an item in history to be the current item') game.add_menu_entry('main', Utils.white_bright('a/w/s/d'), 'Move cursor Left/Up/Down/Right') game.add_menu_entry( 'main', Utils.white_bright('j/i/k/l'), Utils.green_bright('Place') + ' the current item and then move cursor Left/Up/Down/Right') game.add_menu_entry( 'main', Utils.white_bright('c'), 'Create a new board item (becomes the current item, previous one is placed in history)' ) game.add_menu_entry('main', Utils.white_bright('p'), 'Modify board parameters') game.add_menu_entry('main', Utils.white_bright('P'), 'Set player starting position') game.add_menu_entry('main', Utils.white_bright('S'),
# Now let's make a loop to dynamically navigate in the menu key = None while True: # clear screen mygame.clear_screen() # First print the message is something is in it the variable if message is not None: print(message) # We don't want to print the message more than once, so we put # the message to None once it's printed. message = None # Now let's display the main_menu mygame.display_menu(current_menu) # Take user input key = input("> ") if key == "1" or key == "2" or key == "j": message = Utils.green_bright(f"Selected menu is: {current_menu}/{key}") elif key == "q": print("Quitting...") break elif key == "h": current_menu = "help_menu" elif key == "b": current_menu = "main_menu" else: message = Utils.red_bright("Invalid menu shortcut.")
# Build the menus i = 0 for sp in dir(Utils): if sp.endswith('_SQUARE') or sp.endswith('_RECT'): game.add_menu_entry('graphics_utils',str(i), '"'+getattr(Utils,sp)+'"', getattr(Utils,sp)) i += 1 i = 0 for sp in dir(Sprites): if not sp.startswith('__'): game.add_menu_entry('graphics_sprites',str(i), getattr(Sprites,sp), getattr(Sprites,sp) ) i += 1 game.add_menu_entry('main',None,'\n=== Menu ('+menu_mode+') ===') game.add_menu_entry('main',Utils.white_bright('Space'),'Switch between edit/delete mode') game.add_menu_entry('main',Utils.white_bright('0 to 9'),Utils.green_bright('Select')+' an item in history to be the current item') game.add_menu_entry('main',Utils.white_bright('a/w/s/d'),'Move cursor Left/Up/Down/Right') game.add_menu_entry('main',Utils.white_bright('j/i/k/l'),Utils.green_bright('Place')+' the current item and then move cursor Left/Up/Down/Right') game.add_menu_entry('main',Utils.white_bright('c'),'Create a new board item (becomes the current item, previous one is placed in history)') game.add_menu_entry('main',Utils.white_bright('p'),'Modify board parameters') game.add_menu_entry('main',Utils.white_bright('P'),'Set player starting position') game.add_menu_entry('main',Utils.white_bright('S'),'Save the current Board to hac-maps/'+game.current_board().name.replace(' ','_')+'.json') game.add_menu_entry('main',Utils.white_bright('+'),'Save this Board and create a new one') game.add_menu_entry('main',Utils.white_bright('L'),'Save this Board and load a new one') game.add_menu_entry('main',Utils.white_bright('m'),'Switch menu display mode between full or hidden') game.add_menu_entry('main',Utils.white_bright('Q'),'Quit the editor') game.add_menu_entry('board',None,'=== Board ===') game.add_menu_entry('board','1','Change '+Utils.white_bright('width')+' (only sizing up)') game.add_menu_entry('board','2','Change '+Utils.white_bright('height')+' (only sizing up)') game.add_menu_entry('board','3','Change '+Utils.white_bright('name'))
# The riddle game game.clear_screen() print(nice_npc.model + Utils.cyan_bright( 'YEAAAH RIDDLE TIME!! Answer my riddle and you ' 'will be awarded an awesome treasure!')) riddle = random.choice(uniriddles) print(nice_npc.model + Utils.magenta_bright(riddle['q'])) answer = input('And your answer is? ') match_count = 0 for k in riddle['k']: if k.lower() in answer.lower(): match_count += 1 if len(riddle['k']) == match_count: print( nice_npc.model + Utils.green_bright( 'You got it!! Congratulations! Here is your prize: ' + Sprites.RAINBOW + ' Rainbow Prize!', ), ) game.player.inventory.add_item( Treasure(model=Sprites.RAINBOW, value=1000, name='Rainbow Prize', type='good_prize'), ) else: print(nice_npc.model + Utils.red_bright('WRONG! You still get a prize... ' + sprite_npc2 + ' a nice looser poop!')) print(nice_npc.model + Utils.cyan_bright( f" by the way, the answer is: {riddle['a']}")) game.player.inventory.add_item( Treasure(model=sprite_npc2, value=-1000,
# On that board the player starts at the center lvl2 = Board(ui_borders=Utils.MAGENTA_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[5, 5]) # And on that board the player starts at the bottom right corner lvl3 = Board(ui_borders=Utils.RED_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[9, 9]) # Now let's create a game object. mygame = Game(name='demo') # And a Player nazbrok = Player(name='Nazbrok', model=Utils.green_bright("¤¤")) # Now add the boards to the game so the Game object can manage them # the parameters of add_board() are a level number and a board. mygame.add_board(1, lvl1) mygame.add_board(2, lvl2) mygame.add_board(3, lvl3) # Now we also want our player to be managed by the game mygame.player = nazbrok # Now let's show a clean screen to our player mygame.clear_screen() # We haven't place nazbrok on any board, but that's ok because we are going # to use Game to manage the starting position of our player
def title_screen(g): global logo, current_state, term_res menu_index = 0 key = None while current_state == "title": g.clear_screen() for logo_line in logo: print(logo_line, end="\r") print("\r") print( Utils.blue(f"{' '*int(term_res/2-10)}Welcome {g.player.name}!\r")) for i in range(0, len(title_screen_menu)): if i == menu_index: print( Utils.green_bright( f"{' '*int(term_res/2-10)}{menu_indicator_left}" f"{title_screen_menu[i]}{menu_indicator_right}\r")) else: print(f" {' '*int(term_res/2-10)}{title_screen_menu[i]}\r") key = Utils.get_key() if key == Utils.key.DOWN: menu_index += 1 if menu_index >= len(title_screen_menu): menu_index = 0 elif key == Utils.key.UP: menu_index -= 1 if menu_index < 0: menu_index = len(title_screen_menu) - 1 elif key == Utils.key.ENTER: if menu_index == 0: g.clear_screen() print(term.bold_underline_green("How to play")) print( "\nThe arrow " + term.bold_underline("(\u2190/\u2191/\u2193/\u2192)") + " keys move the panda.\n\n" + "The " + term.bold_underline("p") + " key, pause the game.\n\n" "The " + term.bold_underline("space") + " key is for jump. You can move while jumping.\n\n" + term.bold_underline("w(z)/a(q)/s/d") + " keys are for shooting seeds that sprouts trees.\n" " Sprouted trees can be used as platforms but:\n" " - You can only have 2 trees at the same time.\n" " - Shooting a seed cost you 3 secondes of time!\n" "\nRunning forward earn you some time (depending on difficulty).\n" "\nYour goal is to reach the end of a level as quickly as " "possible without falling into radioactive wastes.\n" "If you do fall into the radioactive wastes, the game will revive " "you up the nearest safe platform. You can move during that time.\n" "It is up to you to try your luck and trick the game or respawn " "safely. You have 3 lives to complete your run.\n" "\nAt the end of a level look for the portal to the next level. " "It looks like a cyclone: " + Graphics.Sprites.CYCLONE + "\n" "\nTo increase your score, just move forward! The higher the level" " the higher the score. Difficulty also inscrease as you earn less" " time.\n" "\nOh... there's also treasures that gives you time and/or points " "and traps that takes times or score (or your life...)\n" "\n\nGOOD LUCK PANDA!!\n\n" + Graphics.Sprites.WARNING + " This game relies on emojis for its " "user interface. If you don't see a panda face between the " "parenthesis (" + Graphics.Sprites.PANDA + "), it means that your terminal fonts do NOT support " "emojis. This game won't display correctly. Try other fonts.\n\n" ) input("Press ENTER when done reading.") elif menu_index == 1: current_state = "game" # We need to start over so back to level 1 g.current_level = 0 # Let's make sure the player is correctly placed by the engine g.player.pos = [None, None] # And lives, score and timer are reset g.timer = 60 g.score = 0 g.player.remaining_lives = 3 # Then reset the player model in case he died g.player.model = (bg_color + Graphics.Sprites.PANDA + Graphics.Style.RESET_ALL) g.clear_screen() change_level([g]) elif menu_index == 2: g.clear_screen() print( Utils.blue(f"{' '*int(term_res/2-10)}" + term.bold_underline("Hall of fame") + "\r")) ranking = 1 for el in sorted(g.config("settings")["hiscores"], reverse=True, key=lambda x: x[1]): extra = "" if ranking == 1: extra = Graphics.Sprites.FIRST_PLACE_MEDAL elif ranking == 2: extra = Graphics.Sprites.SECOND_PLACE_MEDAL elif ranking == 3: extra = Graphics.Sprites.THIRD_PLACE_MEDAL print(f"{' '*int(term_res/2-10)}{el[0]} : {el[1]} {extra}") ranking += 1 input("\n\nHit the ENTER key to return to the main menu.\n") elif menu_index == 3: # Switch resolution if term_res == 80: term_res = 140 else: term_res = 80 load_logo() g.partial_display_viewport = [10, int(term_res / 4)] elif menu_index == 4: g.player.name = input( "\n\nPlease enter your name (it will be used for high scores)> " ) g.config("settings")["player_name"] = g.player.name elif menu_index == (len(title_screen_menu) - 1): # Quit current_state = "eop"
elif key == Utils.key.SPACE: if g.player.dy == 0 and len(g.neighbors(1, g.player)) > 0: # Jump # Start with sound jump_wave_obj.play() g.player.max_y = g.player.pos[0] - 3 g.player.dy = 1 elif key == "X": g.stop() break elif key in "awsdzq": projectile = Projectile( name="treeball", direction=Constants.RIGHT, range=2, model=Utils.green_bright(bg_color + " *" + Utils.Style.RESET_ALL), hit_model=bg_color + Graphics.Sprites.DECIDUOUS_TREE + Utils.Style.RESET_ALL, hit_callback=sprout, ) row = g.player.pos[0] column = g.player.pos[1] + 1 if key == "w" or key == "z": projectile.set_direction(Constants.UP) row = g.player.pos[0] - 1 column = g.player.pos[1] elif key == "s": projectile.set_direction(Constants.DOWN) row = g.player.pos[0] + 1 column = g.player.pos[1] elif key == "a" or key == "q":
def create_wizard(): global game key = "" while True: game.clear_screen() print(Utils.green_bright("\t\tObject creation wizard")) print("What do you want to create: a NPC or a structure?") print("1 - NPC (Non Playable Character)") print("2 - Structure (Wall, Door, Treasure, Portal, Trees, etc.)") key = Utils.get_key() if key == "1" or key == "2": break if key == "1": game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.cyan_bright("NPC")) new_object = NPC() print("First give a name to your NPC. Default value: " + new_object.name) r = str(input("(Enter name)> ")) if len(r) > 0: new_object.name = r print( "Then give it a type. A type is important as it allows grouping.\n" "Type is a string. Default value: " + new_object.type) r = str(input("(Enter type)> ")) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.cyan_bright("NPC") + f" - {new_object.model}") print("We now needs to go through some basic statistics. " "You can decide to go with default by simply hitting " 'the "Enter" key.') r = input_digit(f"Number of cell crossed in one turn. " f"Default: {new_object.step}(type: int) > ") if len(r) > 0: new_object.step = int(r) else: # If it's 0 it means it's going to be a static NPC so to prevent # python to pass some random pre-initialized default, we explicitly # set the Actuator to a static one new_object.actuator = SimpleActuators.RandomActuator(moveset=[]) r = input_digit(f"Max HP (Health Points). " f"Default: {new_object.max_hp}(type: int) > ") if len(r) > 0: new_object.max_hp = int(r) new_object.hp = new_object.max_hp r = input_digit(f"Max MP (Mana Points). " f"Default: {new_object.max_mp}(type: int) > ") if len(r) > 0: new_object.max_mp = int(r) new_object.mp = new_object.max_mp r = input_digit( f"Remaining lives (it is advised to set that to 1 for a " f"standard NPC). " f"Default: {new_object.remaining_lives}(type: int) > ") if len(r) > 0: new_object.remaining_lives = int(r) r = input_digit(f"AP (Attack Power). " f"Default: {new_object.attack_power}(type: int) > ") if len(r) > 0: new_object.attack_power = int(r) r = input_digit(f"DP (Defense Power). " f"Default: {new_object.defense_power}(type: int) > ") if len(r) > 0: new_object.defense_power = int(r) r = input_digit( f"Strength. Default: {new_object.strength}(type: int) > ") if len(r) > 0: new_object.strength = int(r) r = input_digit( f"Intelligence. Default: {new_object.intelligence}(type: int) > ") if len(r) > 0: new_object.intelligence = int(r) r = input_digit( f"Agility. Default: {new_object.agility}(type: int) > ") if len(r) > 0: new_object.agility = int(r) game.clear_screen() print("We now need to give some life to that NPC. " "What kind of movement should it have:") print("1 - Randomly chosen from a preset of directions") print("2 - Following a predetermined path") print("3 - Following a predetermined path back and forth") print( "4 - Automatically finding it's way from one point to another (no" " pre-determined path, you will set the points on the map).") r = Utils.get_key() if r == "1": new_object.actuator = SimpleActuators.RandomActuator(moveset=[]) print("Random it is! Now choose from which preset " "of movements should we give it:") print("1 - UP,DOWN,LEFT, RIGHT") print("2 - UP,DOWN") print("3 - LEFT, RIGHT") print("4 - UP,DOWN,LEFT, RIGHT + all DIAGONALES") print("5 - DIAGONALES (DIAG UP LEFT, DIAG UP RIGHT, etc.) " "but NO straight UP, DOWN, LEFT and RIGHT") print("6 - No movement") r = Utils.get_key() if r == "1": new_object.actuator.moveset = [ Constants.UP, Constants.DOWN, Constants.LEFT, Constants.RIGHT, ] elif r == "2": new_object.actuator.moveset = [Constants.UP, Constants.DOWN] elif r == "3": new_object.actuator.moveset = [Constants.RIGHT, Constants.LEFT] elif r == "4": new_object.actuator.moveset = [ Constants.UP, Constants.DOWN, Constants.LEFT, Constants.RIGHT, Constants.DLDOWN, Constants.DLUP, Constants.DRDOWN, Constants.DRUP, ] elif r == "5": new_object.actuator.moveset = [ Constants.DLDOWN, Constants.DLUP, Constants.DRDOWN, Constants.DRUP, ] elif r == "6": new_object.actuator.moveset = [] else: Utils.warn( f'"{r}" is not a valid choice. Movement set is now empty.') new_object.actuator.moveset = [] elif r == "2" or r == "3": if r == "2": new_object.actuator = SimpleActuators.PathActuator(path=[]) elif r == "3": new_object.actuator = SimpleActuators.PatrolActuator(path=[]) print("Great, so what path this NPC should take:") print("1 - UP/DOWN patrol") print("2 - DOWN/UP patrol") print("3 - LEFT/RIGHT patrol") print("4 - RIGHT/LEFT patrol") print("5 - Circle patrol: LEFT, DOWN, RIGHT, UP") print("6 - Circle patrol: LEFT, UP, RIGHT, DOWN") print("7 - Circle patrol: RIGHT, DOWN, LEFT, UP") print("8 - Circle patrol: RIGHT, UP, LEFT, DOWN") print("9 - Write your own path") r = Utils.get_key() if r == "1": print("How many steps should the NPC go in one direction " "before turning back ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += ([ Constants.UP for i in range(0, r, 1) ], ) new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == "2": print("How many steps should the NPC go in one " "direction before turning back ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == "3": print("How many steps should the NPC go in one " "direction before turning back ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] elif r == "3": print("How many steps should the NPC go in one direction " "before turning back ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] elif r == "4": print("How many steps should the NPC go in one " "direction before turning back ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == "5": print("How many steps should the NPC go in EACH " "direction before changing ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == "6": print("How many steps should the NPC go in EACH " "direction before changing ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == "7": print("How many steps should the NPC go in EACH " "direction before changing ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] elif r == "8": print("How many steps should the NPC go in EACH direction " "before changing ?") r = int(input_digit("(please enter an integer)> ")) new_object.actuator.path += [ Constants.RIGHT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.UP for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.LEFT for i in range(0, r, 1) ] new_object.actuator.path += [ Constants.DOWN for i in range(0, r, 1) ] elif r == "9": print("Write your own path using only words from this list: " "UP, DOWN, LEFT, RIGHT, DLDOWN, DLUP, DRDOWN, DRUP.") print("Each direction has to be separated by a coma.") r = str(input("Write your path: ")).upper() new_object.actuator.path = r.split(",") else: Utils.warn(f'"{r}" is not a valid choice. Path is now empty.') new_object.actuator.path = [] elif r == "4": new_object.actuator = AdvancedActuators.PathFinder( parent=new_object, circle_waypoints=True) print( "Do you want the NPC to go through your way points once and stop or" " to cycle through all of them infinitely ?") print("1 - Cycle once") print("2 - Cycle infinitely (default value)") r = Utils.get_key() if r == "1": new_object.actuator.circle_waypoints = False return new_object elif key == "2": while True: game.clear_screen() print( Utils.green_bright("\t\tObject creation wizard: ") + Utils.magenta_bright("Structure")) print("What kind of structure do you want to create:") print( "1 - A wall like structure (an object that cannot be picked-up " "and is not overlappable). Ex: walls, trees, non moving " "elephant (try to go through an elephant or to pick it up " "in your backpack...)") print("2 - A door (player and/or NPC can go through)") print("3 - A treasure (can be picked up, take space in the " "inventory, give points to the player)") print("4 - A generic object (you can set the properties to " "make it pickable or overlappable)") print("5 - A generic actionable object (to make portals, heart " "to replenish life, etc.)") key = Utils.get_key() new_object = None if key == "1": new_object = Structures.Wall() new_object.name = str(uuid.uuid1()) new_object.model = model_picker() break elif key == "2": new_object = Structures.Door() new_object.name = str(uuid.uuid1()) new_object.model = model_picker() break elif key == "3": new_object = Structures.Treasure() print("First give a name to your Treasure. Default value: " + new_object.name) r = str(input("(Enter name)> ")) if len(r) > 0: new_object.name = r print("Then give it a type. A type is important as it allows " "grouping (in this case probably in the inventory).\n" "Type is a string. Default value: " + new_object.type) r = str(input("(Enter type)> ")) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() break elif key == "4" or key == "5": if key == "4": new_object = Structures.GenericStructure() else: new_object = Structures.GenericActionableStructure() new_object.set_overlappable(False) new_object.set_pickable(False) print("First give a name to your structure. Default value: " + new_object.name) r = str(input("(Enter name)> ")) if len(r) > 0: new_object.name = r print( "Then give it a type. \nType is a string. Default value: " + new_object.type) r = str(input("(Enter type)> ")) if len(r) > 0: new_object.type = r print("Now we need a model. Default value: " + new_object.model) input('Hit "Enter" when you are ready to choose a model.') new_object.model = model_picker() print("Is this object pickable? (can it be picked up " "by the player)?") print("0 - No") print("1 - Yes") r = Utils.get_key() if r == "1": new_object.set_pickable(True) print("Is this object overlappable? (can it be walked " "over by player?") print("0 - No") print("1 - Yes") r = Utils.get_key() if r == "1": new_object.set_overlappable(True) break return new_object # Placeholder return BoardItemVoid()
i = 0 for sp in dir(Sprites): if not sp.startswith("__"): game.add_menu_entry("graphics_sprites", str(i), getattr(Sprites, sp), getattr(Sprites, sp)) i += 1 game.add_menu_entry( "main", None, "\n=== Menu (" + game.config("settings")["menu_mode"] + ") ===") game.add_menu_entry("main", Utils.white_bright("Space"), "Switch between edit/delete mode") game.add_menu_entry( "main", Utils.white_bright("0 to 9"), Utils.green_bright("Select") + " an item in history to be the current item", ) game.add_menu_entry( "main", Utils.white_bright("\u2190/\u2191/\u2193/\u2192"), "Move cursor Left/Up/Down/Right", ) game.add_menu_entry( "main", Utils.white_bright("j/i/k/l"), Utils.green_bright("Place") + " the current item and then move cursor Left/Up/Down/Right", ) game.add_menu_entry( "main",