python 弹球游戏

import pygame as pg
import sys
import random
a,b=2,2
pg.init()
size=width,height=1500,900
bg=(0,0,0)
count=0
screen=pg.display.set_mode(size)
pg.display.set_caption("接球")
image=pg.image.load('.//img//3.png').convert_alpha()
font=pg.font.SysFont('SimHei',60)
text=font.render("你输了", True, (0,255,0))

position=image.get_rect(centerx=600,centery=200)
color=(255,0,0)
while True:
    for event in pg.event.get():
        if event.type==pg.QUIT:
            sys.exit()
    posx=pg.mouse.get_pos()[0]-200

    screen.fill(bg)

    if 0<posx<=width-400:
        pos=[posx,870,400,30]
    rect=pg.draw.rect(screen,color,pos)
    position=position.move(a,b)
    if position.right>width:
        a=-random.randint(5,15)
#         a=-a
       
    elif position.left<0:
        
        a=random.randint(5,15)
        
    if position.top<0:

        b=random.randint(5,15)

#     flag=pg.Rect.collidelistall(position,rect) 
    flag= pg.Rect.colliderect(position,rect)
    if flag and 872<position.bottom<900:
        count+=100
        b=-random.randint(5,15)

    elif position.bottom>=900:
        screen.blit(text,(650,350))
    text2 = font.render("分数:%d" % count, True, (0, 255, 0))
    screen.blit(text2, (1200, 0))
    
#     if position.bottom    
#     if position.bottom>=900:
        
        

    screen.blit(image,position)
    pg.display.flip()
    pg.time.delay(5)

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值