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 generate_trap(b, row, column): # Here we just take a chance and put a trap here. # but we should actually explore the rest of the column for other suitable place if b.available_traps > 0: chance = int(b.max_traps_number / b.size[0] * 100) if random.randint(0, 100) >= 100 - chance: if random.choice([True, False]): trap = Wall( model=bg_color + traps_color + Graphics.Blocks.QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT + Graphics.Blocks.QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT + Graphics.Style.RESET_ALL, type="trap.hfire", ) trap.fire_timer = random.uniform(1.0, 4.0) b.place_item(trap, row, column) if isinstance(b.item(row, column - 1), BoardItemVoid): trap.fdir = Constants.LEFT else: trap.fdir = Constants.RIGHT else: trap = Wall( model=bg_color + Utils.red_bright( Graphics.Blocks. QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT_AND_LOWER_RIGHT # noqa E501 + Graphics.Blocks. QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT # noqa E501 ) + Graphics.Style.RESET_ALL, type="trap.vfire", ) trap.fire_timer = random.uniform(2.0, 6.0) b.place_item(trap, row, column) trap.fdir = Constants.UP b.available_traps -= 1
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')
current_file = e['data'] game.update_menu_entry( 'main', Utils.white_bright('S'), f'Save the current Board to {current_file}') current_menu = 'main' elif key == 'B': current_menu = 'main' # Print the screen and interface game.clear_screen() if current_menu == 'main' or current_menu == 'board': print(Utils.white_bright('Current mode: '), end='') if edit_mode: print(Utils.green_bright("EDIT"), end='') else: print(Utils.red_bright('DELETE'), end='') print( f' | Board: {game.current_board().name} - {game.current_board().size} | Cursor @ {game.player.pos}' ) game.display_board() if len(object_history) > 10: del (object_history[0]) if current_menu == 'main': print('Item history:') cnt = 0 for o in object_history: print(f"{cnt}: {o.model}", end=' ') cnt += 1 print('') print(f'Current item: {current_object.model}') if not (current_menu == 'main' and menu_mode == 'hidden'):
# 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.")
if key == "Q": break elif key == "1": viewport = [10, 10] g.partial_display_viewport = viewport elif key == "2": viewport = [15, 30] g.partial_display_viewport = viewport elif key == "3": viewport = [20, 20] g.partial_display_viewport = viewport if key == " ": if g.player.mp >= 4: fireball = Projectile( name="fireball", model=Utils.red_bright(black_circle), hit_model=Sprites.EXPLOSION, ) fireball.animation = Animation( auto_replay=True, animated_object=fireball, refresh_screen=None, display_time=0.5, ) fireball.animation.add_frame(Utils.red_bright(black_circle)) fireball.animation.add_frame(Utils.red_bright(circle_jot)) fireball.range = 7 fireball.set_direction(Constants.RIGHT) g.add_projectile(1, fireball, g.player.pos[0], g.player.pos[1] + 1) g.player.mp -= 4
import examples_includes # noqa: F401 # First import the Utils module import gamelib.Utils as Utils # Then get creative! # you directly print colored messages: print(Utils.magenta_bright("This is a rather flashy magenta...")) # Each color function has 3 variations : regular, dim and bright print(Utils.yellow_dim("This is dim.")) print(Utils.yellow("This is regular.")) print(Utils.yellow_bright("This is bright.")) # Now, the color functions are just that: functions. So you can store the # results in a variable and use them: blue = Utils.blue_bright("blue") white = Utils.white_bright("white") red = Utils.red_bright("red") print(f"France's flag is {blue} {white} {red}!")
Treasure, GenericStructure, GenericActionableStructure, ) import gamelib.Constants as cst from gamelib.Actuators.SimpleActuators import PathActuator import gamelib.Utils as Utils import gamelib.Sprites as Sprites import time import sys import random sprite_mode = 'nosprite' sprite_player = { 'left': Utils.red_bright('-|'), 'right': Utils.red_bright('|-'), } sprite_npc = None sprite_npc2 = None sprite_portal = None sprite_treasure = None sprite_treasure2 = None sprite_tree = None sprite_wall = None sprite_heart = None sprite_heart_minor = None # The following code is used to switch rendering between # emojis enabled terminal and the others. # Use 'nosprite' if you see unicode codes displayed in your terminal.
previous_level = None refresh_screen() notifications.clear() g.actuate_npcs(g.current_level) # Here we do everything related to the first level. if g.current_level == 1: whale_behavior() portal_fairy_behavior() # Now, let's take care of the case where player's life is down to zero or worst. if g.player.hp <= 0: # First, does he have a Scroll of Wisdom. If yes we save him and warn him that next time he is dead. if len(g.player.inventory.search("Scroll of Wisdom")) > 0: # To do so we set the HP back to the maximum g.player.hp = g.player.max_hp # Warn the player print( Utils.red_bright('You have been saved by the Scroll of Wisdom, be careful next time you will die!') ) # And consume the scroll in the process g.player.inventory.delete_item("Scroll of Wisdom") else: # If he doesn't, well... Death is the sentence and that's game over. g.clear_screen() Utils.print_white_on_red(f"\n\n\n\t{g.player.name} is dead!\n\t ** Game over ** \n\n") g.change_level(999) g.display_board() break # Finally if the amount of turn left in level 2 is 0 we exit with a message if level_2_turns_left == 0: g.clear_screen() print_animated(f"{Sprites.UNICORN_FACE}: Congratulations Mighty Wizard!\n{Sprites.UNICORN_FACE}: The whales are happy and the sheep are patrolling!\n{Sprites.UNICORN_FACE}: You also got {Utils.green_bright(str(g.player.inventory.value()+(g.player.hp*100)))} points!\n{Sprites.UNICORN_FACE}: Try to do even better next time.\n\n{Sprites.UNICORN_FACE}: Thank you for playing!\n") break key = Utils.get_key()
g.actuate_npcs(g.current_level) # Here we do everything related to the first level. if g.current_level == 1: whale_behavior() portal_fairy_behavior() # Now, let's take care of the case where player's life is down to zero or worst. if g.player.hp <= 0: # First, does he have a Scroll of Wisdom. If yes we save him and warn him that # next time he is dead. if len(g.player.inventory.search("Scroll of Wisdom")) > 0: # To do so we set the HP back to the maximum g.player.hp = g.player.max_hp # Warn the player print( Utils.red_bright( "You have been saved by the Scroll of Wisdom, be careful next time" " you will die!")) # And consume the scroll in the process g.player.inventory.delete_item("Scroll of Wisdom") else: # If he doesn't, well... Death is the sentence and that's game over. g.clear_screen() Utils.print_white_on_red( f"\n\n\n\t{g.player.name} is dead!\n\t ** Game over ** \n\n" ) g.change_level(999) g.display_board() break # Finally if the amount of turn left in level 2 is 0 we exit with a message if level_2_turns_left == 0: g.clear_screen()
import examples_includes # First import the Utils module import gamelib.Utils as Utils # Then get creative! # you directly print colored messages: print("France flag is "+Utils.blue_bright('blue ')+Utils.white_bright('white ')+Utils.red_bright('red')+"!") # Each color function has 3 variations : regular, dim and bright print( Utils.yellow_dim('This is dim.')+Utils.yellow(' This is regular.')+Utils.yellow_bright(' This is bright.') ) # Now, the color functions are just that: functions. So you can store the results in a variable and use them: flashymagy = Utils.magenta_bright('This is a rather flashy magenta...') print('Now that is a colored message in a variable: '+flashymagy)
# Utils.debug(f"Setting directory to: {directory}") if os.path.exists(directory): if default_map_dir is None: default_map_dir = directory 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): ")
def redraw_screen(): global g global terminal global current_spell_template g.clear_screen() nb_blocks_mp = int((g.player.mp / g.player.max_mp) * 20) nb_blocks_hp = int((g.player.hp / g.player.max_hp) * 20) print(f"HP |{Graphics.RED_RECT * nb_blocks_hp}" f"{Graphics.BLACK_RECT * (20 - nb_blocks_hp)}| " f"Mana |{Graphics.BLUE_RECT * nb_blocks_mp}" f"{Graphics.BLACK_RECT * (20 - nb_blocks_mp)}|") print(f"\rLevel: {g.player.level}") print("\r", end="") g.display_board() print(f"Terminal size: {terminal.width}x{terminal.height}") b = g.current_board() with terminal.location(b.size[0] * 2 + 5, 3): print(terminal.bold_underline_green("Enemies")) line = 4 # for o in g.current_board().get_movables(): for o in g.neighbors(current_spell_template.range, g.player): if isinstance(o, NPC): nb_blocks_hp = int((o.hp / o.max_hp) * 20) with terminal.location(terminal.width - 20, line): print(f"{Graphics.GREEN_RECT * nb_blocks_hp}" f"{Graphics.BLACK_RECT * (20 - nb_blocks_hp)}") with terminal.location(terminal.width - 20, line + 1): print(f"{o.name}") line += 2 with terminal.location(b.size[0] * 2 + 5, 12): print(terminal.bold_underline_blue("Spells")) with terminal.location(b.size[0] * 2 + 5, 13): print(terminal.bold("9 - Fireball")) with terminal.location(b.size[0] * 2 + 5, 14): print(terminal.bold("0 - Bolt")) with terminal.location(0, b.size[1] + 6): color_prefix = "" if current_spell_template.name == "fireball": color_prefix = Utils.Fore.BLUE print(color_prefix + Graphics.BoxDrawings.LIGHT_ARC_DOWN_AND_RIGHT + Graphics.BoxDrawings.LIGHT_HORIZONTAL * 3 + Graphics.BoxDrawings.LIGHT_ARC_DOWN_AND_LEFT + "\n\r" + Graphics.BoxDrawings.LIGHT_VERTICAL + Utils.red_bright("-") + color_prefix + Graphics.Sprites.COLLISION + Graphics.BoxDrawings.LIGHT_VERTICAL + "\n\r" + Graphics.BoxDrawings.LIGHT_ARC_UP_AND_RIGHT + Graphics.BoxDrawings.LIGHT_HORIZONTAL + "9" + Graphics.BoxDrawings.LIGHT_HORIZONTAL + Graphics.BoxDrawings.LIGHT_ARC_UP_AND_LEFT + Graphics.Style.RESET_ALL + "\n\r") color_prefix = "" if current_spell_template.name == "zap": color_prefix = Utils.Fore.BLUE with terminal.location(5, b.size[1] + 6): print(color_prefix + Graphics.BoxDrawings.LIGHT_ARC_DOWN_AND_RIGHT + Graphics.BoxDrawings.LIGHT_HORIZONTAL * 3 + Graphics.BoxDrawings.LIGHT_ARC_DOWN_AND_LEFT) with terminal.location(5, b.size[1] + 7): print(color_prefix + Graphics.BoxDrawings.LIGHT_VERTICAL + " " + Graphics.Sprites.HIGH_VOLTAGE + Graphics.BoxDrawings.LIGHT_VERTICAL) with terminal.location(5, b.size[1] + 8): print(color_prefix + Graphics.BoxDrawings.LIGHT_ARC_UP_AND_RIGHT + Graphics.BoxDrawings.LIGHT_HORIZONTAL + "0" + Graphics.BoxDrawings.LIGHT_HORIZONTAL + Graphics.BoxDrawings.LIGHT_ARC_UP_AND_LEFT + Graphics.Style.RESET_ALL + "\n\r")
last_direction = Constants.RIGHT is_fullscreen = False terminal = Terminal() print(terminal.enter_fullscreen) black_circle = "\U000025CF" circle_jot = "\U0000233E" throw_fireball = False _thread.start_new_thread(ui_threaded, ()) # Fireball template fireball_template = Projectile( model=Utils.red_bright(f"~{black_circle}"), name="fireball", range=7, hit_model=Graphics.Sprites.COLLISION, hit_animation=None, hit_callback=fireball_callback, step=1, is_aoe=True, aoe_radius=1, ) zap_template = Projectile( model=Utils.yellow_bright("\U00002301\U00002301"), name="zap", range=8, hit_model=Graphics.Sprites.HIGH_VOLTAGE, hit_callback=zap_callback,
import examples_includes # First import the Utils module import gamelib.Utils as Utils # Then get creative! # you directly print colored messages: print(Utils.magenta_bright('This is a rather flashy magenta...')) # Each color function has 3 variations : regular, dim and bright print(Utils.yellow_dim('This is dim.')) print(Utils.yellow('This is regular.')) print(Utils.yellow_bright('This is bright.')) # Now, the color functions are just that: functions. So you can store the # results in a variable and use them: blue = Utils.blue_bright('blue') white = Utils.white_bright('white') red = Utils.red_bright('red') print(f"France's flag is {blue} {white} {red}!")