pygame实现投篮游戏

本文介绍了如何利用Python的pygame库创建一个简单的篮球抛物线轨迹模拟游戏,通过控制图像位置实现篮球运动效果。
摘要由CSDN通过智能技术生成

在这里插入图片描述
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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值