Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/_uix/modal_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@asynccontextmanager
async def darken(*, priority, **kwargs: Unpack[CommonParams]):
interpolate = kwargs["clock"].interpolate_scalar
interpolate = kwargs["clock"].interpolate
draw_target = kwargs["draw_target"]
overlay_surface = Surface(draw_target.size)
set_alpha = overlay_surface.set_alpha
Expand All @@ -32,7 +32,7 @@ async def darken(*, priority, **kwargs: Unpack[CommonParams]):

async def move_rects_vertically(clock: Clock, rects, movement, duration):
org_ys = tuple(rect.y for rect in rects)
async for v in clock.interpolate_scalar(0, movement, duration=duration):
async for v in clock.interpolate(0, movement, duration=duration):
for rect, org_y in zip(rects, org_ys):
rect.y = org_y + v

Expand Down
26 changes: 21 additions & 5 deletions examples/bouncing_balls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@

import pygame
from pygame.colordict import THECOLORS
from pygame import Rect, Vector2, Color
from pygame import Rect, Vector2, Color, Surface

import asyncpygame as apg


async def bouncing_ball(*, dest: Rect, space: Rect, color, velocity: Vector2, **kwargs: Unpack[apg.CommonParams]):
draw_func = partial(pygame.draw.ellipse, kwargs["draw_target"], color, dest)
BLACK = Color("black")
WHITE = Color("white")


def generate_ball_image(*, color, size) -> Surface:
img = Surface((size, size))
bgcolor = WHITE if color == BLACK else BLACK
img.fill(bgcolor)
pygame.draw.ellipse(img, color, img.get_rect())
img = img.convert()
img.set_colorkey(bgcolor)
return img


async def bouncing_ball(*, initial_pos, size: tuple, space: Rect, color, velocity: Vector2, **kwargs: Unpack[apg.CommonParams]):
ball_img = generate_ball_image(color=color, size=size)
dest = ball_img.get_rect(center=initial_pos)
draw_func = partial(kwargs["draw_target"].blit, ball_img, dest)
with kwargs["executor"].register(draw_func, kwargs["priority"]):
async for dt in kwargs["clock"].anim_with_dt():
dest.move_ip(velocity * (dt / 1000.0))
Expand Down Expand Up @@ -38,9 +54,9 @@ async def main(**kwargs: Unpack[apg.CommonParams]):
screen_rect = screen.get_rect()
while True:
await clock.sleep(randint(1000, 2000))
ball_size = randint(20, 150)
nursery.start(bouncing_ball(
dest=Rect(0, 0, ball_size, ball_size).move_to(center=screen_rect.center),
initial_pos=screen_rect.center,
size=randint(20, 150),
space=screen_rect,
color=Color(randint(0, 255), randint(0, 255), randint(0, 255)),
velocity=Vector2(randint(-150, 150), randint(-150, 150)),
Expand Down
6 changes: 3 additions & 3 deletions examples/whack_a_human.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ async def pop_out_enemy(
sounds["hit"].play()
plus_one = with_isolated_alpha(images["plus_one"])
with register(partial(draw_target.blit, plus_one, plus_one.get_rect(midtop=enemy_dest.midtop).move(0, 30)), priority + 0xFFFF0000):
async for v in clock.interpolate_scalar(255, 0, duration=500):
async for v in clock.interpolate(255, 0, duration=500):
enemy_img.set_alpha(v)
plus_one.set_alpha(v)
else:
Expand Down Expand Up @@ -403,7 +403,7 @@ async def pop_out_ally(
await sleep(1000 * speed)
if hit_tracker.finished:
sounds["hit"].play()
async for v in clock.interpolate_scalar(255, 0, duration=500):
async for v in clock.interpolate(255, 0, duration=500):
ally_img.set_alpha(v)
else:
score.value += 3
Expand All @@ -414,7 +414,7 @@ async def pop_out_ally(
draw_ally_req.callback = partial(draw_target.blit, ally_img, ally_dest, ally_clip)
plus_three = with_isolated_alpha(images["plus_three"])
with register(partial(draw_target.blit, plus_three, plus_three.get_rect(midbottom=ally_dest.midtop)), priority + 0xFFFF0000):
async for v in clock.interpolate_scalar(255, 0, duration=500):
async for v in clock.interpolate(255, 0, duration=500):
plus_three.set_alpha(v)
await apg.wait_all(
anim_attrs(ally_dest, top=ally_dest.bottom, duration=500 * speed),
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/asyncpygame/_sdlevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class SDLEvent:

# Waits for the left mouse button to be pressed.
e = await sdlevent.wait(MOUSEBUTTONDOWN, filter=lambda e: e.button == 1)

.. note::

``priority`` 引数は ``PriorityExecutor`` の物とは逆に働きます。すなわち大きい値で ``wait()`` しているタスクほと早く再開します。
'''

def __init__(self):
Expand Down
6 changes: 3 additions & 3 deletions src/asyncpygame/scene_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ async def __call__(self, *, priority, draw_target, clock, executor, **kwargs):
overlay_surface.fill(self.overlay_color)
set_alpha = overlay_surface.set_alpha
with executor.register(partial(draw_target.blit, overlay_surface), priority=priority):
async for v in clock.interpolate_scalar(0, 255, duration=self.out_duration):
async for v in clock.interpolate(0, 255, duration=self.out_duration):
set_alpha(v)
yield
await clock.sleep(self.interval)
yield
async for v in clock.interpolate_scalar(255, 0, duration=self.in_duration):
async for v in clock.interpolate(255, 0, duration=self.in_duration):
set_alpha(v)


Expand Down Expand Up @@ -191,7 +191,7 @@ async def __call__(self, *, priority, draw_target, clock, executor, **kwargs):
executor.register(scroll_inst, priority),
executor.register(partial(draw_target.blit, frame1, dest1), priority + 1),
):
async for v in clock.interpolate_scalar(0, end_pos1, duration=self.duration):
async for v in clock.interpolate(0, end_pos1, duration=self.duration):
v = int_(v)
if is_vertical:
dest1.y = v
Expand Down
4 changes: 2 additions & 2 deletions tests/test_the_python_language.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest


def test_close_a_full_consumed_async_generator_1():
def test_close_a_fully_consumed_async_generator_1():
async def create_agen():
yield

Expand All @@ -16,7 +16,7 @@ async def async_fn(agen):
async_fn(create_agen()).send(None)


def test_close_a_full_consumed_async_generator_2():
def test_close_a_fully_consumed_async_generator_2():
async def create_agen():
return
yield
Expand Down
Loading