import random
import pygame
import sys
import time
# 1。加载中 loading 初始化
pygame.init()
# 2.设置窗口大小 dis分开 展览馆 展示 (宽,高)
screen = pygame.display.set_mode((890, 550))
# 4.设置标题
pygame.display.set_caption("接炸药游戏")
ball_x = 445
ball_y = 300
rect_w, rect_h = 150, 25
rect_x, rect_y = 300, 525
# 文1.0 设置文字类型和大小 font 字体
font = pygame.font.Font("ziti.ttf", 50)
# 图1.0 加载图片 image 图片 load 加载
boom = pygame.image.load("boom.jpg")
# 分数
score = 0
# 3.刷新
while True:
# 电脑监控我们的操作
# event 事件 pos position 位置
for event in pygame.event.get():
# print(event)
# 判断事件类型是不是退出
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
# 画小球: 窗口, 颜色 rgb , 位置(x,y)
# pygame.draw.circle(screen, (135, 206, 250), (ball_x, ball_y), 20)
# 画长方形: 窗口, 颜色 rgb , (x, y, 长,宽)
pygame.draw.rect(screen, (0, 255, 0), (rect_x, rect_y, rect_w, rect_h ))
# 文2.0 设置文字内容和颜色
text = font.render("分数:%d"%score, True, (0, 0, 0))
# 文3.0 将文字放到窗口上 blit传送
screen.blit(text, (10, 10))
# 图2.0 将图片放到窗口上 blit传送
screen.blit(boom, (ball_x, ball_y))
pygame.display.update()
# time.sleep(1)
binrui - 接炸药游戏2.0
猜你喜欢
转载自blog.csdn.net/houlaos/article/details/105419692
今日推荐
周排行