aden -接球游戏3.0

import pygame
import time
# 游戏初始化
pygame.init()
# 设置窗口大小  640长度  窗口宽度500
screen = pygame.display.set_mode((640, 500))
# 设置窗口标题
pygame.display.set_caption("坦福版接球游戏")

# 文字1. 设置文字字体和大小
font = pygame.font.SysFont("SimHei", 35)


a = 200
b = 200
board_x = 400
board_y = 320
speedy = 1
speedx = 1
while 1 < 100:
    # 事件:我们对电脑的物理操作,按键,鼠标(按键,移动)
    for event in pygame.event.get():
        # print(event)
        if event.type == pygame.QUIT:
            pygame.quit() # 退出游戏
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_a:
                board_x = board_x - 10
            if event.key == pygame.K_d:
                board_x = board_x + 10
        elif event.type == pygame.MOUSEMOTION:
            board_x,board_y = event.pos

    screen.fill((0, 0, 0))
    b = b + speedy
    a = a + speedx
    if a > 640:
        speedx = -1
    elif a< 0:
        speedx = 1



    if b > 640:
        b = 0
    if b < 0:
        speedy = 1

    if board_x< a<board_x + 200 and board_y < b < board_y+10:
        speedy = -1



    # 画小球:屏幕,rgb三基色,坐标,半径
    pygame.draw.circle(screen,(200,200,200),(a,b), 23)
    # time.sleep(1)
    #  画一个长方形 pygame.draw.rect(屏幕,(r,g,b),(经度,维度,板长,板宽))
    pygame.draw.rect(screen,(105,105,150),(board_x,board_y,200,10))

    # 2.设置文字的内容和颜色
    font2 = font.render("蔡徐坤", True, (0,255,0))
    # 3.把文字放在窗口上
    screen.blit(font2, (100,100))


    # 刷新
    pygame.display.update()




猜你喜欢

转载自blog.csdn.net/houlaos/article/details/106554694
今日推荐