用户:糖果PB查看:0 回复:0 评论:0 创建时间:2022-09-06T22:03:02
【作品展示】

【作品介绍】
很好玩
【作品源代码】
from random import randint
import pgzrun
WIDTH = 800
HEIGHT = 600
score = 0
game_state = 'b'
box_width = [randint(40, 120), randint(40, 120),
randint(40, 120), randint(40, 120)]
box_height = [randint(20, 130), randint(20, 130),
randint(20, 130), randint(20, 130)]
box = [Rect(WIDTH + 100, randint(0, HEIGHT - box_height[0]), box_width[0], box_height[0]),
Rect(WIDTH + 250, randint(0, HEIGHT - box_height[1]), box_width[1], box_height[1]),
Rect(WIDTH + 300, randint(0, HEIGHT - box_height[2]), box_width[2], box_height[2]),
Rect(WIDTH + 350, randint(0, HEIGHT - box_height[3]), box_width[3], box_height[3])]
box2 = Rect(50, 360, 60, 60)
time = 60
state = ''
button1 = Actor('button1', (300, 300))
button2 = Actor('button2', (500, 300))
def box_value(value):
box[value].x = WIDTH + randint(20, 400)
box[value].y = randint(20, 400)
box_width[value] = randint(40, 120)
box_height[value] = randint(20, 130)
def draw():
global game_state, score, state
if game_state == 'b':
screen.fill('yellow')
button1.draw()
button2.draw()
elif game_state == 's':
screen.fill('yellow')
if state == '1':
screen.draw.text('Dodge Blocks', center=(400, 300),
color='dodgerblue', fontsize=100)
else:
screen.draw.text('Eliminate Blocks', center=(400, 300),
color='dodgerblue', fontsize=100)
if keyboard.space:
game_state = 'p'
music.play('bg_music3')
elif game_state == 'p':
screen.fill('gold')
screen.draw.filled_rect(box2, 'red')
screen.draw.text('Score:' + str(score), center=(70, 20),
color='dodgerblue', fontsize=50)
screen.draw.text('Time Left:' + str(time), center=(110, 55),
color='dodgerblue', fontsize=50)
for i in range(len(box)):
screen.draw.filled_rect(box[i], 'orange')
elif game_state == 'go':
screen.fill('gold')
screen.draw.text('Game Over', center=(400, 300),
color='dodgerblue', fontsize=100)
music.pause()
if score > 50:
screen.fill('gold')
screen.draw.text('You Win!', center=(400, 300),
color='dodgerblue', fontsize=100)
music.pause()
music.play_once('success')
score = 0
game_state = 'Win'
def update_time_left():
global game_state, time
if game_state == 'p':
if time > 0:
time -= 1
else:
game_state = 'go'
def update():
global game_state, score, state
if game_state == 'p':
if state == '1':
for i in range(len(box)):
box[i].x -= 5 + score // 10
if box[i].x < 0 - box_height[i]:
box_value(i)
score += 1
elif box[i].colliderect(box2):
game_state = 'go'
if keyboard.w:
box2.y -= 5
elif keyboard.s:
box2.y += 5
elif state == '2':
for i in range(len(box)):
box[i].x -= 5 + score // 10
if box[i].x < 0 - box_height[i]:
box_value(i)
elif box2.colliderect(box[i]):
box_value(i)
score += 1
if keyboard.w:
box2.y -= 5
elif keyboard.s:
box2.y += 5
def on_mouse_down(pos):
global state, game_state
if game_state == 'b':
if button1.collidepoint(pos):
state = '1'
game_state = 's'
elif button2.collidepoint(pos):
state = '2'
game_state = 's'
clock.schedule_interval(update_time_left, 1)
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn