Python 弹跳小球

### 弹跳小球

import sys
import pygame as pg
import random as rd

pg.init()
PGscreensize=INTwidth,INTheight=1200,800
PGscreen=pg.display.set_mode(PGscreensize)                                  # 屏幕初始化
PGcolor=(0,0,0)                                                             # 屏幕背景色

STRLISTfilename=["ball1.png","ball2.png","ball3.png","ball4.png","ball5.png","ball6.png","ball7.png","ball8.png","ball9.png","ball10.png","b
all11.png","ball12.png","ball13.png","ball14.png","ball15.png","ball16.png"]
for i in range(len(STRLISTfilename)):
    exec("PGballname{}=pg.image.load(STRLISTfilename[{}])".format(i,i))
    exec("PGballrect{}=PGballname{}.get_rect()".format(i,i))
    exec("PGballspeed{}=[rd.randint(1,10),rd.randint(1,10)]".format(i))
PGclock=pg.time.Clock()
while True:
    PGclock.tick(60)
    for event in pg.event.get():
        if event.type==pg.QUIT:
            sys.exit()
    PGscreen.fill(PGcolor)
    for i in range(len(STRLISTfilename)):
        exec("PGballrect{}=PGballrect{}.move(PGballspeed{})".format(i,i,i))
        exec("INTleft=PGballrect{}.left".format(i))
        exec("INTright=PGballrect{}.right".format(i))
        exec("INTtop=PGballrect{}.top".format(i))
        exec("INTbottom=PGballrect{}.bottom".format(i))
        if INTleft<0 or INTright>INTwidth:
            exec("PGballspeed{}[0]=-PGballspeed{}[0]".format(i,i))
        if INTtop<0 or INTbottom>INTheight:
            exec("PGballspeed{}[1]=-PGballspeed{}[1]".format(i,i))
        exec("PGscreen.blit(PGballname{},PGballrect{})".format(i,i))
    pg.display.flip()
pg.quit()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值