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 =
445ball_y =
300rect_w, rect_h =
150,
50rect_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 +
2if 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 接炸藥遊戲2 0
import random import pygame import sys import time 1。載入中 loading 初始化 pygame.init 2.設定視窗大小 dis分開 展覽館 展示 寬,高 screen pygame.display.set mode 890 550 4.設定...
junjie 接小球遊戲3 0
import pygame import random defqiu bally,speedy,ballx,speedx,r,g,b bally bally speedy ballx ballx speedx if bally 0 speedy 1if ballx chuang kou kuan s...
junjie 接小球遊戲
import pygame import random import time python game loading.初始化.載入中.pygame.init 介面遊戲 dis 分開 play玩 diaplay 展覽展示的意思 set設定 mode模式 chuang kou pygame.displ...