binrui -接药水游戏3.0(原接炸药游戏)

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, 50
rect_x, rect_y = 300, 525

# 文1.0 设置文字类型和大小  font 字体
letter_style = pygame.font.Font("ziti.ttf", 50)
# 图1.0 加载图片  image 图片   load 加载
boom = pygame.image.load("隐身药水.jpg")

# 分数
score = 0
# point hit
ph = 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 + 2
    if ball_y > 550:
        ball_y = 50
        ball_x = random.randint(50, 800)

    # 判断接到炸药?
    # 板的x坐标《球的x坐标 < 板的x坐标+宽度
    # print(ball_x, ball_y)
    # print(rect_x, rect_y)
    if rect_x + rect_w > ball_x > rect_x and rect_y + rect_h > ball_y >rect_y:
        score = score + 1
        ball_y = 50
        ball_x = random.randint(50, 800)
    # 画小球: 窗口, 颜色 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 = letter_style.render("分数:%d" % score, True, (0, 0, 0))
    text2 = letter_style.render("生命值:%d" % ph, True, (0, 0, 0))
    # 文3.0 将文字放到窗口上  blit传送
    screen.blit(text, (10, 10))
    screen.blit(text2, (10, 60))
    # 图2.0 将图片放到窗口上 blit传送
    screen.blit(boom, (ball_x, ball_y))

    pygame.display.update()
    # time.sleep(1)










发布了613 篇原创文章 · 获赞 21 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/105566731