xingtai -接小球游戏2.0

# 窗口,退出,图画,操作,战绩,,五毛特效,音乐
# 2D 游戏
import pygame
import sys
import time

# 1.加载中,初始化,loading
pygame.init()
# 2.窗口   dis分开  play玩 ---展览馆--展示
screen = pygame.display.set_mode((700, 600))

# 3。刷新  update 升级
ball_x = 350
ball_y = 300
ban_x, ban_y, ban_k, ban_g = 350, 530, 200, 70
# 设置电脑每过多少毫秒相应一次
pygame.key.set_repeat(1,1)

while True:
    # 电脑监控操作,事件
    for event in pygame.event.get():
        print(event)
        # 如果事件类型是退出,则退出游戏
        if event.type == pygame.QUIT:
            pygame.quit()  # 退出游戏
            sys.exit()  # 退出文件
        # 判断事件类型是不是按键  type类型
        elif event.type == pygame.KEYDOWN:
            # 判断你是按了什么键
            if event.key == pygame.K_a:
                ban_x = ban_x - 1
            if event.key == pygame.K_d:
                ban_x = ban_x + 1
            # if event.key == pygame.K_w:
            #     ban_y = ban_y - 1
            # if event.key == pygame.K_s:
            #     ban_y = ban_y + 1
    # 填充背景颜色 fill
    screen.fill((0, 0, 100))  # red  green  blue

    # ball_x= ball_x + 1
    ball_y = ball_y + 1
    # 判断小球有没有界面
    # if ball_x > 700:
    #     ball_x = 0
    if ball_y > 600:
        ball_y = 0

    # 空气墙
    if ban_x < 0:
        ban_x = 0
    if ban_x > 600:
        ban_x = 600
    if ban_y < -70:
        ban_y = 600
    # 向下

    # 画一个圆形
    pygame.draw.circle(screen, (0, 245, 255), (ball_x, ball_y), 50)
    # 画一个长方形:屏幕参数
    pygame.draw.rect(screen, (170, 182, 1), (ban_x, ban_y, ban_k, ban_g))
    pygame.display.update()
    time.sleep(0.001)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值