コード例 #1
0
ファイル: suparex.py プロジェクト: A-Productions/pygamelib
def make_platform(b, row, column):
    psize = random.randint(2, 10)
    plateform = []
    tmp_game = Game()
    # Only because Game needs it, we don't care.
    tmp_game.player = Player()
    tmp_game.add_board(0, b)
    tmp_game.change_level(0)
    # print(
    #     f"[d] make_platform at {row}, {column}, psize is {psize} column will be "
    #     f"between {column} and {column + psize + 1}"
    # )
    get_up = 0
    # for i in range(column, column + psize + 1):
    for i in range(column - psize - 1, column):
        if i >= b.size[0]:
            break
        if not isinstance(b.item(row, i), BoardItemVoid):
            break
        if i in b.visited_columns:
            break
        # Check if we have other platforms around.
        # If yes moving the platform up.
        if get_up < 3:
            for e in tmp_game.neighbors(2, Door(pos=[row, i])):
                if e.type == "ground":
                    get_up = 3
                    break
        if get_up < 4:
            for e in tmp_game.neighbors(1, Door(pos=[row, i])):
                if e.type == "ground":
                    get_up = 4
                    break
        m = block_color() + "  " + Utils.Style.RESET_ALL
        plateform.append([Wall(model=m, type="platform"), row, i])
    for i in plateform:
        b.place_item(i[0], i[1] - get_up, i[2])
        if random.choice([True, False]):
            generate_treasure(b, i[1] - get_up - 1, i[2])
        else:
            generate_trap(b, i[1] - get_up - 1, i[2])
        b.visited_columns.append(i[2])
コード例 #2
0
            random_board.place_item(Door(model=Sprites.DOOR), r, c)
        elif dg.dungeon[r][c].get_ch() == ".":
            potential_starting_position.append([r, c])
random_board.player_starting_position = choice(potential_starting_position)
print("done")
print(f"starting position chosen: {random_board.player_starting_position}")

# dg.print_map()
# random_board.display()
input("New random dungeon generated. Next?")

g = Game()
g.enable_partial_display = True
# g.load_board('/home/arnaud/Code/Games/hgl-editor/Large_Dungeon.json', 1)
g.player = Player(model=Sprites.MAGE)
g.add_board(1, random_board)
g.change_level(1)

key = None
viewport = [10, 10]
g.partial_display_viewport = viewport
while True:
    if key == "Q":
        break
    elif key == "S":
        g.save_board(1, f"random-dungeon-{randrange(1000,9999)}.json")
    elif key == "1":
        viewport = [10, 10]
        g.partial_display_viewport = viewport
    elif key == "2":
        viewport = [15, 30]
コード例 #3
0
    print("Mana [" + Utils.BLUE_RECT * nb_blocks + Utils.BLACK_RECT *
          (20 - nb_blocks) + "]")
    g.display_board()
    # manage_fireballs()


b = Board(
    ui_borders=Utils.WHITE_SQUARE,
    ui_board_void_cell=Utils.BLACK_SQUARE,
    size=[20, 20],
    player_starting_position=[5, 5],
)
wall = Wall(model=Sprites.WALL)
b.place_item(wall, 1, 6)
g = Game()
g.add_board(1, b)
g.player = Player(model=Sprites.MAGE, name="The Maje")
g.player.mp = 20
g.player.max_mp = 20
g.change_level(1)
key = None

black_circle = "-\U000025CF"
circle_jot = "-\U0000233E"

throw_fireball = False
projectile = Projectile()

while True:
    if key == "Q":
        break
コード例 #4
0
ファイル: 02-move-player.py プロジェクト: kaozdl/hac-game-lib
import time

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)

mygame.change_level(1)

key = None
# Main game loop
while True:
    mygame.clear_screen()
    mygame.display_board()

    # Key handler
    if key == 'q':
        print(Utils.yellow_bright("Good bye and thank you for playing!"))
        break
    elif key == 'a':
コード例 #5
0
    ui_board_void_cell=Utils.BLACK_SQUARE,
    player_starting_position=[0, 0],
)

game = Game(name='HAC Game')
p = Player(model=sprite_player['right'], name='Nazbrok')
npc1 = NPC(model=sprite_npc, name='Bad guy 1', step=1)
# Test of the PathActuator
npc1.actuator = PathActuator(path=[
    cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.RIGHT,
    cst.RIGHT, cst.RIGHT, cst.RIGHT, cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN,
    cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN, cst.LEFT, cst.LEFT, cst.LEFT,
    cst.LEFT
])

game.add_board(1, lvl1)
game.add_board(2, lvl2)

t = Treasure(model=sprite_treasure, name='Cool treasure', type='gem')
money_bag = Treasure(model=sprite_treasure2, name='money', value=20)

tree = GenericStructure(model=sprite_tree)
tree.set_overlappable(False)
tree.set_pickable(False)

portal2 = GenericActionableStructure(model=sprite_portal)
portal2.set_overlappable(False)
portal2.action = change_current_level
portal2.action_parameters = [game, 2]

portal1 = GenericActionableStructure(model=sprite_portal)
コード例 #6
0
             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
# First let's display nazbrok's position
Utils.debug(f"Nazbrok is at position ({nazbrok.pos[0]}, {nazbrok.pos[0]})"
            f" -- BEFORE changing level")
# Now the only thing we need is to change level
コード例 #7
0
ファイル: 99-final-game.py プロジェクト: kaozdl/hac-game-lib
    g.current_board().clear_cell(g.player.pos[0],g.player.pos[1]) 
    g.current_board().place_item(g.player,row,column)

# Load the board as level 1
b = g.load_board(level_1,1)
# The game over screen is going to be level 999. There is no reason for that, it is just a convention as I don't think that this game is going to have more than 998 levels.
g.load_board(game_over,999)
# And help 998
g.load_board(help_menu,998)

# Now let's build a random generated bonus stage!
# First we need a board. Same size 50x30 but the player starting position is random.
player_starting_row = random.randint(0,29)
player_starting_column = random.randint(0,49)
bonus_board = Board(name='Bonus Stage', size=[50,30], player_starting_position=[player_starting_row,player_starting_column], ui_borders=Utils.YELLOW_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE)
g.add_board(2,bonus_board)
# To place the treasures we have 30*50 = 1500 cells available on the map, minus the player it brings the total to 1499.
# Now let's randomely place 300 money bags. Each bag increase the score by 100.
for k in range(0,300):
    row = None
    column = None
    retry = 0
    while True :
        if row == None:
            row = random.randint(0,bonus_board.size[1]-1)
        if column == None:
            column = random.randint(0,bonus_board.size[0]-1)
        # print(f"Game.add_npc() finding a position for NPC {npc.name} trying ({x},{y})")
        if isinstance(bonus_board.item(row,column), BoardItemVoid):
            break
        elif retry > 20:
コード例 #8
0
ファイル: hgl-editor.py プロジェクト: A-Productions/pygamelib
# Main program
game = Game()
current_file = ""
game.player = Player(model="[]")
key = "None"
current_object = BoardItemVoid(model="None")
current_object_instance = BoardItemVoid(model="None")
object_history = []
viewport_board = Board(
    name="Viewport testing board",
    size=[viewport_width * 2, viewport_height * 2],
    ui_borders=Utils.GREEN_SQUARE,
    ui_board_void_cell=Utils.RED_SQUARE,
)
game.add_board(2, viewport_board)
current_menu = "main"
while True:
    game.clear_screen()
    print(
        Utils.cyan_bright("HAC-GAME-LIB - EDITOR v" +
                          Constants.HAC_GAME_LIB_VERSION))
    # Create config_dir if not exist and populate it with a directories.json file.
    if (not os.path.exists(config_dir) or not os.path.isdir(config_dir)
            or not os.path.exists(base_config_dir)
            or not os.path.isdir(base_config_dir)
            or not os.path.isdir(editor_config_dir) or not os.path.exists(
                os.path.join(editor_config_dir, "settings.json"))):
        first_use()
    else:
        game.load_config(os.path.join(editor_config_dir, "settings.json"),