Ejemplo n.º 1
0
def test_sys_time(console):
    libtcodpy.sys_set_fps(0)
    libtcodpy.sys_get_fps()
    libtcodpy.sys_get_last_frame_length()
    libtcodpy.sys_sleep_milli(0)
    libtcodpy.sys_elapsed_milli()
    libtcodpy.sys_elapsed_seconds()
Ejemplo n.º 2
0
    def handle_drag_event(self, mouse_event):
        """Check for and handle (if necessary) drag events.
        """
        start = tcod.sys_elapsed_milli()
        dragged = False
        mouse = mouse_event.state
        ox, oy = mouse.cx, mouse.cy
        key = tcod.Key()
        while mouse.lbutton:
            tcod.sys_check_for_event(tcod.EVENT_MOUSE, key, mouse)
            mouse.dx, mouse.dy = ox - mouse.cx, oy - mouse.cy
            if (tcod.sys_elapsed_milli() > (self.drag_delay * 1000 + start)) and \
                    (mouse.dx != 0 or mouse.dy != 0):
                dragged = True
                # Are we dragging on the window title (move!)?
                if self.window_manager.topwin.can_drag_p and \
                    self.window_manager.topwin.on_upper_window_border(mouse.cx - self.window_manager.topwin.tlx,
                                                       mouse.cy - self.window_manager.topwin.tly):
                    self.window_manager.topwin.mouse_drag(mouse)

                # Are we dragging on the bottom right corner (resize!)?
                elif self.window_manager.topwin.can_resize_p and \
                    ox == (self.window_manager.topwin.tlx + self.window_manager.topwin.width - 1) and \
                    oy == (self.window_manager.topwin.tly + self.window_manager.topwin.height - 1):
                    self.window_manager.topwin.mouse_resize(mouse)
                else:
                    self.window_manager.topwin.on_mouse_event(MouseDragEvent(winx=mouse.cx - self.window_manager.topwin.tlx,
                                                              winy=mouse.cy - self.window_manager.topwin.tly,
                                                              mouse_state=mouse_event))
Ejemplo n.º 3
0
def test_sys_time(console):
    libtcodpy.sys_set_fps(0)
    libtcodpy.sys_get_fps()
    libtcodpy.sys_get_last_frame_length()
    libtcodpy.sys_sleep_milli(0)
    libtcodpy.sys_elapsed_milli()
    libtcodpy.sys_elapsed_seconds()
Ejemplo n.º 4
0
 def step(self, root):
     start = tcod.sys_elapsed_milli()
     if self.current_key_event.pressed == True and self.current_key_event.vk == tcod.KEY_ESCAPE:
         self.end_game = True
     super().step(root)
     self.print_debug_info()
     # self.game_step()
     end = tcod.sys_elapsed_milli()
Ejemplo n.º 5
0
 def step(self, root):
     start = tcod.sys_elapsed_milli()
     if self.current_key_event.pressed == True and self.current_key_event.vk == tcod.KEY_ESCAPE:
         self.end_game = True
     super().step(root)
     self.print_debug_info()
     # self.game_step()
     end = tcod.sys_elapsed_milli()
Ejemplo n.º 6
0
def animation(anim_frame, anim_time):
    if libtcod.sys_elapsed_milli() - anim_time > 200:
        anim_time = libtcod.sys_elapsed_milli()
        if anim_frame < 3:
            anim_frame += 1
        else:
            anim_frame = 0
    return anim_frame, anim_time
Ejemplo n.º 7
0
 def step(self, root):
     start = tcod.sys_elapsed_milli()
     if self.build_world:
         self.world_view.build_world(root)
         self.build_world = False
     super().step(root)
     self.world_view.on_update()
     if self.current_key_event.pressed == True and self.current_key_event.vk == tcod.KEY_ESCAPE:
         self.end_game = True
     #self.print_debug_info()
     # self.game_step()
     end = tcod.sys_elapsed_milli()
Ejemplo n.º 8
0
 def step(self, root):
     start = tcod.sys_elapsed_milli()
     if self.build_world:
         self.world_view.build_world(root)
         self.build_world = False
     super().step(root)
     self.world_view.on_update()
     if self.current_key_event.pressed == True and self.current_key_event.vk == tcod.KEY_ESCAPE:
         self.end_game = True
     #self.print_debug_info()
     # self.game_step()
     end = tcod.sys_elapsed_milli()
Ejemplo n.º 9
0
 def process_window(self, focus_changed=False):
     """
     Check if window needs not hidden and needs to be redrawn (either through changed_p or auto_redraw_p)
     and if so prepares the window and draws it to the root console.
     """
     if self.hidden_p:
         return
     if (self.changed_p and self.auto_redraw_p) or \
             (self.auto_redraw_time and
              tcod.sys_elapsed_milli() >
              (self.auto_redraw_time + self.last_update_time)):
         self.prepare()
         self.redraw_area(draw_window=True)
         self.dirty_window()
         self.changed_p = False
         self.last_update_time = tcod.sys_elapsed_milli()
     elif focus_changed:
         self.redraw_area(draw_window=True)
Ejemplo n.º 10
0
 def process_window(self, focus_changed=False):
     """
     Check if window needs not hidden and needs to be redrawn (either through changed_p or auto_redraw_p)
     and if so prepares the window and draws it to the root console.
     """
     if self.hidden_p:
         return
     if (self.changed_p and self.auto_redraw_p) or \
             (self.auto_redraw_time and
              tcod.sys_elapsed_milli() >
              (self.auto_redraw_time + self.last_update_time)):
         self.prepare()
         self.redraw_area(draw_window=True)
         self.dirty_window()
         self.changed_p = False
         self.last_update_time = tcod.sys_elapsed_milli()
     elif focus_changed:
         self.redraw_area(draw_window=True)
Ejemplo n.º 11
0
    def _percent_of_catch_to_display(self):
        """
            Given that we are currently attempting to catch a creature this 
            function returns how far through the catch process we are.

            The return value comes as a percent and is maxed at the percent
            caught of the creature (as first calculated).
        """
        return min((libtcod.sys_elapsed_milli() - self.time_started_catching_ms) / BattleState.ms_per_percent_complete,
                   self.percent_of_creature_caught)
Ejemplo n.º 12
0
 def send_mouse_click_event(self, window, event):
     double_click = False
     if window:
         if event.state.lbutton and event.state.cy == window.tly and event.state.cx == window.brx and window.can_close_p:
             window.hide(True)
         elif self.last_mouse_click and type(event) == type(self.last_mouse_click) and \
                         (tcod.sys_elapsed_milli() - self.last_mouse_click.time) < self.double_click_speed:
             double_click = True
         self.last_mouse_click = MouseEvent(winx=event.state.cx - window.tlx,
                                            winy=event.state.cy - window.tly,
                                            mouse_state=event,
                                            window=window,
                                            double_click=double_click)
         window.on_mouse_event(self.last_mouse_click)
Ejemplo n.º 13
0
    def _selecting_pokeball_input(self, key):
        """
            Input handler when the sub state is selecting a pokeball.
        """
        if key.vk == libtcod.KEY_ESCAPE:
            self.selecting_pokeball = False
        elif key.vk == libtcod.KEY_CHAR:
            for pokeball in self.game_data.player.available_pokeballs():
                if key.c == ord(pokeball.display_char) or key.c == ord(pokeball.display_char.lower()):
                    self.selecting_pokeball = False
                    self.catching_with_pokeball = pokeball
                    self.time_started_catching_ms = libtcod.sys_elapsed_milli()
                    num_checks_passed = battle_calculations.num_catch_checks_passed(self.game_data.battle_data.defending_creature(), pokeball, BattleState.number_catch_checks)

                    self.percent_of_creature_caught = (100 * num_checks_passed) // BattleState.number_catch_checks
                    self.game_data.player.use_pokeball(pokeball)
                    break
Ejemplo n.º 14
0
 def draw(self):
     self.write(1, 2, "No draw method defined, using default method.")
     self.write(1, 3, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     self.write(1, 4, "FPS = {0}".format(tcod.sys_get_fps()))
Ejemplo n.º 15
0
 def __init__(self, window=None, winx=0, winy=0):
     self.window = window
     self.winx = winx
     self.winy = winy
     self.time = tcod.sys_elapsed_milli()
Ejemplo n.º 16
0
 def draw(self):
     self.write(1, 2, "No draw method defined, using default method.")
     self.write(1, 3, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     self.write(1, 4, "FPS = {0}".format(tcod.sys_get_fps()))
Ejemplo n.º 17
0
 def print_debug_info(self):
     fps = tcod.sys_get_fps()
     root = self.window_manager.rootc
     root.write(0, 0, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
Ejemplo n.º 18
0
 def print_debug_info(self):
     fps = tcod.sys_get_fps()
     root = self.window_manager.rootc
     root.write(0, 0, "Time elapsed = {0}".format(tcod.sys_elapsed_milli()))
     root.write(0, 1, "FPS = {0}".format(fps))
     root.write(0, 2, "Current event = {0}.".format(self.current_event))
Ejemplo n.º 19
0
 def __init__(self, window=None, winx=0, winy=0):
     self.window = window
     self.winx = winx
     self.winy = winy
     self.time = tcod.sys_elapsed_milli()
Ejemplo n.º 20
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