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)
binrui -接藥水遊戲3.0(原接炸藥遊戲)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.