示例#1
0
文件: spaceship.py 项目: kostiq/async
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    frame_rows, frame_columns = get_frame_size(garbage_frame)
    column = max(column, 0)
    column = min(column, columns_number - 1)

    uid = uuid.uuid4()

    row = 0

    while row < rows_number:
        if uid in obstacles_in_last_collisions:
            obstacles_in_last_collisions.remove(uid)
            obstacles.pop(uid)
            await explode(canvas, row, column)
            return

        obstacles[uid] = Obstacle(row,
                                  column,
                                  frame_rows,
                                  frame_columns,
                                  uid=uid)

        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed

    obstacles.pop(uid)
示例#2
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 1
    frame_rows, frame_columns = get_frame_size(garbage_frame)

    barrier = Obstacle(row, column, frame_rows, frame_columns)
    obstacles.append(barrier)

    while row < rows_number - frame_rows - 3:  # -3 to save the year info

        barrier.row = row

        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)

        row += speed

        if barrier in obstacles_in_last_collisions:
            await explode(canvas, row, column)
            obstacles_in_last_collisions.remove(barrier)
            obstacles.remove(barrier)
            return False

    obstacles.remove(barrier)
示例#3
0
async def starship_animation(canvas, start_row, start_column, images):
    for image in cycle(images):
        image_row, image_col = get_frame_size(image)
        rows_number, columns_number = canvas.getmaxyx()

        row_bottom = rows_number - image_row
        col_right = columns_number - image_col

        rows_direct, columns_direct, space_pressed = read_controls(canvas)
        start_row = start_row + rows_direct
        start_column = start_column + columns_direct

        if max(start_row, image_row) == image_row:
            start_row = 0
        if min(start_row, row_bottom) == row_bottom:
            start_row = row_bottom
        if max(start_column, image_col) == image_col:
            start_column = 0
        if min(start_column, col_right) == col_right:
            start_column = col_right

        draw_frame(canvas, start_row, start_column, image, negative=False)
        canvas.refresh()
        await asyncio.sleep(0)
        draw_frame(canvas, start_row, start_column, image, negative=True)
示例#4
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0
    obstacle_row, obstacle_column = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, obstacle_row, obstacle_column)
    obstacles.append(obstacle)
    # coroutines.append(show_obstacles(canvas, obstacles))

    while row < rows_number:
        draw_frame(canvas, row, column, garbage_frame)

        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed
        obstacle.row += speed
        if obstacle in obstacles_in_last_collision:
            obstacles.remove(obstacle)
            obstacles_in_last_collision.remove(obstacle)
            await explode(canvas, row + obstacle_row // 2,
                          column + obstacle_column // 2)
            return
    else:
        obstacles.remove(obstacle)
示例#5
0
async def fly_garbage(playground, column, garbage_frame, speed=0.5):
    """
    Animate garbage, flying from top to bottom.
    Column position will stay same, as specified on start.
    """
    min_row, min_col, max_row, max_col = get_playground_limits(playground)

    column = max(column, min_col)
    column = min(column, max_col)

    row = min_row

    rows, cols = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, rows, cols)
    obstacles.append(obstacle)
    center_row = round(rows / 2)
    center_col = round(cols / 2)

    while row < max_row:
        if obstacle in obstacles_in_last_collision:
            obstacles.remove(obstacle)
            obstacles_in_last_collision.remove(obstacle)
            del obstacle
            await explode(playground, row + center_row, column + center_col)
            return
        obstacle.row = row
        draw_frame(playground, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(playground, row, column, garbage_frame, negative=True)
        row += speed
    else:
        obstacles.remove(obstacle)
示例#6
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """
    Animate garbage, flying from top to bottom. Сolumn position will stay
    same, as specified on start.
    """
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0
    garbage_row, garbage_column = get_frame_size(garbage_frame)

    while row < rows_number:

        draw_frame(canvas, row, column, garbage_frame)
        obstacles.append(Obstacle(row, column, garbage_row, garbage_column))
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        obstacles.pop(0)

        # for obst in obstacles_in_last_collisions:
        #     return obst

        row += speed
示例#7
0
async def run_spaceship(canvas, row, column):
    """ controls location of spaceship and draws it on the screen"""
    row_speed = column_speed = 0
    global spaceship_frame
    global coroutines
    global year
    spaceship_collision = False
    while not spaceship_collision:
        maxx, maxy = canvas.getmaxyx()
        rows_direction, columns_direction, space_pressed = read_controls(
            canvas)
        row_speed, column_speed = update_speed(row_speed, column_speed,
                                               rows_direction,
                                               columns_direction)
        frame_rows, frame_columns = get_frame_size(spaceship_frame)
        row, column = speed_reduction_near_border(row, column, frame_rows,
                                                  frame_columns, maxx, maxy,
                                                  row_speed, column_speed)

        draw_frame(canvas, row, column, spaceship_frame)
        last_frame = spaceship_frame

        frame_rows, frame_columns = get_frame_size(spaceship_frame)
        await sleep(1)
        if space_pressed and (year >= 2020):
            coroutines.append(fire(canvas, row, column + 2))

        draw_frame(canvas, row, column, last_frame, negative=True)

        if if_collision_append_collision_list(row, column, frame_rows,
                                              frame_columns):
            spaceship_collision = True
    coroutines.append(
        explode(canvas, row + frame_rows // 2, column + frame_columns // 2))
    coroutines.append(show_gameover(canvas))
示例#8
0
async def animate_spaceship(canvas, row, column, frames):
    for frame in itertools.cycle(frames):
        row, column, space_pressed = get_ship_coordinates(
            canvas, row, column, frame)
        curses_tools.draw_frame(canvas, row, column, frame)
        await asyncio.sleep(0)
        curses_tools.draw_frame(canvas, row, column, frame, negative=True)
示例#9
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0
    row_size, column_size = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, row_size, column_size)
    obstacles.append(obstacle)

    while row < rows_number:
        draw_frame(canvas, row, column, garbage_frame)
        obstacle.row, obstacle.column = row, column
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)

        if obstacle in obstacles_in_last_collisions:
            obstacles_in_last_collisions.remove(obstacle)
            await explode(canvas, row + row_size // 2, column + column_size // 2)
            break

        row += speed

    obstacles.remove(obstacle)
示例#10
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom.

    Сolumn position will stay same, as specified on start.
    """
    global obstacles

    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0

    frame_height, frame_width = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, frame_height, frame_width)
    obstacles.append(obstacle)

    await sleep(1)
    while row < rows_number:
        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed
        obstacle.row += speed

        # Remove garbage that has encountered fire
        if obstacle in obstacles_in_last_collisions:
            obstacles_in_last_collisions.remove(obstacle)
            obstacles.remove(obstacle)
            await explode(canvas, row, column)
            return

    # Remove an obstacle flying over the edge
    obstacles.remove(obstacle)
示例#11
0
async def fly_garbage(canvas, column: int, garbage_frame: TrashFrame,
                      obstacle_id: int, obstacles: dict,
                      destoyed_obstacle_ids: set):
    """
    Animate garbage, flying from top to bottom.
    Сolumn position will stay same, as specified on start.
    """
    rows_number, columns_number = canvas.getmaxyx()

    corrected_column = column - garbage_frame.width - 1
    column = min(max(1, corrected_column), column)

    obstacles[obstacle_id] = Obstacle(0, column, garbage_frame.height,
                                      garbage_frame.width)

    speed = 0.01 + random()

    row = 0
    while row < rows_number:
        draw_frame(canvas, row, column, garbage_frame.frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame.frame, negative=True)

        if obstacle_id in destoyed_obstacle_ids:
            destoyed_obstacle_ids.remove(obstacle_id)
            center_row = row + int(garbage_frame.height / 2)
            center_col = column + int(garbage_frame.width / 2)
            await explode(canvas, center_row, center_col)
            break

        row += speed
        obstacles[obstacle_id].row = row

    del obstacles[obstacle_id]
示例#12
0
async def show_game_over(canvas, window_size):
    with open('frames/game_over.txt', 'r') as file:
        frame = file.read()

    window_size_y, window_size_x = window_size
    frame_size = get_frame_size(frame)
    frame_size_y, frame_size_x = frame_size

    window_center_x = median([
        0,
        window_size_x,
    ])
    frame_width_half = median([
        0,
        frame_size_x,
    ])
    text_start_position_x = window_center_x - frame_width_half
    column = text_start_position_x

    window_center_y = median([
        0,
        window_size_y,
    ])
    frame_height_half = median([
        0,
        frame_size_y,
    ])
    text_start_position_y = window_center_y - frame_height_half
    row = text_start_position_y
    while True:
        draw_frame(canvas, row, column, frame)
        await asyncio.sleep(0)
async def run_spaceship(canvas):
    # Положение корабля и отрисовка
    global spaceship_frame
    max_row, max_col = canvas.getmaxyx()
    frame_max_row, frame_max_col = get_frame_size(load_frames("rocket")[0])
    row = max_row - (frame_max_row + 1)
    col = max_col // 2
    row_speed = col_speed = 0
    while True:
        drow, dcol, space = read_controls(canvas)
        border = 1
        row_speed, col_speed = update_speed(row_speed, col_speed, drow, dcol)

        if border < (col + col_speed) < (max_col - frame_max_col - border):
            col += col_speed
        if border < (row + row_speed) < (max_row - frame_max_row - border):
            row += row_speed

        if space and (globalvars.year >= 2020):
            coroutines.append(fire(canvas, row, col + 2))

        for obstacle in obstacles:
            if obstacle.has_collision(row, col):
                coroutines.append(show_gameover(canvas))
                return

        draw_frame(canvas, row, col, spaceship_frame)
        old_frame = spaceship_frame
        await asyncio.sleep(0)
        draw_frame(canvas, row, col, old_frame, negative=True)
示例#14
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    global obstacles, obstacles_in_last_collisions
    rows_number, columns_number = canvas.getmaxyx()
    height, width = get_frame_size(garbage_frame)

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0

    obstacle = obs.Obstacle(row, column, height, width)
    obstacles.append(obstacle)

    while row < rows_number:
        if obstacle in obstacles_in_last_collisions:
            obstacles.remove(obstacle)
            obstacles_in_last_collisions.remove(obstacle)
            await explode(canvas, row + height / 2, column + width / 2)
            return

        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed
        obstacle.row = row
    obstacles.remove(obstacle)
示例#15
0
async def fire(canvas,
               start_row,
               start_column,
               rows_speed=0.3,
               columns_speed=0):
    """Display animation of gun shot. Direction and speed can be specified."""

    row, column = start_row, start_column

    draw_frame(canvas, row, column, '*')
    await sleep()
    draw_frame(canvas, row, column, 'O')
    await sleep()
    draw_frame(canvas, row, column, 'O', negative=True)
    row += rows_speed
    column += columns_speed

    symbol = '-' if columns_speed else '|'

    rows, columns = canvas.getmaxyx()
    max_row, max_column = rows - 1, columns - 1

    curses.beep()

    while 0 < row < max_row and 0 < column < max_column:
        for obstacle in obstacles:
            if obstacle.has_collision(row, column):
                hit_obstacles.append(obstacle)
                return

        draw_frame(canvas, row, column, symbol)
        await sleep()
        draw_frame(canvas, row, column, symbol, negative=True)
        row += rows_speed
        column += columns_speed
示例#16
0
async def show_messages(canvas):
    message_template = "Year: {} {}"
    while True:
        yr = message_template.format(year, PHRASES.get(year, ''))
        draw_frame(canvas, 0, 0, yr)
        await asyncio.sleep(0)
        draw_frame(canvas, 0, 0, yr, negative=True)
示例#17
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5, uid=None):
    """Animate garbage, flying from top to bottom.
     Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()
    column = max(column, 0)
    column = min(column, columns_number - 1)
    row = 0
    garbage_rows, garbabe_columns = get_frame_size(garbage_frame)
    global obstacles
    global obstacles_in_last_collisions
    obstacle = Obstacle(row, column, garbage_rows, garbabe_columns)
    obstacles.append(obstacle)
    try:
        while row < rows_number:
            draw_frame(canvas, row, column, garbage_frame)
            await sleep(1)
            draw_frame(canvas, row, column, garbage_frame, negative=True)
            if obstacle in obstacles_in_last_collisions:
                obstacles_in_last_collisions.remove(obstacle)
                await explode(canvas, row + garbage_rows / 2,
                              column + garbabe_columns / 2)
                return
            row += speed
            obstacle.row = row
    finally:
        obstacles.remove(obstacle)
示例#18
0
async def run_spaceship(canvas, start_row, start_col):
    row, column = start_row, start_col
    row_speed, column_speed = 0, 0
    min_row, min_column = FRAME_BORDER_SIZE, FRAME_BORDER_SIZE
    max_row, max_column = get_correct_window_dimensions(canvas)

    while True:
        temp_spaceship_frame = spaceship_frame
        # frame_size = get_frame_size(temp_spaceship_frame)
        rows, columns = get_frame_size(temp_spaceship_frame)
        move_row, move_column, space_pressed = read_controls(canvas)
        row_speed, column_speed = update_speed(
            row_speed, column_speed, move_row, move_column)
        row, column = row + row_speed, column + column_speed

        column = min(max(min_column, column), max_column -
                     columns - FRAME_BORDER_SIZE)
        row = min(max(min_row, row), max_row -
                  rows - FRAME_BORDER_SIZE)

        collisions = [obstacle
                      for obstacle in obstacles if obstacle.has_collision(row, column, rows, columns)]
        if collisions:
            await show_gameover(canvas, start_row, start_col)

        if space_pressed and year >= PLASMA_GUN_ERA:
            coroutines.append(
                fire(canvas, row, column + columns // 2))

        draw_frame(canvas, row, column, temp_spaceship_frame)

        await sleep()
        draw_frame(canvas, row, column, temp_spaceship_frame, negative=True)
示例#19
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom.
    Сolumn position will stay same, as specified on start."""
    global obstacles
    global obstacles_in_last_collision
    global coroutines

    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)
    row = 0
    row_size, column_size = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, row_size, column_size)
    obstacles.append(obstacle)

    while row < rows_number:
        if obstacle in obstacles_in_last_collision:
            coroutines.append(
                explode(canvas, row + row_size // 2,
                        column + column_size // 2))
            obstacles_in_last_collision.remove(obstacle)
            break
        draw_frame(canvas, row, column, garbage_frame)
        obstacle.row = row
        obstacle.column = column
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed
    obstacles.remove(obstacle)
示例#20
0
async def fly_garbage(canvas,
                      column,
                      garbage_frame,
                      garbage_id,
                      obstacles,
                      obstacles_in_last_collisions,
                      speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""

    rows_number, columns_number = canvas.getmaxyx()
    frame_rows, frame_columns = get_frame_size(garbage_frame)

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0
    while row < rows_number and garbage_id not in obstacles_in_last_collisions:
        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed
        update_obstacle(obstacles, row, column, frame_rows, frame_columns,
                        garbage_id)
    else:
        remove_obstacle(obstacles, garbage_id)
        if garbage_id in obstacles_in_last_collisions:
            obstacles_in_last_collisions.remove(garbage_id)
            await explode(canvas, row, column)
示例#21
0
async def fly_garbage(canvas, column, garbage_frame, status, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""

    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0
    rows_size, columns_size = get_frame_size(garbage_frame)
    obstacle_object = Obstacle(row, column, rows_size, columns_size)
    status.obstacles.append(obstacle_object)
    try:
        while row < rows_number:
            if obstacle_object in status.obstacles_in_last_collisions:
                await explode(canvas, row + rows_size // 2,
                              column + columns_size // 2)
                status.obstacles_in_last_collisions.remove(obstacle_object)
                return
            draw_frame(canvas, row, column, garbage_frame)
            await sleep()
            draw_frame(canvas, row, column, garbage_frame, negative=True)
            row += speed
            obstacle_object.row = row
    finally:
        status.obstacles.remove(obstacle_object)
示例#22
0
async def run_spaceship(canvas, canvas_vertical_center, canvas_horizontal_center, frames):
    row, column = canvas_vertical_center, canvas_horizontal_center
    frame_rows, frame_columns = get_frame_size(frames[0])
    canvas_rows, canvas_column = canvas.getmaxyx()
    row_speed, column_speed = 0, 0
    while True:
        rows_direction, columns_direction, space_pressed = read_controls(canvas)

        row_speed, column_speed = update_speed(row_speed, column_speed, rows_direction, columns_direction)

        row = max(1, min(row + row_speed, canvas_rows - frame_rows - 1))
        column = max(1, min(column + column_speed, canvas_column - frame_columns - 1))

        previous_spaceship_frame = spaceship_frame

        draw_frame(canvas, row, column, spaceship_frame, negative=False)

        plasma_gun_activation_year = 2020

        if year > plasma_gun_activation_year and space_pressed:
            coroutines.append(fire(canvas, row, column + 2))

        await asyncio.sleep(0)

        draw_frame(canvas, row, column, previous_spaceship_frame, negative=True)

        for index, obstacle in enumerate(obstacles.copy()):
            # add show_gameover coroutine if spaceship meet garbage
            if obstacle.has_collision(row, column):
                coroutines.append(
                    show_gameover(canvas, canvas_vertical_center, canvas_horizontal_center)
                )

                return
示例#23
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay
    same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0

    rows_size, columns_size = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, rows_size, columns_size)
    obstacles.append(obstacle)

    try:
        while row < rows_number:
            draw_frame(canvas, row, column, garbage_frame)
            await asyncio.sleep(0)
            draw_frame(canvas, row, column, garbage_frame, negative=True)
            row += speed
            obstacle.row = row

            if obstacle in obstacles_in_last_collisions:
                obstacles_in_last_collisions.remove(obstacle)
                await explode(canvas, row, column)
                return
    finally:
        obstacles.remove(obstacle)
示例#24
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Column position will stay the same, as specified on start."""

    rows_number, columns_number = canvas.getmaxyx()

    garbage_current_row = 0

    garbage_rows_takes, garbage_columns_takes = get_frame_size(garbage_frame)

    column = max(column, 0)
    garbage_current_column = min(column, columns_number - garbage_columns_takes)

    current_obstacle = Obstacle(garbage_current_row, garbage_current_column, garbage_rows_takes, garbage_columns_takes)

    obstacles.append(current_obstacle)

    try:
        while garbage_current_row < rows_number:
            if current_obstacle in obstacles_in_last_collisions:
                obstacles_in_last_collisions.remove(current_obstacle)
                return

            draw_frame(canvas, garbage_current_row, garbage_current_column, garbage_frame)
            await asyncio.sleep(0)
            draw_frame(canvas, garbage_current_row, garbage_current_column, garbage_frame, negative=True)
            garbage_current_row += speed
            current_obstacle.row += speed
    finally:
        obstacles.remove(current_obstacle)
示例#25
0
async def show_gameover(canvas, window_height, window_width, frame):
    message_size_y, message_size_x = get_frame_size(frame)
    message_pos_y = round(window_height / 2) - round(message_size_y / 2)
    message_pos_x = round(window_width / 2) - round(message_size_x / 2)
    while True:
        draw_frame(canvas, message_pos_y, message_pos_x, frame)
        await asyncio.sleep(0)
示例#26
0
async def fly_garbage(canvas, column, garbage_frame, obstacles, speed=0.5):
    """
        Animate garbage, flying from top to bottom.
        Column position will stay same, as specified on start.
    """
    from main import obstacles_in_last_collisions

    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0

    row_size, col_size = get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, rows_size=row_size, columns_size=col_size)
    obstacles.append(obstacle)

    while row < rows_number:
        obstacle.row = row
        draw_frame(canvas, row, column, garbage_frame)
        await asyncio.sleep(0)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        row += speed

        if obstacle in obstacles_in_last_collisions:
            obstacles_in_last_collisions.remove(obstacle)
            obstacles.remove(obstacle)
            explode_row, explode_col = get_garbage_center(
                row, column, row_size, col_size
            )
            await explode(canvas, explode_row, explode_col)
            return

    obstacles.remove(obstacle)
示例#27
0
 async def show_game_over(self):
     x_pos, y_pos = self.get_game_over_text_position()
     frame_text = '\n'.join(self.game_over_frame)
     while True:
         if self.is_space_died:
             draw_frame(self.canvas, y_pos, x_pos, frame_text)
         await asyncio.sleep(0)
示例#28
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number)

    row = 0

    garbage_rows_size, garbage_columns_size = get_frame_size(garbage_frame)

    obstacle = Obstacle(row, column, garbage_rows_size, garbage_columns_size)
    obstacles.append(obstacle)

    try:

        while row < rows_number:
            draw_frame(canvas, row, column, garbage_frame)
            await sleep()
            draw_frame(canvas, row, column, garbage_frame, negative=True)

            if obstacle in hit_obstacles:
                await explode(canvas, obstacle.center_row,
                              obstacle.center_column)
                return

            row += speed
            obstacle.row = row
    finally:
        obstacles.remove(obstacle)
        if obstacle in hit_obstacles:
            hit_obstacles.remove(obstacle)
示例#29
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    column = max(column, 0)
    column = min(column, columns_number)
    row = 1
    height, width = curses_tools.get_frame_size(garbage_frame)
    obstacle = Obstacle(row, column, rows_size=height, columns_size=width)
    _, bounding_column, bounding_frame = obstacle.dump_bounding_box()

    state.obstacles.append(obstacle)

    while obstacle.row < rows_number:
        # curses_tools.draw_frame(canvas, obstacle.row - 1, bounding_column, bounding_frame)
        curses_tools.draw_frame(canvas, obstacle.row, column, garbage_frame)
        await asyncio.sleep(0)
        curses_tools.draw_frame(canvas,
                                obstacle.row,
                                column,
                                garbage_frame,
                                negative=True)
        # curses_tools.draw_frame(canvas, obstacle.row - 1, bounding_column, bounding_frame, negative=True)
        obstacle.row += speed

        if obstacle in state.obstacles_in_last_collisions.copy():
            state.obstacles_in_last_collisions.remove(obstacle)
            state.obstacles.remove(obstacle)

            state.coroutines.append(
                explode(canvas, obstacle.row + height // 2,
                        column + width // 2))

            return
示例#30
0
async def fly_garbage(canvas, column, garbage_frame, speed=0.5):
    """Animate garbage, flying from top to bottom. Сolumn position will stay same, as specified on start."""
    rows_number, columns_number = canvas.getmaxyx()

    global obstacles
    global obstacles_in_last_collisions
    column = max(column, 0)
    column = min(column, columns_number - 1)

    row = 0

    while row < rows_number:
        draw_frame(canvas, row, column, garbage_frame)
        garbage_height, garbage_length = get_frame_size(garbage_frame)
        obstacle = Obstacle(row, column, garbage_height, garbage_length)
        obstacles.append(obstacle)
        if delay := get_garbage_delay_tics(year):
            await sleep(delay)
        draw_frame(canvas, row, column, garbage_frame, negative=True)
        obstacles.remove(obstacle)
        if obstacle in obstacles_in_last_collisions:
            await explode(canvas, row + garbage_height // 2,
                          column + garbage_length // 2)
            obstacles_in_last_collisions.remove(obstacle)
            return
        row += speed