首页 > 其他分享 >篮球自动弹跳

篮球自动弹跳

时间:2022-12-01 22:22:28浏览次数:35  
标签:ball ballrect screen 篮球 自动 pygame 弹跳 speed event



import sys
import pygame
pygame.init()  
size = width, height = 640, 480  
screen = pygame.display.set_mode(size)  
color = (0, 0, 0)  
ball = pygame.image.load("ball.png") 
ballrect = ball.get_rect()  
speed = [5, 5]  
clock = pygame.time.Clock()  
while True:
    clock.tick(60)  
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:  
            sys.exit()
    ballrect = ballrect.move(speed)  
   
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]
    screen.fill(color)  
    screen.blit(ball, ballrect) 
    pygame.display.flip()  

pygame.quit()  

 

 
 
 

 

标签:ball,ballrect,screen,篮球,自动,pygame,弹跳,speed,event
From: https://www.cnblogs.com/xsj666/p/16942986.html

相关文章

  • 跳动的篮球
    importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygame......
  • 第十三章实例1篮球自动弹跳
    #-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init......
  • 篮球自动跳跃
    importsysimportpygamepygame.init()#初始化pygamesize=width,height=640,640#设置窗口screen=pygame.display.set_mode(size)#显示窗口color=(0,0,......
  • 篮球自动弹跳
    #-*-codings:utf-8-*-importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.imag......
  • 【51cto】top1全栈接口测试教程 jmeter接口测试,接口自动化测试
    测试时优先对其进行结构化拆分,将测试整体拆分为各个场景创建线程组,简单控制器,HTTP请求默认值,HTTP信息头管理器将测试目标结构化,可以更好地管理测试框架和整合其他组件,有利于......
  • 【51cto】top1全栈接口测试教程 jmeter接口测试,接口自动化测试【2】
    延时等待(全局性)api测试⽤例执⾏速度⾮常快,某些时候因为业务的特性想让它延迟⼏秒执⾏,那么这个时候就使⽤延时等待。参数化可以理解为:⼀个测试点需要多次操作,并且每......
  • 篮球
         ......
  • 篮球自动弹跳
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.im......
  • Python 篮球自动跳
    importsysimportpygamepygame.init()#初始化pygamesize=width,height=640,480#设置窗口screen=pygame.display.set_mode(size)#显示窗口color=......
  • python第十三章(篮球的跳跃游戏
    #-*-coding:utf-8-*-importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.load("b......