def first_use():
    global config_dir
    global editor_config_dir
    global base_config_dir
    global default_map_dir
    global game
    print(
        Utils.yellow_bright("Configuration wizard (fresh install or update)"))
    print(
        "You may see that wizard because hgl-editor was updated with new settings.\n"
        "Please check that everything is fine (your previous values are showned as "
        "default values)\n")
    if not os.path.exists(config_dir):
        os.makedirs(config_dir)
    if not os.path.exists(os.path.join(base_config_dir, "editor", "maps")):
        os.makedirs(os.path.join(base_config_dir, "editor", "maps"))
    if not os.path.exists(editor_config_dir):
        os.makedirs(editor_config_dir)
    print(
        "We need to set up the default directory where we are going to save maps.",
        f"Default is {default_map_dir}",
    )
    new_default = str(input("Default maps directory: "))
    while (not os.path.exists(new_default) or not os.path.isdir(new_default)
           or not os.path.isabs(new_default)) and new_default != "":
        print(
            Utils.red(
                "The path to directory needs to exists and be absolute."))
        new_default = str(input("Default maps directory: "))
    if new_default != "":
        default_map_dir = new_default
    if not os.path.exists(os.path.join(config_dir, "directories.json")):
        with open(os.path.join(config_dir, "directories.json"), "w") as fp:
            fp.write(f'["{default_map_dir}","hac-maps","maps"]')
    if not os.path.exists(os.path.join(editor_config_dir, "settings.json")):
        game.create_config("settings")
        game.config("settings")["directories"] = [
            default_map_dir, "hac-maps", "maps"
        ]
        game.config("settings")["config_file_version"] = 10100
        game.config("settings")["enable_partial_display"] = True
        game.config("settings")["partial_display_viewport"] = [10, 30]
        game.config("settings")["menu_mode"] = "full"
        game.config("settings")["last_used_board_parameters"] = {
            "name": None,
            "width": None,
            "height": None,
        }
        game.config("settings")["object_library"] = []
Exemple #2
0
import gamelib.Constants as Constants

# First let's create a Board that uses squares as delimiters
myboard = Board(
                name='A demo board',
                size=[40,20],
                ui_border_left=Utils.WHITE_SQUARE, # Borders are going to be white squares
                ui_border_right=Utils.WHITE_SQUARE,
                ui_border_top=Utils.WHITE_SQUARE,
                ui_border_bottom=Utils.WHITE_SQUARE,
                ui_board_void_cell=Utils.BLACK_SQUARE, # Cells with nothing inside are going to be black squares
                player_starting_position=[10,20]
                )

# Then create a player 
playerone = Player( model=Utils.yellow_bright('××') )

# Place it on the board
myboard.place_item(playerone, 10,10)

# Now let's display our board
myboard.display()

# And make a short loop that moves the player and display the board 
# WARNING: in real life we would use the Game object to manage the game and the screen

for k in range(1,10,1):
    # Clear screen
    Utils.clear_screen()
    # Print a debug message
    Utils.debug(f'Round {k} player position is ({playerone.pos[0]},{playerone.pos[1]}) -- BEFORE moving')
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':
        # Left
        mygame.move_player(Constants.LEFT, 1)
    elif key == 'd':
        # Right
        mygame.move_player(Constants.RIGHT, 1)
    elif key == 'w':
        # Up
        mygame.move_player(Constants.UP, 1)
    elif key == 's':
        # Down
        mygame.move_player(Constants.DOWN, 1)
    elif key == '3':
        mygame.move_player(Constants.DRDOWN, 1)
Exemple #4
0
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}!")
Exemple #5
0
if sprite_mode == 'sprite':
    # sprite_player = Sprites.SHEEP
    sprite_portal = Sprites.CYCLONE
    sprite_treasure = Sprites.GEM_STONE
    sprite_treasure2 = Sprites.MONEY_BAG
    sprite_tree = Sprites.TREE_PINE
    sprite_wall = Sprites.WALL
    sprite_npc = Sprites.SKULL
    sprite_npc2 = Sprites.POO
    sprite_heart = Sprites.HEART_SPARKLING
    sprite_heart_minor = Sprites.HEART_BLUE
else:
    # sprite_player = Utils.RED_BLUE_SQUARE
    sprite_portal = Utils.CYAN_SQUARE
    sprite_treasure = Utils.YELLOW_RECT + Utils.RED_RECT
    sprite_treasure2 = Utils.yellow_bright('$$')
    sprite_tree = Utils.GREEN_SQUARE
    sprite_wall = Utils.WHITE_SQUARE
    sprite_npc = Utils.magenta_bright("oO")
    sprite_npc2 = Utils.magenta_bright("'&")
    sprite_heart = Utils.red_bright('<3')
    sprite_heart_minor = Utils.blue_bright('<3')


# Here are some functions to manage the game
# This one clear the screen, print the game title, print the player stats,
# display the current board, print the inventory and print the menu.
def refresh_screen(mygame, player, menu):
    mygame.clear_screen()
    # print(Utils.magenta_bright(f"\t\t~+~ Welcome to {mygame.name} ~+~"))
    mygame.display_player_stats()
Exemple #6
0
def ui_threaded(g):
    while g.state != Constants.STOPPED:
        gravity(g)
        refresh_screen(g)
        g.actuate_projectiles(g.current_level)
        sleep(0.1)
        if g.state == Constants.RUNNING:
            g.timer -= 0.1
            for trap in g.current_board().get_immovables(type="trap."):
                # Only actually fire for traps that are on screen or close
                if (trap.pos[1] >
                        g.player.pos[1] + g.partial_display_viewport[1] + 5
                        or trap.pos[1] <
                        g.player.pos[1] - g.partial_display_viewport[1] - 5):
                    continue
                if trap.type == "trap.hfire":
                    trap.fire_timer -= 0.1
                    if trap.fire_timer <= 0.0:
                        proj = Projectile(
                            model=bg_color +
                            Utils.yellow_bright("\U00002301\U00002301") +
                            Graphics.Style.RESET_ALL,
                            name="zap",
                            range=5,
                            hit_model=bg_color +
                            Graphics.Sprites.HIGH_VOLTAGE +
                            Graphics.Style.RESET_ALL,
                            hit_callback=zap_callback,
                        )
                        proj.set_direction(trap.fdir)
                        trap_shoot_wave_obj.play()
                        if trap.fdir == Constants.RIGHT:
                            g.add_projectile(g.current_level, proj,
                                             trap.pos[0], trap.pos[1] + 1)
                        else:
                            g.add_projectile(g.current_level, proj,
                                             trap.pos[0], trap.pos[1] - 1)
                        trap.fire_timer = 1.5
                elif trap.type == "trap.vfire":
                    trap.fire_timer -= 0.1
                    if trap.fire_timer <= 0.0:
                        proj = Projectile(
                            model=bg_color + Graphics.Sprites.BOMB +
                            Graphics.Style.RESET_ALL,
                            name="boom",
                            range=2,
                            hit_model=bg_color + Graphics.Sprites.COLLISION +
                            Graphics.Style.RESET_ALL,
                            hit_callback=boom_callback,
                            is_aoe=True,
                            aoe_radius=1,
                        )
                        proj.set_direction(trap.fdir)
                        trap_shoot_wave_obj.play()
                        # Right now if the player sits on it, it does nothing.
                        g.add_projectile(g.current_level, proj,
                                         trap.pos[0] - 1, trap.pos[1])
                        trap.fire_timer = 2.5
        if g.player.pos[0] == g.current_board().size[1] - 1:
            g.timer = 0.0
        if round(g.timer, 1) <= 0.0:
            g.player.model = bg_color + Graphics.Sprites.SKULL + Utils.Style.RESET_ALL
            g.player.remaining_lives -= 1
            refresh_screen(g)
        if (g.player.pos[0] == g.current_board().size[1] - 1
                and g.player.dy == 0) or round(g.timer, 1) <= 0.0:
            if g.player.remaining_lives == 0:
                g.stop()
                g.config("settings")["hiscores"].append(
                    [g.player.name, g.score])
                if len(g.config("settings")["hiscores"]) > 10:
                    g.config("settings")["hiscores"] = sorted(
                        g.config("settings")["hiscores"],
                        reverse=True,
                        key=lambda x: x[1],
                    )[0:10]
                raise SystemExit()
            else:
                g.current_board().clear_cell(g.player.pos[0], g.player.pos[1])
                potential_respawns = g.neighbors(2, g.player)
                g.player.model = (bg_color + Graphics.Sprites.PANDA +
                                  Graphics.Style.RESET_ALL)
                for o in potential_respawns:
                    if o.type == "platform":
                        g.current_board().place_item(
                            g.player,
                            g.current_board().size[1] - 10, o.pos[1])
                        g.player.max_y = g.current_board().size[1] - 11
                        g.player.dy = 0
                        g.timer = 30 + 10 * g.player.remaining_lives
                        break
        if len(g.obj_stack) > 0:
            new_stack = []
            for o in g.obj_stack:
                if isinstance(g.current_board().item(o.pos[0], o.pos[1]),
                              BoardItemVoid):
                    g.current_board().place_item(o, o.pos[0], o.pos[1])
                    sprouted_trees = g.current_board().get_immovables(
                        type="sprouted_tree")
                    # Some times the game hangs and I wonder if it's not coming from
                    # here. I'm trying to put a hard stop here.
                    hard_stop = 0
                    while (len(g.current_board().get_immovables(
                            type="sprouted_tree")) > 2 and hard_stop < 20):
                        goner = sprouted_trees[0]
                        for i in sprouted_trees:
                            if i.age < goner.age:
                                goner = i
                        g.current_board().clear_cell(goner.pos[0],
                                                     goner.pos[1])
                        hard_stop += 1
                else:
                    new_stack.append(o)
            g.obj_stack = new_stack
        if g.player.inventory.size() > 0:
            for iname in g.player.inventory.items_name():
                item = g.player.inventory.get_item(iname)
                if item.type == "treasure.scorers":
                    g.score += int(item.value)
                elif item.type == "treasure.timers":
                    g.timer += int(item.value)
                elif item.type == "treasure.diamond":
                    g.timer += item.value
                    g.score += int(item.value)
                elif item.type == "treasure.1UP":
                    g.player.remaining_lives += 1
            g.player.inventory.empty()
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)
_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,
)
# Left
fireball_template.add_directional_model(Constants.LEFT,
                                        Utils.red_bright(f"{black_circle}~"))
fa = Animation(
    auto_replay=True,
    animated_object=fireball_template,
    refresh_screen=redraw_screen,
    display_time=0.5,
)
fa.add_frame(Utils.red_bright(f"{black_circle}~"))
# First let's create a Board that uses squares as delimiters
# Borders are going to be white squares
# Cells with nothing inside are going to be black squares
myboard = Board(
    name="A demo board",
    size=[40, 20],
    ui_border_left=Utils.WHITE_SQUARE,
    ui_border_right=Utils.WHITE_SQUARE,
    ui_border_top=Utils.WHITE_SQUARE,
    ui_border_bottom=Utils.WHITE_SQUARE,
    ui_board_void_cell=Utils.BLACK_SQUARE,
    player_starting_position=[10, 20],
)

# Then create a player
playerone = Player(model=Utils.yellow_bright("××"))

# Place it on the board
myboard.place_item(playerone, 10, 10)

# Now let's display our board
myboard.display()

# And make a short loop that moves the player and display the board
# WARNING: in real life we would use the Game object to manage the game
# and the screen
for k in range(1, 10, 1):
    # Clear screen
    Utils.clear_screen()
    # Print a debug message
    Utils.debug(
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}!")