import pygame
import time
import random
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption("蔡旭坤大招乔碧落")
ball_x = 300
ball_y = 250
rect_x, rect_y, rect_w, rect_h = 300, 460, 120, 40
font1 = pygame.font.Font(None, 24)
score = 0
lives = 3
def ball(ball_x, ball_y):
pygame.draw.circle(screen, (255., 25, 52), (ball_x, ball_y), 20, 0)
while True:
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == pygame.MOUSEMOTION:
rect_x, _ = event.pos
screen.fill((34, 177, 135))
ball_y = ball_y + 1
if ball_y > 500:
ball_y = 0
ball_x = random.randint(0, 600)
lives = lives -1
ball(ball_x, ball_y)
if rect_x < ball_x < rect_x + rect_w and rect_y < ball_y < rect_y + rect_h:
score = score + 1
ball_y = 0
ball_x = random.randint(0, 600)
Text_score = font1.render('score:%d' % score, True, (0, 0, 0))
screen.blit(Text_score, (0, 0))
Text_lives = font1.render('lives:%d' % lives, True, (0, 0, 0))
screen.blit(Text_lives, (530, 0))
pygame.draw.rect(screen, (100, 200, 30), (rect_x, rect_y, rect_w, rect_h), 0)
pygame.display.update()
pygame.quit()