Beispiel #1
0
Datei: start.py Projekt: Esum/rpg
def load_game_loop(window: sf.RenderWindow, input_clock=sf.Clock(), cursor=0):
    name = ''
    password = ''
    password_md5 = 'd41d8cd98f00b204e9800998ecf8427e'
    typing_text = False
    while True:
        for event in window.events:
            if event.type == sf.Event.RELEASED:
                window.close()
                exit()
        if typing_text:
            if cursor == 0:
                name += input.text.text_input(input_clock)
            elif cursor == 1:
                password += input.text.text_input(input_clock)
                password_md5 = hashlib.md5(password.encode()).hexdigest()
            else:
                game_loop(window, get_player_identifier(name, password_md5))
            if input.key.key_pressed(input.key.Key.BACK_SPACE, input_clock):
                if cursor == 0:
                    name = name[:-1]
                elif cursor == 1:
                    password = password[:-1]
            if input.key.key_pressed(input.key.Key.RETURN, input_clock):
                print(name)
                print(password_md5)
                typing_text = False
        else:
            if input.key.key_pressed(input.key.Key.DOWN, input_clock):
                cursor = (cursor + 1) % 3
            elif input.key.key_pressed(input.key.Key.UP, input_clock):
                cursor = (cursor - 1) % 3
            if input.key.key_pressed(input.key.Key.RETURN, input_clock):
                if cursor == 0 or cursor == 1:
                    typing_text = True
                if cursor == 2:
                    player = get_player_identifier(name, password_md5)
                    break
        draw.draw_load_game_menu(window, cursor, name)
        window.display()
    if cursor == 2:
        del password
        load_maps()
        game_loop(window, player, input_clock)
Beispiel #2
0
Datei: game.py Projekt: Esum/rpg
def game_loop(window: sf.RenderWindow, player: int, input_clock=sf.Clock()):
    moving = 0
    running = conf.auto_run
    menu = False
    cursor = 0
    direction = world.Direction.DOWN
    battle = None
    while True:
        for event in window.events:
            if event.type == sf.Event.RELEASED:
                window.close()
                exit()
        if battle is not None:
            draw.draw_battle(window, player, battle)
            window.display()
        else:
            if moving:
                moving -= 2 + int(running)
                if moving <= 0:
                    moving = 0
                    world.activate_walk_event(player)
            elif menu:
                if input.key.key_pressed(input.key.Key.DOWN, input_clock):
                    cursor = (cursor + 1) % 3
                elif input.key.key_pressed(input.key.Key.UP, input_clock):
                    cursor = (cursor - 1) % 3
                elif input.key.key_pressed(input.key.Key.MENU, input_clock):
                    menu = False
            else:
                if input.key.key_pressed(input.key.Key.RIGHT, input_clock):
                    moving, direction, battle = world.move_player(player, world.Direction.RIGHT)
                elif input.key.key_pressed(input.key.Key.UP, input_clock):
                    moving, direction, battle = world.move_player(player, world.Direction.UP)
                elif input.key.key_pressed(input.key.Key.LEFT, input_clock):
                    moving, direction, battle = world.move_player(player, world.Direction.LEFT)
                elif input.key.key_pressed(input.key.Key.DOWN, input_clock):
                    moving, direction, battle = world.move_player(player, world.Direction.DOWN)
                elif input.key.key_pressed(input.key.Key.MENU, input_clock):
                    menu = True
            draw.draw_game(window, player, moving, direction.value)
            if menu:
                draw.draw_game_menu(window, player, cursor)
            window.display()
            music.play_music(player)
Beispiel #3
0
Datei: start.py Projekt: Esum/rpg
def main_menu_loop(window: sf.RenderWindow, input_clock=sf.Clock()):
    cursor = 0
    while True:
        for event in window.events:
            if event.type == sf.Event.RELEASED:
                window.close()
                exit()
        if input.key.key_pressed(input.key.Key.DOWN, input_clock):
            cursor = (cursor + 1) % 3
        elif input.key.key_pressed(input.key.Key.UP, input_clock):
            cursor = (cursor - 1) % 3
        if input.key.key_pressed(input.key.Key.RETURN, input_clock):
            if cursor == 2:
                window.close()
                exit()
            else:
                break
        draw.draw_main_menu(window, cursor)
        window.display()
    if cursor == 0:
        load_players()
        load_game_loop(window, input_clock)
Beispiel #4
0
def draw_window(window: sf.RenderWindow, position: tuple, size: tuple):
    background = sf.Sprite(windowskin, (0, 0, 63, 63))
    frame_topleft = sf.Sprite(windowskin, (64, 0, 7, 7))
    frame_topright = sf.Sprite(windowskin, (121, 0, 7, 7))
    frame_bottomleft = sf.Sprite(windowskin, (64, 57, 7, 7))
    frame_bottomright = sf.Sprite(windowskin, (121, 57, 7, 7))
    frame_top = sf.Sprite(windowskin, (71, 0, 50, 6))
    frame_left = sf.Sprite(windowskin, (64, 7, 6, 50))
    frame_right = sf.Sprite(windowskin, (122, 7, 6, 50))
    frame_bottom = sf.Sprite(windowskin, (71, 58, 50, 6))
    frame_top.scale(((size[0]-6)/50, 1.0))
    frame_left.scale((1.0, (size[1]-6)/50))
    frame_right.scale((1.0, (size[1]-6)/50))
    frame_bottom.scale(((size[0]-6)/50, 1.0))
    background.scale((size[0]/63, size[1]/63))
    background.move(position)
    frame_topleft.move((position[0]-3, position[1]-3))
    frame_topright.move((position[0]+size[0]-4, position[1]-3))
    frame_bottomleft.move((position[0]-3, position[1]+size[1]-4))
    frame_bottomright.move((position[0]+size[0]-4, position[1]+size[1]-4))
    frame_top.move((position[0]+3, position[1]-3))
    frame_left.move((position[0]-3, position[1]+3))
    frame_right.move((position[0]+size[0]-3, position[1]+3))
    frame_bottom.move((position[0]+3, position[1]+size[1]-3))
    background.color = sf.Color(255, 255, 255, conf.window_transparency)
    window.draw(background)
    window.draw(frame_topleft)
    window.draw(frame_topright)
    window.draw(frame_bottomleft)
    window.draw(frame_bottomright)
    window.draw(frame_top)
    window.draw(frame_left)
    window.draw(frame_right)
    window.draw(frame_bottom)
Beispiel #5
0
def draw_cursor(window: sf.RenderWindow, position: tuple):
    cursor = sf.Sprite(windowskin, (104, 25, 8, 14))
    cursor.move(position)
    window.draw(cursor)