猫史档案馆


pygame入门游 戏 -> 弹球(没有图片)

用户:FexcodeFexcode查看:0 回复:1 评论:0 创建时间:2023-02-03T17:16:08


import pygame
import random

pygame.init()

screen = pygame.display.set_mode((600, 480))
pygame.display.set_caption('飞星动了')
clock = pygame.time.Clock()

speed = 2 
x, y = speed, speed

ball = pygame.Rect((0, 0), (10, 10)) 
ball.center = random.randint(10, 500), random.randint(10, 300)

board = pygame.Rect((0, 0), (60, 10))

pygame.mouse.set_visible(False)

r = True
while r:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            r = False

    if ball.bottom>473:
        r = False
    if ball.colliderect(board):
        y = -speed
    if ball.right > 600:
        x = -speed
    if ball.top <= 0:
        y = speed
    if ball.left <= 0:
        x = speed
    ball.move_ip(x, y)
    board.center = pygame.mouse.get_pos()[0], 475

    clock.tick(80)  # 在这里改速度

    screen.fill((255, 255, 255))
    pygame.draw.circle(screen, (255, 11, 122), ball.center, 10)
    pygame.draw.rect(screen, (5, 5, 5), board)

    pygame.display.update()

pygame.quit()




#去学C了,都在学C++...

可以改速度。


回复

上一页1 页 / 共 1下一页
AokenAoken

点赞0


评论