import random
import pygame
import sys
import time
pygame.init()
screen = pygame.display.set_mode((890, 550))
pygame.display.set_caption("接炸药游戏")
ball_x = 445
ball_y = 300
rect_w, rect_h = 150, 25
rect_x, rect_y = 300, 525
font = pygame.font.Font("ziti.ttf", 50)
boom = pygame.image.load("boom.jpg")
score = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEMOTION:
rect_x, _ = event.pos
screen.fill((250, 240, 230))
ball_y = ball_y + 1
if ball_y > 500:
ball_y = 50
ball_x = random.randint(50, 800)
score = score + 1
pygame.draw.rect(screen, (0, 255, 0), (rect_x, rect_y, rect_w, rect_h ))
text = font.render("分数:%d"%score, True, (0, 0, 0))
screen.blit(text, (10, 10))
screen.blit(boom, (ball_x, ball_y))
pygame.display.update()