zz-BooM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  6 随笔 :: 0 文章 :: 0 评论 :: 997 阅读
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("qiu.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: 
            pygame.quit()
    
    ballrect = ballrect.move(speed)
    if ballrect.left <0 or ballrect.right > width:
        speed[0] = -speed[1]
    if ballrect.top <0 or ballrect.bottom > height:
        speed[1] = -speed[1] 
    screen.fill(color)
    screen.blit(ball, ballrect) 
    pygame.display.flip() 


    # for event in pygame.event.get():
    #     if event.type == pygame.QUIT:
    #         pygame.quit()

显示为球在跳动,且可以正常退出不闪退

posted on   zz_BooM  阅读(37)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示