kewin - 接小球游戏

1.0

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

# 事件
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            # 4.退出
            pygame.quit()

    # 填充屏幕颜色
    screen.fill((80, 140, 20)) # rgb 三基色red green blue
    bally1 += 1
    ballx1 += 1
    if bally1>600:
        bally1=0
        ballx1=random.randint(0,700)
        color1 = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
        r1 = random.randint(1,100)

    bally2 += 1
    ballx2 += 1
    if bally2>600:
        bally2=0
        ballx2=random.randint(0,700)
        color2 = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
        r2 = random.randint(1,100)
    # 画小球
    pygame.draw.circle(screen,color1,(ballx1, bally1),r1)
    pygame.draw.circle(screen,color2,(ballx2, bally2),r2)

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


2.0


import pygame
import random
# 1.loading 初始化
pygame.init()
# 2.窗口   dis分开   play玩 ----》 展示
screen = pygame.display.set_mode((700, 600))
# 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,550,220,100
score = 0 # f分数
live  = 3
font = pygame.font.Font(None, 24)
# 事件
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((80, 140, 20)) # rgb 三基色red green blue
    bally1 += 1
    # ballx1 += 1
    if bally1>600:
        live = live -1
        bally1=0
        ballx1=random.randint(0,700)
        color1 = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
        r1 = random.randint(20,40)
    # 判断生命值是否用完
    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
        bally1 = 0
        ballx1 = random.randint(0, 700)

    score_text = font.render("score:%d"%score,True,(0,0,0) )
    screen.blit(score_text,(10,10))
    live_text = font.render("live:%d" % live, True, (0, 0, 0))
    screen.blit(live_text, (10, 40))
    # 画圆
    pygame.draw.circle(screen,color1,(ballx1, bally1),r1)
    # 画长方形 rect
    pygame.draw.rect(screen,(240,197,105),(ban_x, ban_y,ban_width,ban_height ) )

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




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值