y=xx0.01125-3.75*x+300是篮球的抛物线轨迹。
import pygame as pg
pg.init()
height=600
width=400
screen = pg.display.set_mode((width, height))
image = pg.image.load("C:\\Users\\zhour\\Pictures\\iconCopy.png")
imageBasket = pg.image.load("C:\\Users\\zhour\\Pictures\\basketball.png") #篮筐
image_rect_basket = imageBasket.get_rect()
image_rect_basket.y=height/2
image_rect_basket.x=350
image_rect = image.get_rect()
image_rect.y=height/2
clock = pg.time.Clock()
while True:
screen.fill((0, 0, 0))
screen.blit(image, image_rect)
screen.blit(imageBasket, image_rect_basket)
image_rect.x += 1
if image_rect.x>400:
break
y=image_rect.x*image_rect.x*0.01125-3.75*image_rect.x+300
image_rect.y = y
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
elif event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
image_rect.y -= 30
clock.tick(60)
pg.display.flip()