succi - 接小球2.0

# 导入专门做游戏的工具包
import pygame
import sys  # 系统工具包
import random

# 1。加载中,初始化
pygame.init()
# 2.设置一个窗口大小   dis=分开  play=玩  display展示
screen_height = 600  # 窗口高度
screen_width = 700  # 窗口宽度
screen = pygame.display.set_mode((screen_width, screen_height))
# 3.设置标题
pygame.display.set_caption("接下球游戏")

# 两个变量
ball_x = 350
ball_y = 300
# 板的位置信息
ban_w, ban_h = 120, 50
ban_x, ban_y = screen_width/2, screen_height - ban_h

# 文字1.0 设置文字字体
font = pygame.font.Font("FZSJ-OXKAJW.TTF", 24)

# 分数变量
fen_shu = 0

# 5.无限循环
while True:
    # 电脑监控操作1.0   事件:点击鼠标,移动鼠标,按键
    # event 事件
    for event in pygame.event.get():
        # print(event)
        # 判断是否点击退出 type类型 kind
        if event.type == pygame.QUIT:
            # quit 游戏退出
            pygame.quit()
            # exit 退出
            sys.exit()
        elif event.type == pygame.MOUSEMOTION:
            ban_x, _ = event.pos

    # 背景填充颜色 fill
    screen.fill((225, 30, 35))
    ball_y = ball_y + 1
    if ball_y > screen_height:
        ball_y = 0
        ball_x = random.randint(0, screen_width)

    if ban_x<ball_x<ban_x+ban_w and ban_y<ball_y<ban_y+ban_h:
        fen_shu = fen_shu + 1
        ball_y = 0
        ball_x = random.randint(0, screen_width)


    # 小球 1.0: 参数:窗口/屏幕;颜色 rgb;坐标(x,y);
    pygame.draw.circle(screen, (0, 0, 0), (ball_x, ball_y), 10)
    # 画一个板 : 参数:窗口/屏幕;颜色 rgb;位置信息(x,y,宽,高);
    pygame.draw.rect(screen, (255, 255, 255), (ban_x, ban_y, ban_w, ban_h ))
    # 文字2.0 设置文字内容
    content = font.render("分数:%d"%fen_shu,True,(0,0,0))
    # 文字3.0 把文字放到窗口上  blit 传送
    screen.blit(content, (0, 0))

    # 4.刷新
    pygame.display.update()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值