Ejemplo n.º 1
0
def main():
    screen_width = 70
    screen_height = 45
    window_title = 'game'
    panel_height = 10

    libtcod.console_set_custom_font(consts.FONT, libtcod.FONT_LAYOUT_ASCII_INROW)
    libtcod.console_init_root(screen_width, screen_height, window_title, False)

    con = libtcod.console_new(screen_width, screen_height)
    panel = libtcod.console_new(screen_width, panel_height)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('assets/images/astro.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, screen_width,
                      screen_height)
            show_load_error(con, show_load_error_message, screen_width, screen_height)
            libtcod.console_flush()
            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    # player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            character_creation(con, screen_width, screen_height)
            # play_game()

            show_main_menu = True
Ejemplo n.º 2
0
def main():
    pygame.init()

    game_running = True
    show_main_menu = True
    show_load_error_message = False
    game_state = GameStates.PLAYERS_TURN
    screen, manager, screen_health_bar, entity_info, player, entities, game_map, map_surf, camera = get_game_variables(
    )

    manager.init_main_menu()

    clock = pygame.time.Clock()

    while (game_running):
        time_delta = clock.tick(60) / 1000.0
        if show_main_menu:
            for event in pygame.event.get():
                manager.gui.process_events(event)

                if event.type == pygame.QUIT:
                    game_running = False

                action = handle_main_menu(event, manager.main_menu)

                new_game = action.get('new_game')
                load_saved_game = action.get('load_game')
                exit_game = action.get('exit')

                if new_game:
                    screen, temp_manager, screen_health_bar, entity_info, player, entities, game_map, map_surf, camera = get_game_variables(
                    )
                    game_state = GameStates.PLAYERS_TURN
                    show_main_menu = False

                elif load_saved_game:
                    try:
                        player, entities, game_map, camera, game_state = load_game(
                        )
                        camera.game_map = game_map
                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True

                elif exit_game:
                    game_running = False
                    break
            manager.update(time_delta)
            manager.gui.draw_ui(screen)
            pygame.display.flip()
        else:
            manager.kill_main_menu()
            if not manager.message_log:
                manager.init_message_log()
            play_game(game_map, map_surf, camera, player, entities, screen,
                      manager, screen_health_bar, entity_info, game_state)
            manager.kill_message_log()
            manager.init_main_menu()
            show_main_menu = True
Ejemplo n.º 3
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)
            show_main_menu = True
Ejemplo n.º 4
0
def main():
    constants = get_constants()

    player = None
    game_map = None
    message_log = None
    game_state = None
    camera = None
    map_type = None

    show_main_menu = True
    show_load_error_message = False

    while True:
        if show_main_menu:
            main_menu(constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box('No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])
            blt.refresh()

            action = handle_main_menu()

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if (show_load_error_message
                    and (new_game or load_saved_game or exit_game)):
                show_load_error_message = False
            elif new_game:
                (game_map, player, game_state, camera, message_log,
                 map_type) = (get_game_variables(constants))
                game_map.get_player(player)

                show_main_menu = False
            elif load_saved_game:
                try:
                    (player, game_map, message_log, game_state, camera,
                     map_type) = load_game()

                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            blt.clear()
            play_game(game_map, player, game_state, camera, message_log,
                      map_type)

            show_main_menu = True
Ejemplo n.º 5
0
    def run(self):
        """ Main game loop """
        show_main_menu = True
        show_load_error_message = False

        main_menu_background_image = tcod.image_load('menu_background.png')

        key = tcod.Key()
        mouse = tcod.Mouse()

        while not tcod.console_is_window_closed():
            tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE,
                                     key, mouse)

            if show_main_menu:
                main_menu(self.main_console, main_menu_background_image,
                          self.constants['screen_width'],
                          self.constants['screen_height'])

                if show_load_error_message:
                    message_box(self.main_console, 'No save game to load', 50,
                                self.constants['screen_width'],
                                self.constants['screen_height'])

                tcod.console_flush()

                action = handle_main_menu(key)

                a_new_game = action.get('new_game')
                a_load_saved_game = action.get('load_game')
                a_exit_game = action.get('exit')

                if show_load_error_message and (a_new_game or a_load_saved_game
                                                or a_exit_game):
                    show_load_error_message = False
                elif a_new_game:
                    self.reset_game()
                    show_main_menu = False
                elif a_load_saved_game:
                    try:
                        self.load_saved_game()
                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif a_exit_game:
                    break

            else:
                tcod.console_clear(self.main_console)
                self.play_game()

                show_main_menu = True
Ejemplo n.º 6
0
def main():
    """
    L'une des deux fonctions principales du jeu, elle est appelée une seule et unique fois : au démarrage du jeu.
    Elle a la charge de gérer le choix d'affichage des menus et les réactions aux inputs du joueur.
    Lorsque le joueur quitte un menu pour retourner en jeu, elle appelle la deuxième fonction de ce module : play_game

    Parametres:
    ----------
    Aucun

    Renvoi:
    -------
    Aucun

    """
    # Initialise le jeu en commencant par afficher le menu principal
    constants = get_constants()
    # The font has 32 chars in a row, and there's a total of 10 rows. Increase the "10" when you add new rows to the sample font file
    libtcod.console_set_custom_font('textures.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)
    load_customfont()

    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], "Rogue doesn't like", False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False
    show_command_menu = False
    show_scores = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    play_bg_music = False
    bg_music = sm.choose_sound(constants.get('sound').get('background_music'))

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    score = (1, 0)

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        # Si le menu principal est affiche :
        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            if show_load_error_message:
                message_box(con, 'Rien a charger', 70, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            sound = action.get('sound')
            command = action.get('command')
            back_to_game = action.get('back_to_game')
            scores = action.get('scores')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            # Cree une nouvelle partie
            elif new_game:
                if score != (1, 0):
                    save_score(score)
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            # Charge une partie existante, si possible
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state, score = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                if score != (1, 0):
                    save_game(player, entities, game_map, message_log, game_state, score)
                sm.close_sound()
                break
            # Lit ou arrete la musique de fond
            elif sound:
                play_bg_music = not play_bg_music
                bg_music.playpause()
            elif command:
                show_command_menu = True
                show_main_menu = False
            elif back_to_game and show_main_menu and game_state != GameStates.PLAYER_DEAD:
                show_main_menu = False
            elif scores:
                show_main_menu = False
                show_scores = True

        # Affiche le menu des commandes
        elif show_command_menu:
            action = handle_main_menu(key)
            command_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            libtcod.console_flush()
            back_to_game = action.get('back_to_game')
            if back_to_game:
                show_main_menu = True
                show_command_menu = False
                libtcod.console_clear(con)

        # Affiche les trois meilleurs scores et le dernier
        elif show_scores:
            action = handle_main_menu(key)
            scores_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            libtcod.console_flush()
            back_to_game = action.get('back_to_game')
            if back_to_game:
                show_main_menu = True
                show_scores = False
                libtcod.console_clear(con)

        # Lance une partie
        else:
            libtcod.console_clear(con)
            player, entities, game_map, message_log, game_state, bg_music, play_bg_music, score = play_game(player, entities, game_map, message_log, game_state, con, panel, constants, bg_music, play_bg_music, score)
            if game_state == GameStates.PLAYER_DEAD:
                show_scores = True
            else:
                show_main_menu = True
Ejemplo n.º 7
0
def main():
    consts = get_constants()

    tcod.console_set_custom_font(
        'consolas10x10_gs_tc.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(consts['scrn_width'], consts['scrn_height'],
                           consts['window_title'], False)
    con = tcod.console_new(consts['scrn_width'], consts['scrn_height'])
    panel = tcod.console_new(consts['scrn_width'], consts['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_err_msg = False

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)
        if show_main_menu:
            main_menu(con, consts['scrn_width'], consts['scrn_height'])

            if show_load_err_msg:
                message_box(con, 'No save game to load', 50,
                            consts['scrn_width'], consts['scrn_height'])

            tcod.console_flush()

            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_save = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_err_msg and (new_game or load_save or exit_game):
                show_load_err_msg = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    consts)
                game_state = GameStates.PLAYER_TURN
                show_main_menu = False
            elif load_save:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_err_msg = True
            elif exit_game:
                break
        else:
            tcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, consts)
            show_main_menu = True
Ejemplo n.º 8
0
def main():

    arial_font_path = app_path('assets', 'images', 'arial10x10.png')

    libtcod.console_set_custom_font(
        arial_font_path,
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(Constants.screen_width,
                              Constants.screen_height,
                              Constants.window_title,
                              False,
                              libtcod.RENDERER_SDL2,
                              vsync=False)

    con = libtcod.console.Console(Constants.screen_width,
                                  Constants.screen_height)
    panel = libtcod.console.Console(Constants.screen_width,
                                    Constants.panel_height)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    bg_path = app_path('assets', 'images', 'menu_fire_background.png')
    main_menu_background_image = libtcod.image_load(bg_path)

    while True:
        key_event = None
        for event in libtcod.event.get():
            if event.type in ("QUIT"):
                print("QUIT event: Exiting")
                raise SystemExit()
            if event.type == "KEYDOWN":
                if event.sym == libtcod.event.K_ESCAPE:
                    print(f"{event.type} K_ESCAPE: Exiting")
                    raise SystemExit()
                else:
                    key_event = event
                #print(f"Got Event: {event.type}: {key_event}")

        if show_main_menu:
            main_menu(con, main_menu_background_image, Constants.screen_width,
                      Constants.screen_height)

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            Constants.screen_width, Constants.screen_height)

            libtcod.console_flush()

            action = handle_main_menu(key_event)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            fullscreen = action.get('fullscreen')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    Constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

            if fullscreen:
                libtcod.console_set_fullscreen(
                    not libtcod.console_is_fullscreen())

        else:
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, Constants)

            show_main_menu = True
Ejemplo n.º 9
0
 def on_key(self, key, state=None):
     return handle_main_menu(key)
Ejemplo n.º 10
0
def main():
    constants = get_constants()

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(constants['screen_width'],
                            constants['screen_height'],
                            constants['window_title'])
    con = tdl.Console(constants['screen_width'], constants['screen_height'])
    panel = tdl.Console(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = image_load('menu_background.png')

    while not tdl.event.is_window_closed():
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if show_main_menu:
            main_menu(con, root_console, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'],
                      constants['colors'])

            if show_load_error_message:
                message_box(con, root_console, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tdl.flush()

            action = handle_main_menu(user_input)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            root_console.clear()
            con.clear()
            panel.clear()
            play_game(player, entities, game_map, message_log, game_state,
                      root_console, con, panel, constants)

            show_main_menu = True
Ejemplo n.º 11
0
def main():
    constants = get_constants()

    # tell libtcod which font to use; dictate the file to read from, and the other two arguments tell libtcod which
    # type of file is being read
    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # create the screen with specified width and height; title; boolean value to say full screen or not
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              'libtcod tutorial revised', False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])

    # create a new console to hold the HP bar and message log
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()
            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
Ejemplo n.º 12
0
def main():
	#define main variables
	constants = get_constants()
	
	# Limit FPS to 100 so we dont kill CPUs
	libtcod.sys_set_fps(60)

	# Load font and create root console (what you see)
	libtcod.console_set_custom_font(os.path.join(definitions.ROOT_DIR,'Nice_curses_12x12.png'), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
	libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

	# Create game area and info area, this will be drawn to our root console so that we can see them
	con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
	panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

	player = get_dummy_player(Warrior())
	entities = []
	game_map = None
	message_log: MessageLog  = None
	game_state = None

	show_main_menu = True
	show_game = False
	show_load_error_message = False

	main_menu_background_image = libtcod.image_load(os.path.join(definitions.ROOT_DIR,'data','menu_background.png'))

	# Capture keyboard and mouse input
	key = libtcod.Key()
	mouse = libtcod.Mouse()


	mixer.init()
	mixer.music.load(os.path.join(definitions.ROOT_DIR, 'data', 'music', 'title.mp3'))
	#mixer.music.play(loops=-1)
	#Our main loop
	while not libtcod.console_is_window_closed():
		# Check for input
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
		
		
		
		if show_main_menu:

			main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])

			if show_load_error_message:
				message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

			libtcod.console_flush()

			
			action = handle_main_menu(key)

			new_game = action.get('new_game')
			load_saved_game = action.get('load_game')
			exit_game = action.get('exit')

			if show_load_error_message and (new_game or load_saved_game or exit_game):
				show_load_error_message = False
			elif new_game:
				show_main_menu = False
				show_game = True
			
			elif load_saved_game:
				try:
					player, entities, game_map, message_log, game_state = load_game()
					show_main_menu = False
				except FileNotFoundError:
					show_load_error_message = True
			
			elif exit_game:
				break

		elif show_game == True:
			action = handle_role_select(key)
			warrior = action.get('warrior')
			ranger = action.get('ranger')
			rogue = action.get('rogue')
			paladin = action.get('paladin')
			warlock = action.get('warlock')
			back = action.get('exit')
			accept = action.get('accept')
			libtcod.console_clear(0)
			role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
			libtcod.console_flush()

			if warrior:
				player = get_dummy_player(Warrior())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if ranger:
				player = get_dummy_player(Ranger())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if rogue:
				player = get_dummy_player(Rogue())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if paladin:
				player = get_dummy_player(Paladin())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if warlock:
				player = get_dummy_player(Warlock())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if accept:
				player, entities, game_map, message_log, game_state = get_game_variables(constants, player)
				show_game = False
			if back:
				show_main_menu = True

		else:
			libtcod.console_clear(con)
			game_state = GameStates.PLAYERS_TURN
			play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

			show_main_menu = True
Ejemplo n.º 13
0
def main():
    # 定数を読み込む
    constants = get_constants()

    # フォントの指定と(libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)でどのタイプのファイルを読み取るのかを伝える
    libtcod.console_set_custom_font("arial10x10.png", libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # ここで実際に画面を作成する、画面サイズとタイトルとフルスクリーンとレンダラーと画面の垂直同期を指定している
    libtcod.console_init_root(constants["screen_width"], constants["screen_height"], constants["window_title"], False)

    con = libtcod.console.Console(constants["screen_width"], constants["screen_height"])
    panel = libtcod.console.Console(constants["screen_width"], constants["panel_height"])

    player = None

    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load("menu_background.png")

    main_window = libtcod.console_is_window_closed()

    

    while True:
        if show_main_menu:
            main_menu(con, main_menu_background_image, constants["screen_width"],
                      constants["screen_height"])

            if show_load_error_message:
                message_box(con, "No save game to load", 50, constants["screen_width"], constants["screen_height"])

            libtcod.console_flush()
            for events in libtcod.event.get():
                if events.type == "KEYDOWN":
                    action = handle_main_menu(events)

                    new_game = action.get("new_game")
                    load_saved_game = action.get("load_game")
                    exit_game = action.get("exit")

                    if show_load_error_message and (new_game or load_saved_game or exit_game):
                        show_load_error_message = False
                    elif new_game:
                        player, entities, game_map, message_log, game_state = get_game_variables(constants)
                        game_state = GameStates.PLAYERS_TURN

                        show_main_menu = False
                    elif load_saved_game:
                        try:
                            player, entities, game_map, message_log, game_state = load_game()
                            show_main_menu = False
                        except FileNotFoundError:
                            show_load_error_message = True
                    elif exit_game:
                        return False


        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

            show_main_menu = True
Ejemplo n.º 14
0
def main():
    '''
    Loads and initializes all it needs. Starts game
    '''
    constants = get_constants()

    # uses custom font image
    libtcod.console_set_custom_font("./art/terminal8x8_gs_ro.png",
        libtcod.FONT_LAYOUT_ASCII_INROW)
    libtcod.console_init_root(constants['screen_width'], constants['screen_height'],
        constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # uses custom background image
    main_menu_background_image = libtcod.image_load('./art/background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE,
            key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'],
                constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'],
                    constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            rules_menu = action.get('rules_menu')
            exit_game = action.get('exit')
            fullscreen = action.get('fullscreen')

            # toggle fullscreen
            if fullscreen:
                libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = \
                    get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif rules_menu:
                show_rules()
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                panel, constants)

            show_main_menu = True
Ejemplo n.º 15
0
def main():
    # Initialises, returns and stores a dictionary of all constant values.
    constants = get_constants()
    # Sets the font.
    libtcod.console_set_custom_font(
        "arial10x10.png",
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    # Sets up the root console.
    libtcod.console_init_root(constants["screen_width"],
                              constants["screen_height"],
                              constants["window_title"], False)
    # Creates the main off-screen console.
    con = libtcod.console_new(constants["screen_width"],
                              constants["screen_height"])
    # Creates the hp bar/log panel.
    panel = libtcod.console_new(constants["screen_width"],
                                constants["panel_height"])

    # Will store the game variables.
    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # Grabs an image from the project directory - it will be used for the main menu background.
    main_menu_background_image = libtcod.image_load("menu_background.png")

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        # Creates the main menu and blits it to the console.
        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants["screen_width"], constants["screen_height"])

            if show_load_error_message:
                message_box(con, "No save game found", 50,
                            constants["screen_width"],
                            constants["screen_height"])

            libtcod.console_flush()

            # Handles key presses.
            action = handle_main_menu(key)

            new_game = action.get("new_game")
            load_saved_game = action.get("load_game")
            exit_game = action.get("exit")

            # If the error message is open pressing one of the menu options will close the window.
            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            # If new game is selected get_game_variables() will be called for a the default setup.
            # And the default PLAYERS_TURN gamestate will be set.
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            # Loads the game using load_game().
            elif load_saved_game:
                # Catching the possible FileNotFoundError in load_game().
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    # Shows a message_box if the file cannot be loaded.
                    show_load_error_message = True
            # Exits the game by breaking the while loop.
            elif exit_game:
                break

        # If show_main_menu is False the player_game function will be called using the newly obtained game variables.
        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            # This is set back to True when the play_game() is finished (the user presses ESC or exits).
            # Brings the user back to the main menu.
            show_main_menu = True

    # Sets up the game variables using the constants and returns each to a stored variable.
    # E.g. sets up the player entity.
    player, entities, game_map, message_log, game_state = get_game_variables(
        constants)
Ejemplo n.º 16
0
def main():
	constants = get_constants()

	libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

	libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

	con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
	panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

	player = None
	entities = []
	game_map = None
	message_log = None
	game_state = None

	show_main_menu = True
	show_load_error_message = False

	main_menu_background_image = libtcod.image_load('menu_background1.png')

	key = libtcod.Key()
	mouse = libtcod.Mouse()

	while not libtcod.console_is_window_closed():
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

		if show_main_menu:
			main_menu(con, main_menu_background_image, constants['screen_width'],
					  constants['screen_height'])

			if show_load_error_message:
				message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

			libtcod.console_flush()

			action = handle_main_menu(key)

			new_game = action.get('new_game')
			load_saved_game = action.get('load_game')
			exit_game = action.get('exit')

			if show_load_error_message and (new_game or load_saved_game or exit_game):
				show_load_error_message = False
			elif new_game:
				player, entities, game_map, message_log, game_state = get_game_variables(constants)
				game_state = GameStates.PLAYERS_TURN

				show_main_menu = False
			elif load_saved_game:
				try:
					player, entities, game_map, message_log, game_state = load_game()
					show_main_menu = False
				except FileNotFoundError:
					show_load_error_message = True
			elif exit_game:
				break

		else:
			libtcod.console_clear(con)
			play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

			show_main_menu = True
Ejemplo n.º 17
0
    def main(self):

        # Set font
        libtcod.console_set_custom_font(
            'dejavu_wide16x16_gs_tc.png',
            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
        # Create game window
        libtcod.console_init_root(self.constants['screen_width'],
                                  self.constants['screen_height'],
                                  self.constants['window_title'], False)

        # Create a console (Drawing Layer?)
        con = libtcod.console_new(self.constants['screen_width'],
                                  self.constants['screen_height'])
        panel = libtcod.console_new(self.constants['screen_width'],
                                    self.constants['panel_height'])

        players = []
        entity = []
        game_map = None
        message_log = None
        self.game_state = None
        self.active_player = 0

        show_main_menu = True
        show_load_error_message = False

        main_menu_background_image = libtcod.image_load('menu_background.png')

        # Holds keyboard and mouse input
        key = libtcod.Key()
        mouse = libtcod.Mouse()

        # Menu loop
        while not libtcod.console_is_window_closed():
            libtcod.sys_check_for_event(
                libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

            if show_main_menu:
                main_menu(con, main_menu_background_image,
                          self.constants['screen_width'],
                          self.constants['screen_height'])

                if show_load_error_message:
                    message_box(con, 'No save game to load', 50,
                                self.constants['screen_width'],
                                self.constants['screen_height'])

                libtcod.console_flush()

                action = handle_main_menu(key)

                new_game = action.get('new_game')
                load_saved_game = action.get('load_game')
                exit_game = action.get('exit')

                if show_load_error_message and (new_game or load_saved_game
                                                or exit_game):
                    show_load_error_message = False
                elif new_game:
                    players, entities, game_map, message_log, self.game_state = get_game_variables(
                        self.constants)
                    self.game_state = GameStates.PLAYERS_TURN

                    show_main_menu = False
                elif load_saved_game:
                    try:
                        players, entities, game_map, message_log, self.game_state, self.active_player = load_game(
                            self.constants['player_count'])
                        self.game_state = GameStates.PLAYERS_TURN

                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif exit_game:
                    break
            else:
                libtcod.console_clear(con)
                self.play_game(players, entities, game_map, message_log,
                               self.game_state, con, panel, self.constants)

                show_main_menu = True
Ejemplo n.º 18
0
def main():
    constants = get_constants()

    libtcod.sys_set_fps(30)

    # Animate
    anim_time = libtcod.sys_elapsed_milli()
    anim_frame = 0

    libtcod.console_set_custom_font(
        'sprite-font.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 48)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)
    libtcod.console_set_default_background(0, colors.get('dark'))

    load_customfont()

    con = libtcod.console_new(constants['map_width'] * 3,
                              constants['map_height'] * 2)
    panel = libtcod.console_new(constants['panel_width'],
                                constants['screen_height'])
    tooltip = libtcod.console_new(constants['screen_width'], 1)
    messages_pane = libtcod.console_new(constants['message_width'], 1000)
    inventory_pane = libtcod.console_new(constants['message_width'], 40)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image_0 = libtcod.image_load('menu_background_0.png')
    main_menu_background_image_1 = libtcod.image_load('menu_background_1.png')
    main_menu_background_image_2 = libtcod.image_load('menu_background_2.png')
    main_menu_background_image_3 = libtcod.image_load('menu_background_3.png')

    log_scroll = 0
    inv_scroll = 0

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():

        anim_frame, anim_time = animation(anim_frame, anim_time)

        if anim_frame == 0:
            main_menu_background_image = main_menu_background_image_0
        elif anim_frame == 1:
            main_menu_background_image = main_menu_background_image_1
        elif anim_frame == 2:
            main_menu_background_image = main_menu_background_image_2
        else:
            main_menu_background_image = main_menu_background_image_3

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'],
                      constants['window_title'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            cam_x, cam_y = update_cam(player, constants)

            log_height, inv_height = update_panels_heights(
                player, constants['panel_height'])
            log_scroll = 0
            inv_scroll = 0
            inv_selected = 0

            play_game(player, entities, game_map, message_log, con, panel,
                      tooltip, messages_pane, inventory_pane, constants, cam_x,
                      cam_y, anim_frame, anim_time, log_scroll, log_height,
                      inv_scroll, inv_height, inv_selected)

            show_main_menu = True
Ejemplo n.º 19
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'],
                              fullscreen=False,
                              renderer=libtcod.RENDERER_SDL2,
                              vsync=False)

    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    player = None
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                # This a terrible hack and doing this the "right" way will require tinkering with the render functions
                message_box(con, 'No save game to load', 20,
                            constants['screen_width'],
                            constants['screen_height'] // 2)

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            con.clear(fg=(191, 0, 0))
            play_game(player, game_map, message_log, game_state, con, panel,
                      constants)
            show_main_menu = True
Ejemplo n.º 20
0
def main():
    """Main function for the game."""

    constants = get_constants()

    # setup Font
    font_path = '/home/bobbias/roguelike/arial10x10.png'
    font_flags = tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD
    tcod.console_set_custom_font(font_path, font_flags)

    # init screen
    # window_title = 'Python 3 libtcod tutorial'
    con = tcod.console_init_root(constants['screen_width'],
                                 constants['screen_height'],
                                 order='F',
                                 renderer=tcod.RENDERER_OPENGL2)
    panel = tcod.console_new(constants['screen_width'],
                             constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_imgage = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_imgage,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load!', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_saved_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            tcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
Ejemplo n.º 21
0
def main_menu_loop(root_console: tcod.console.Console) -> None:
    con = tcod.console.Console(constants.screen_width,
                               constants.screen_height,
                               order='F')
    panel = tcod.console.Console(constants.screen_width,
                                 constants.panel_height,
                                 order='F')

    player = None
    entities: List[Entity] = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = tcod.image_load('menu_background1.png')

    while True:
        action: UserAction = {}
        # We pass a 1 second timeout to wait() primarily to give a chance for
        # the Python interpreter to react to ^C in a relatively timely manner.
        for event in tcod.event.wait(1):
            if event.type == 'QUIT':
                sys.exit()
            elif event.type == 'KEYDOWN':
                action = handle_main_menu(event)
            if action:
                break

        if show_main_menu:
            main_menu(root_console, main_menu_background_image,
                      constants.screen_width, constants.screen_height)

            if show_load_error_message:
                message_box(root_console, 'No save game to load', 50,
                            constants.screen_width, constants.screen_height)

            tcod.console_flush()

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            fullscreen = action.get('fullscreen')

            if fullscreen:
                tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                (player, entities, game_map, message_log,
                 game_state) = get_game_variables()
                show_main_menu = False
            elif load_saved_game:
                try:
                    (player, entities, game_map, message_log,
                     game_state) = load_game()
                except FileNotFoundError:
                    show_load_error_message = True
                else:
                    show_main_menu = False
            elif exit_game:
                break

        else:
            con.clear()
            assert player is not None
            assert game_map is not None
            assert message_log is not None
            assert game_state is not None
            play_game(player, entities, game_map, message_log, game_state,
                      root_console, con, panel)
            show_main_menu = True
Ejemplo n.º 22
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'TiledFont.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_character_screen = False
    start_game = None
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            choose_fighter = action.get('choose_fighter')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants, 'barbarian')
                game_state = GameStates.PLAYER_TURN

                show_main_menu = False
                start_game = True
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                    start_game = True
                except FileNotFoundError:
                    show_load_error_message = True
            elif choose_fighter:
                show_main_menu = False
                #show_character_screen = True
                new_character_screen(con, main_menu_background_image,
                                     constants['screen_width'],
                                     constants['screen_height'])
                libtcod.console_flush()
                '''TODO: Задать переменную, отвечающую за то, что открыто ли окно choose_fighter или нет'''
                action_character_menu = handle_new_character_menu_keys(key)

                warrior = 'warrior'
                thief = 'thief'
                barbarian = 'barbarian'
                exit_character_menu = 'exit'

                if action_character_menu.get('warrior') == warrior:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, warrior)

                    game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                    #show_main_menu = False
                    #start_game = True
                    #start_game = True
                    choose_fighter = False

                elif action_character_menu.get('thief') == thief:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, thief)
                    #game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                    choose_fighter = False

                elif action_character_menu.get('barbarian') == barbarian:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, barbarian)
                    game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                elif action_character_menu.get('exit') == exit_character_menu:
                    show_character_screen = False
                    show_main_menu = True
                    main_menu(con, main_menu_background_image,
                              constants['screen_width'],
                              constants['screen_height'])
                    libtcod.console_flush()

                show_character_screen = False

            elif choose_fighter == False:
                start_game = True
                game_state.PLAYER_TURN

            elif exit_game:
                break
        elif start_game == True:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
Ejemplo n.º 23
0
def main():

    constants = get_constants()
    names_list = get_unidentified_names()
    colors_list = get_render_colors()
    load_customfont()

    libtcod.console_set_custom_font(
        'fontplus.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW, 16, 30)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                constants = get_constants()
                names_list = get_unidentified_names()
                colors_list = get_render_colors()

                if intro(constants):
                    if not game_options(constants) == "nah":
                        if not origin_options(constants) == "nah":
                            if not character_name(constants) == 'nah':
                                player, entities, game_map, message_log, game_state = get_game_variables(
                                    constants, names_list, colors_list)
                                game_state = GameStates.PLAYERS_TURN

                                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state, constants = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants, names_list, colors_list)

            show_main_menu = True
Ejemplo n.º 24
0
def main():
    constants = get_constants()
    main_menu_background_image = tcod.image_load('menu_background.png')
    tcod.console_set_custom_font(
        'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

    root_con = tcod.console_init_root(constants["screen_width"],
                                      constants["screen_height"],
                                      constants["window_title"],
                                      order="C",
                                      renderer=tcod.RENDERER_SDL2,
                                      vsync=True)

    con = tcod.console.Console(constants['screen_width'],
                               constants['screen_height'])
    panel = tcod.console.Console(constants['screen_width'],
                                 constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    while show_main_menu:
        main_menu(con, main_menu_background_image, constants['screen_width'],
                  constants['screen_height'], root_con)

        if show_load_error_message:
            message_box(con, 'No save game to load', 50,
                        constants['screen_width'], constants['screen_height'],
                        root_con)

        tcod.console_flush()
        action = {}
        for event in tcod.event.get():
            if isinstance(event, tcod.event.KeyDown):
                action = handle_main_menu(event)

        new_game = action.get('new_game')
        load_saved_game = action.get('load_game')
        exit_game = action.get('exit')

        if show_load_error_message and (new_game or load_saved_game
                                        or exit_game):
            show_load_error_message = False
        elif new_game:
            player, entities, game_map, message_log, game_state = get_game_variables(
                constants)
            game_state = GameStates.PLAYER_TURN
            show_main_menu = False
        elif load_saved_game:
            try:
                player, entities, game_map, message_log, game_state = load_game(
                )
                show_main_menu = False
            except FileNotFoundError:
                show_load_error_message = True
        elif exit_game:
            quit()
    else:
        con.clear()
        play_game(player, entities, game_map, message_log, game_state, con,
                  panel, constants, root_con)
        main()
Ejemplo n.º 25
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font('tennisOut.png',
                                    libtcod.FONT_LAYOUT_ASCII_INROW, 32, 10)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)
    load_customfont()
    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    show_main_menu = True
    show_load_error_message = False

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:

            main_menu(con, constants['screen_width'],
                      constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    play_game(player, entities, game_map, message_log, con,
                              panel, constants)
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)

            character_selection(constants, con, panel)

            show_main_menu = True
Ejemplo n.º 26
0
def main():
    # pull variables
    constants = get_constants()

    # set graphics template (source, type, layout)

    # --- original setup ---
    # libtcod.console_set_custom_font(
    #     'arial10x10.png',
    #     libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # --- new font file ---
    libtcod.console_set_custom_font(
        'TiledFont.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)

    # create screen (width, height, title, fullscreen_boolean)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    # initialize console
    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    libtcod.console_set_fullscreen(True)

    # mixer.music.play(-1)
    # music_loop = mixer.Sound('Cave_Loop.wav')
    # mixer.Sound.play(music_loop)

    mixer.init()
    music_loop = mixer.Sound('Cave_Loop.wav')
    mixer.Sound.play(music_loop, loops=-1)

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYER_TURN
                show_main_menu = False

            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
Ejemplo n.º 27
0
def main():
    constants = get_constants()
    tc.console_set_custom_font('arial10x10.png',
                               tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD)
    tc.console.Console(constants['screen_width'], constants['screen_height'])
    tc.console_init_root(constants['screen_width'], constants['screen_height'],
                         constants['window_title'], False, tc.RENDERER_SDL2,
                         "F", True)

    con = tc.console.Console(constants['screen_width'],
                             constants['screen_height'])
    panel = tc.console.Console(constants['screen_width'],
                               constants['screen_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # main_menu_background_image = tc.image_load('menu_background.png')
    main_menu_background_image = tc.image_load('')

    key = tc.Key()
    mouse = tc.Mouse()

    event = tc.event.get()

    # for event in tcod.event.wait():
    while event != "QUIT":
        tc.sys_check_for_event(tc.EVENT_KEY_PRESS | tc.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            con.clear()
            clear_all(con, entities)
            tc.console_blit(con, 0, 0, constants['screen_width'],
                            constants['screen_height'], 0, 0, 0, 1.0, 1.0)
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tc.console_flush()
            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                show_main_menu = False
                #REVERT BEFORE COMMIT
                # game_state = GameStates.SHOW_TUTORIAL
                game_state = GameStates.PLAYERS_TURN

            elif load_saved_game:

                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False

                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
Ejemplo n.º 28
0
def main():
    constants = get_constants()

    # Fonts
    tcod.console_set_custom_font(
        'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    # Initialise console
    tcod.console_init_root(constants['screen_width'],
                           constants['screen_height'],
                           constants['window_title'],
                           False,
                           renderer=tcod.RENDERER_SDL2,
                           vsync=True)

    # Variables for console and display panel
    con = tcod.console.Console(constants['screen_width'],
                               constants['screen_height'])
    panel = tcod.console.Console(constants['screen_width'],
                                 constants['screen_height'])

    # Initalise variables
    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False

            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break
        else:
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
Ejemplo n.º 29
0
def main():
    game = Game()
    show_load_error_message = False

    game.game_state: GameStates = GameStates.MAIN_MENU
    game.previous_state: GameStates = game.game_state

    blt.open()
    blt.composition(True)
    blt.set(
        f"window: size={CONSTANTS.screen_width}x{CONSTANTS.screen_height}, title={CONSTANTS.window_title}, cellsize=8x8"
    )
    blt.set("input: filter={keyboard, mouse+}")
    blt.set(f"{CONSTANTS.map_font}")
    blt.set(f"{CONSTANTS.ui_font}")
    blt.set(f"{CONSTANTS.bar_font}")
    blt.set(f"{CONSTANTS.hover_font}")

    while game.game_running:
        if game.game_state == GameStates.MAIN_MENU:

            blt.clear()

            if show_load_error_message:
                message_box(
                    header="No save game to load",
                    width=50,
                    screen_width=CONSTANTS.screen_width,
                    screen_height=CONSTANTS.screen_height,
                )

            main_menu(CONSTANTS.camera_width)
            blt.refresh()

            if blt.has_input():

                terminal_input = blt.read()
                print(terminal_input)
                action = handle_main_menu(terminal_input)

                new_game: bool = action.get("new_game", False)
                load_saved_game: bool = action.get("load_game", False)
                exit_game: bool = action.get("exit_game", False)

                if show_load_error_message and (new_game or load_saved_game
                                                or exit_game):
                    show_load_error_message = False
                elif new_game:
                    game = game.new_game()
                    game.map_generator.make_map(
                        width=CONSTANTS.map_width,
                        height=CONSTANTS.map_height,
                        entities=game.entities,
                        min_monsters=CONSTANTS.min_monsters,
                    )
                    game.game_state = GameStates.PLAYER_TURN
                    game.player.position = game.map_generator.player_start_point

                elif load_saved_game:
                    try:
                        game = game.load_game()
                    except FileNotFoundError:
                        show_load_error_message = True
                elif exit_game:
                    break
        else:
            blt.clear()
            play_game(game)

            game.game_state = GameStates.MAIN_MENU
Ejemplo n.º 30
0
def main():
    constants = get_constants()
    #mixer.init(frequency=44100, size=16, channels=2,buffer=4096)
    #mixer.music.load('A Memory Lost.ogg')
    #mixer.music.play(loops=0, start=0.0)
    #mixer.music.set_volume(0.01)

    libtcod.console_set_custom_font('terminal16x16_gs_ro.png',
                                    libtcod.FONT_LAYOUT_ASCII_INROW, 16, 18)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False,
                              libtcod.RENDERER_OPENGL)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    message_panel = libtcod.console_new(constants['message_panel_width'],
                                        constants['panel_height'])
    char_info_panel = libtcod.console_new(constants['char_info_panel_width'],
                                          constants['char_info_panel_height'])
    area_info_panel = libtcod.console_new(constants['area_info_panel_width'],
                                          constants['area_info_panel_height'])
    under_mouse_panel = libtcod.console_new(
        constants['under_mouse_panel_width'],
        constants['under_mouse_panel_height'])

    #load_customfont()

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False
    show_controls_menu = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No saved games to load', libtcod.darker_blue,
                            23, constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            controls = action.get('controls')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_new_game_variables(
                    constants)

                if player != None:
                    fov_map = initialize_fov(game_map)
                    floor_index = []
                    entity_index = []
                    original_entity_index = entity_index
                    fov_index = []
                    floor_index.append(game_map.tiles)
                    entity_index.append(entities)
                    original_entity_index.append(entities)
                    fov_index.append(fov_map)
                    game_state = GameStates.PLAYERS_TURN
                    show_main_menu = False

            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state, floor_index, original_entity_index, \
                    entity_index, fov_index = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif controls and show_controls_menu == False:
                show_controls_menu = True
                show_main_menu = False

            elif exit_game:
                break

        elif show_controls_menu:
            libtcod.console_clear(0)
            controls_menu(con, '', 30, constants['screen_width'],
                          constants['screen_height'])
            action = handle_controls_menu(key)
            libtcod.console_flush()
            back_to_main_menu = action.get('exit')

            if back_to_main_menu:
                show_controls_menu = False
                show_main_menu = True
                libtcod.console_clear(0)

        elif show_main_menu == False and show_controls_menu == False:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      message_panel, char_info_panel, area_info_panel,
                      under_mouse_panel, constants, floor_index,
                      original_entity_index, entity_index, fov_index)

            show_main_menu = True
Ejemplo n.º 31
0
def main():
    constants = get_constants()

    tcod.console_set_custom_font(
        'consolas12x12_gs_tc.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(constants['screen_width'],
                           constants['screen_height'],
                           constants['window_title'], False)
    con = tcod.console_new(constants['screen_width'],
                           constants['screen_height'])
    panel = tcod.console_new(
        constants['screen_width'],
        constants['screen_height'] - constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None
    show_main_menu = True
    show_load_error_message = False
    main_menu_background_image = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)
        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])
            if show_load_error_message:
                menu(con, 'Save game unfound', [], 50,
                     constants['screen_width'], constants['screen_height'])
            tcod.console_flush()

            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_game_bool = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_vars(
                    constants)
                show_main_menu = False
            elif load_game_bool:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break
        else:
            tcod.console_clear(con)
            start_game(player, entities, game_map, message_log, game_state,
                       con, panel, constants)

            show_main_menu = True