用户:
癫才喵查看:0 回复:1 评论:0 创建时间:2024-08-17T11:31:04
【作品展示】

【作品介绍】
【作品源代码】
import pgzrun
import random
WIDTH = 500
HEIGHT = 700
dudu = Actor('嘟嘟')
score = 0
music.play('背景音乐')
direction = 3
bricks = []
for i in range(5):
n = random.randint(1, 4)
b = Actor('踏板' + str(n))
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
b.y = 140 * (i + 1)
bricks.append(b)
if i == 2:
dudu.x = b.x
dudu.bottom = b.top
b.image = '踏板1'
def draw():
global score
screen.blit('背景', [0, 0])
dudu.draw()
for brick in bricks:
brick.draw()
screen.draw.text(str(score), (20, 10))
def update():
global score, direction
if dudu.image == '嘟嘟':
score += 1
on_brick = 0
for b in bricks:
b.y -= 3
if b.image == '踏板2':
b.x += direction
if b.right >= WIDTH:
direction = -3
elif b.left <= 0:
direction = 3
if b.y < 0:
n = random.randint(1, 4)
b.image = '踏板' + str(n)
b.y = HEIGHT
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
for b in bricks:
if dudu.colliderect(b) and dudu.bottom < b.bottom:
dudu.bottom = b.top
on_brick = 1
if b.image == '踏板4':
dudu.image = '嘟嘟哭'
if b.image == '踏板2':
dudu.x += direction
if dudu.right >= WIDTH:
direction = -3
elif dudu.left <= 0:
direction = 3
if on_brick == 0:
dudu.y += 8
if dudu.bottom > HEIGHT:
dudu.image = '嘟嘟哭'
if keyboard.left:
if dudu.left > 0:
dudu.x -= 5
if keyboard.right:
if dudu.right < WIDTH:
dudu.x += 5
if dudu.image == '嘟嘟哭':
music.stop()
def on_key_down(key):
if key == keys.SPACE and dudu.image == '嘟嘟哭':
global score, bricks
music.play('背景音乐')
dudu.image = '嘟嘟'
bricks = []
score = 0
for i in range(5):
n = random.randint(1, 4)
b = Actor('踏板' + str(n))
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
b.y = 140 * (i + 1)
bricks.append(b)
if i == 2:
b.image = '踏板1'
dudu.x = b.x
dudu.bottom = b.top
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cnimport pgzrun
import random
WIDTH = 500
HEIGHT = 700
dudu = Actor('嘟嘟')
score = 0
music.play('背景音乐')
direction = 3
bricks = []
for i in range(5):
n = random.randint(1, 4)
b = Actor('踏板' + str(n))
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
b.y = 140 * (i + 1)
bricks.append(b)
if i == 2:
dudu.x = b.x
dudu.bottom = b.top
b.image = '踏板1'
def draw():
global score
screen.blit('背景', [0, 0])
dudu.draw()
for brick in bricks:
brick.draw()
screen.draw.text(f'Score: {score}', (20, 10))
if dudu.image == '嘟嘟哭':
screen.draw.text('Game Over! Press SPACE to restart.', (WIDTH // 2 - 120, HEIGHT // 2), color='red')
def update():
global score, direction
if dudu.image == '嘟嘟':
score += 1
on_brick = 0
for b in bricks:
b.y -= 3
if b.image == '踏板2':
b.x += direction
if b.right >= WIDTH:
direction = -3
elif b.left <= 0:
direction = 3
if b.y < 0:
n = random.randint(1, 4)
b.image = '踏板' + str(n)
b.y = HEIGHT
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
for b in bricks:
if dudu.colliderect(b) and dudu.bottom < b.bottom:
dudu.bottom = b.top
on_brick = 1
if b.image == '踏板4':
dudu.image = '嘟嘟哭'
if b.image == '踏板2':
dudu.x += direction
if dudu.right >= WIDTH:
direction = -3
elif dudu.left <= 0:
direction = 3
if on_brick == 0:
dudu.y += 8
if dudu.bottom > HEIGHT:
dudu.image = '嘟嘟哭'
if keyboard.left and dudu.left > 0:
dudu.x -= 5
if keyboard.right and dudu.right < WIDTH:
dudu.x += 5
if dudu.image == '嘟嘟哭':
music.stop()
def on_key_down(key):
if key == keys.SPACE and dudu.image == '嘟嘟哭':
restart_game()
def restart_game():
global score, bricks
music.play('背景音乐')
dudu.image = '嘟嘟'
dudu.y = HEIGHT // 2
score = 0
bricks.clear()
for i in range(5):
n = random.randint(1, 4)
b = Actor('踏板' + str(n))
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
b.y = 140 * (i + 1)
bricks.append(b)
if i == 2:
dudu.x = b.x
dudu.bottom = b.top
b.image = '踏板1'
pgzrun.go() 修改内容:
点赞0
评论