首页 > 其他分享 >跳动篮球-

跳动篮球-

时间:2022-12-02 11:56:38浏览次数:37  
标签:ball ballrect screen 篮球 跳动 pygame speed event

点击查看代码
import sys
import pygame

pygame.init()
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
color = (121,178,250) 

ball = pygame.image.load("basketball.png")
ballrect = ball.get_rect()

speed = [2,3]
clock = pygame.time.Clock()
while True:
    clock.tick(120)
    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/m7hhhhhh/p/16944016.html

相关文章

  • pygame篮球弹跳
     Pygame的基本应用 创建一个游戏窗口,然后再窗口内创建一个小球。以一定的速度移动小球,当小球碰到游戏窗口的边缘时,小球弹回,继续移动。importsysimportpygamepyg......
  • 篮球自动弹跳
    代码:#-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygamesize=width,height=640,480#设置窗口scr......
  • 跳动小球
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.load("th.jpg......
  • python篮球自动弹跳
           具体思路是首先导入sys和pygame模块然后初始化pygame然后显示窗口加载篮球图片执行死循环检查事件设置移动篮球将图片画在窗口上最后更新全部显示......
  • 篮球自动弹跳
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.......
  • 跳动的篮球
    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......
  • 篮球
         ......