2020.08.12 13:30班 pygame 第1节

#2020.08.12 13:30班 讲到判断游戏结束,下节课讲创建字体对象,把游戏结束写到屏幕上
import pygame,sys
pygame.init()    #初始化,把所有的小库加载到内存中
screen=pygame.display.set_mode([800,600])
c=pygame.time.Clock()    #建立游戏时钟
ball=pygame.image.load('d:\\pygame\\ball1.png')
ballrect=ball.get_rect()    #获取图片的rect框
wood=pygame.image.load('d:\\pygame\\wood.png')
woodrect=wood.get_rect()    #获取图片的rect框

speedy=7
speedx=12
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()    #卸载各种小库,释放内存
            sys.exit()       #关闭当前窗口
        if event.type == pygame.MOUSEMOTION:
            woodrect.centerx=event.pos[0]
            woodrect.bottom=600
    ballrect.y+=speedy            #移动rect框到新位置
    ballrect.x+=speedx            #移动rect框到新位置
    if ballrect.top<0:
        speedy=-speedy
    if ballrect.left<0 or ballrect.right>800:
        speedx=-speedx
    if pygame.Rect.colliderect(ballrect,woodrect)==True:
        speedy = -speedy
    if ballrect.bottom>600:
        speedx,speedy=0,0
    screen.fill((0,0,0))
    screen.blit(ball,ballrect)      #把图片绘制到新rect框中
    screen.blit(wood,woodrect)      #把图片绘制到新rect框中

    pygame.display.update()  #刷新到屏幕上
    c.tick(60)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值