kewin -接小球终极版

import pygame
import random
# 1.loading 初始化
pygame.init()
# 2.窗口   dis分开   play玩 ----》 展示
screen_width = 960
screen_height = 540
screen = pygame.display.set_mode((screen_width, screen_height ))
# 3.游戏名字 caption标题
pygame.display.set_caption("接小球游戏")
ballx1 = 350
bally1 =300
color1 = (200,200,200)
r1 = 50

ban_x, ban_y,ban_width,ban_height = 400,screen_height-50,220,100
score = 0 # f分数
live  = 3
font = pygame.font.Font("ziti.ttf", 24)

# 1.加载图片  image
qiu = pygame.image.load("cai.png")
qiu2 = pygame.image.load("qiu.jpg")
beijing=pygame.image.load('bg3.jpg')

# 速度
speed = 1
# 事件
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            # 4.退出
            pygame.quit()
        elif event.type == pygame.MOUSEMOTION:
            ban_x, a = event.pos   # pos ---> position  位置

    # 填充屏幕颜色
    # screen.fill((255, 255, 255)) # rgb 三基色red green blue
    screen.blit(beijing, (0, 0))

    bally1 += speed
    # ballx1 += 1
    if bally1>screen_height:
        live = live -1
        bally1=0
        ballx1=random.randint(0,screen_width)
        color1 = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
        r1 = random.randint(20,40)
        if speed>1:
            speed=speed-1
    # 判断生命值是否用完
    if live<=0:
        pygame.quit()
    # 判断常伴接到小球 撤销 ctrl + z
    if ban_x<ballx1<ban_x+ban_width and ban_y<bally1<ban_y+ban_height:
        score = score+1
        speed=speed+1
        bally1 = 0
        ballx1 = random.randint(0, screen_width-100)

    score_text = font.render("分数:%d"%score,True,(255,255,255) )
    screen.blit(score_text,(10,10))
    live_text = font.render("生命值:%d" % live, True, (255, 255, 255))
    screen.blit(live_text, (10, 40))
    # 画圆
    # pygame.draw.circle(screen,color1,(ballx1, bally1),r1)
    if score<10:
        screen.blit(qiu,(ballx1, bally1))
    else:
        screen.blit(qiu2,(ballx1,bally1))


    # 画长方形 rect
    pygame.draw.rect(screen,(240,197,105),(ban_x, ban_y,ban_width,ban_height ) )

    # 3.刷新
    pygame.display.update()









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值