用户:
Fexcode查看: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++...
可以改速度。