from gasp import *
begin_graphics(800, 600, title="Catch", background=color.YELLOW)
set_speed(120)
mitt_x = 780
mitt_y = 300
mitt = Circle((mitt_x, mitt_y), 20)
while True:
if key_pressed('k') and mitt_y <= 580:
mitt_y += 5
elif key_pressed('j') and mitt_y >= 20:
mitt_y -= 5
if key_pressed('escape'):
break
# ^^^^
# 因為 break 會直接跳出這個 while 迴圈,不繼續執行下面的 move_to() 和 update_when()
# 所以按了 esc 後就只會執行最後一行的 end_graphics(),不會改變 mitt 的座標
move_to(mitt, (mitt_x, mitt_y))
update_when('next_tick')
end_graphics()