elif key == "l" and not edit_mode: clear_and_go(Constants.RIGHT) elif key == ' ': switch_edit_mode() elif key in '1234567890' and current_menu == 'main': if edit_mode: if len(object_history) > int(key): o = object_history[int(key)] to_history(current_object) current_object = o else: if len(object_history) > int(key): del (object_history[int(key)]) is_modified = True elif key == 'P': game.current_board().player_starting_position = game.player.pos is_modified = True info_messages.append( f'New player starting position set at {game.player.pos}') elif key == 'p': current_menu = 'board' elif key == 'c': to_history(current_object) current_object = create_wizard() to_history(current_object) elif key == '+': save_current_board() create_board_wizard() elif key == 'L': save_current_board() current_menu = "boards_list"
g.player = Player(name='The Mighty Wizard', model=Sprites.MAGE) g.change_level(1) g.actuate_npcs(1) pf = PathFinder(game=g, actuated_object=g.player) pf.add_waypoint(dest_row, dest_col) pf.add_waypoint(24, 24) pf.add_waypoint(21, 40) pf.circle_waypoints = True pf.set_destination(dest_row, dest_col) blocker = NPC(model=Sprites.SKULL) g.current_board().place_item(blocker, 20, 1) wall = Wall(model=Sprites.WALL) wall.animation = Animation(animated_object=wall) wall.animation.add_frame(Sprites.BANKNOTE_DOLLARS) wall.animation.add_frame(Sprites.BANKNOTE_EUROS) wall.animation.add_frame(Sprites.BANKNOTE_WINGS) g.current_board().place_item(wall, 5, 25) # 43,28 43,34 39,34 39,40 44,40 44,28 patroller = NPC(model=Sprites.ALIEN, name='patroller') patroller.actuator = PathFinder(game=g, actuated_object=patroller) g.add_npc(1, patroller, 42, 28) patroller.actuator.set_destination(43, 29) patroller.actuator.add_waypoint(43, 29) patroller.actuator.add_waypoint(43, 34)
g.add_projectile(1, fireball, g.player.pos[0], g.player.pos[1] + 1) g.player.mp -= 4 elif key == Utils.key.UP: g.move_player(Constants.UP, 1) elif key == Utils.key.DOWN: g.move_player(Constants.DOWN, 1) elif key == Utils.key.LEFT: g.move_player(Constants.LEFT, 1) elif key == Utils.key.RIGHT: g.move_player(Constants.RIGHT, 1) redraw_screen() print("Screen just redrawn") g.actuate_npcs(1) g.actuate_projectiles(1) g.animate_items(1) print(f"Player position {g.player.pos}") for f in g.current_board().get_movables(): print(f"{f.name} position {f.pos}") if throw_fireball: print(f"{g.player.model} FIREBALL!!!") throw_fireball = False if g.player.mp < 4: print(f"{g.player.model} I'm all out of mana") if g.player.mp < 20: g.player.mp += 1 else: g.player.mp = 20 key = Utils.get_key()
g = Game() b = g.load_board('hac-maps/kneighbors.json',1) g.player = Player(model=Sprites.FLYING_SAUCER,name='player') g.change_level(1) key = None while True: if key == 'w': g.move_player(Constants.UP,1) elif key == 's': g.move_player(Constants.DOWN,1) elif key == 'a': g.move_player(Constants.LEFT,1) elif key == 'd': g.move_player(Constants.RIGHT,1) elif key == 'q': break g.clear_screen() g.display_board() for i in g.neighbors(1): print(f'Player: {i.name} ({i.pos[0]},{i.pos[1]})') for i in g.neighbors(1, g.current_board().item(7,7) ): print(f'NPC: {i.name} ({i.pos[0]},{i.pos[1]})') key = Utils.get_key()
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')) game.add_menu_entry('board','4','Change '+Utils.white_bright('top')+' border') game.add_menu_entry('board','5','Change '+Utils.white_bright('bottom')+' border') game.add_menu_entry('board','6','Change '+Utils.white_bright('left')+' border') game.add_menu_entry('board','7','Change '+Utils.white_bright('right')+' border') game.add_menu_entry('board','8','Change '+Utils.white_bright('void cell')) game.add_menu_entry('board','0','Go back to the main menu')
pass def activate_portal(params): pass # Create the player object. g.player = Player(name='The Mighty Wizard', model=Sprites.MAGE) g.change_level(1) # Now we need to fix the river (it's missing 2 tiles of water) # First let's move the NPCs so the whales are not replaced by our new tiles. g.actuate_npcs(1) # Now let's place the 2 river tiles (we use the Door object as a shortcut to get a overlapable, restorable item) g.current_board().place_item(Door(model=Utils.BLUE_SQUARE), 0, 26) g.current_board().place_item(Door(model=Utils.BLUE_SQUARE), 11, 0) # Now we need to take care of the explosions. Hide them and set the callback functions. for item in g.current_board().get_immovables(): # Here we need to set the functions that are going to be called when the player touches our hidden traps. if item.type == 'simple_explosion' or item.type == 'mega_explosion': # First let's set our model to the same as the current level's board void cell model. item.model = g.current_board().ui_board_void_cell # Then depending on the type of explosion we use the explosion() function. # This function will be called when the player interact with the GenericActionable object. # explosion() takes 3 parameters: the calling item, a model to use when it's exploded and a damage value to hurt the player. if item.type == 'simple_explosion': item.action = explosion item.action_parameters = [item, Sprites.FIRE, 10]
## https://astro.hyrul.es/guides/hac-game-lib/tutorial-01-the-game-object.html ## ## ## ################################################################################# mygame = Game(name='Demo game') board1 = Board(name='Level 1', ui_borders=Sprites.WALL, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[0, 0]) board2 = Board(name='Level 2', ui_borders=Utils.RED_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[4, 4]) mygame.player = Player(name='DaPlay3r', model=Sprites.UNICORN_FACE) mygame.add_board(1, board1) mygame.add_board(2, board2) count = 0 lvl = 1 while count < 10: mygame.clear_screen() mygame.change_level(lvl) mygame.current_board().display() lvl += 1 if lvl > 2: lvl = 1 time.sleep(2) count += 1
column = None retry += 1 bonus_board.place_item(Treasure(model=Sprites.CROWN, value=5000, name=f'crown_{k}'), row, column) # Create the player object. g.player = Player(name='Mighty Wizard',model=Sprites.MAGE) g.change_level(1) introduction_scene() # Now we need to fix the river (it's missing 2 tiles of water) # First let's move the NPCs so the whales are not replaced by our new tiles. g.actuate_npcs(1) # Now let's place the 2 river tiles (we use the Door object as a shortcut to get a overlapable, restorable item) g.current_board().place_item(Door(model=Utils.BLUE_SQUARE),0,26) g.current_board().place_item(Door(model=Utils.BLUE_SQUARE),11,0) # Now we need to take care of the explosions. Hide them and set the callback functions. for item in g.current_board().get_immovables(): # Here we need to set the functions that are going to be called when the player touches our hidden traps. if item.type == 'simple_explosion' or item.type == 'mega_explosion': # First let's set our model to the same as the current level's board void cell model. item.model = g.current_board().ui_board_void_cell # Then depending on the type of explosion we use the explosion() function. # This function will be called when the player interact with the GenericActionable object. # explosion() takes 3 parameters: the calling item, a model to use when it's exploded and a damage value to hurt the player. if item.type == 'simple_explosion': item.action = explosion item.action_parameters = [item,Sprites.FIRE,10]
from gamelib.Characters import Player, Vehicle from gamelib.Game import Game import gamelib.Utils as Utils import gamelib.Constants as Constants g = Game() g.player = Player(model="\u232C") b = Board(size=[80, 50]) mod_right = [["\u25E3", " "], ["\u25A2", "\u25D7"], ["\u25E4", " "]] mod_left = [["\u25E2"], ["\u25D6", "\u25A2"], ["\u25E2"]] mi = Vehicle(model=mod_right) g.add_board(1, b) g.change_level(1) g.current_board().place_item(mi, 20, 20) key = None while True: if key == Utils.key.UP: g.current_board().move(mi, Constants.UP, 1) elif key == Utils.key.DOWN: g.current_board().move(mi, Constants.DOWN, 1) elif key == Utils.key.LEFT: # mi.update_model(mod_left) g.current_board().move(mi, Constants.LEFT, 1) elif key == Utils.key.RIGHT: # mi.update_model(mod_right) g.current_board().move(mi, Constants.RIGHT, 1) elif key == "q":
elif key == "l" and not edit_mode: clear_and_go(Constants.RIGHT) elif key == " ": switch_edit_mode() elif key in "1234567890" and current_menu == "main": if edit_mode: if len(object_history) > int(key): o = object_history[int(key)] to_history(current_object) current_object = o else: if len(object_history) > int(key): del object_history[int(key)] is_modified = True elif key == "P": game.current_board().player_starting_position = game.player.pos is_modified = True info_messages.append( f"New player starting position set at {game.player.pos}") elif key == "p": current_menu = "board" elif key == "V": current_menu = "viewport" game.change_level(2) game.player.model = Utils.RED_SQUARE elif key == "c": to_history(current_object) current_object = create_wizard() to_history(current_object) elif key == "+": save_current_board()
winner[1]) redraw() # input(f'Winner: {winner}') return winner g = Game() # b = g.load_board('/home/arnaud/Code/Games/hgl-editor/TestChasing.json', 1) b = g.load_board("hac-maps/The_Castle.json", 1) g.player = Player(name="The Mighty Wizard", model=Sprites.MAGE) g.change_level(1) guards = [] for item in g.current_board().get_movables(type="guard"): guards.append(item) nm = None key = None chasing = False while nm != Constants.NO_DIR: if g.player.hp <= 0: g.clear_screen() Utils.print_white_on_red("GAME OVER") break r = g.player.pos[0] c = g.player.pos[1] if key == Utils.key.UP: g.move_player(Constants.UP, 1)