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)
上一篇:一个演奏乐曲的趣味小程序


下一篇:leetcode: 600. Non-negative Integers without Consecutive Ones