用户:
超厉害的老吴查看:0 回复:0 评论:0 创建时间:2023-12-12T19:56:46
【作品展示】

【作品介绍】
用pygane做的小游戏玩法:
左右键控制嘟嘟(那只小企鹅)移动
在失败的时候按下空格键重新开始游戏
难度系数:★★★★★
【作品源代码】
import pgzrun, random, time
WIDTH = 500
HEIGHT = 700
dudu = Actor('嘟嘟')
bricks = []
direction = 3
for i in range(5):
n = random.randint(1, 4)
n_2 = random.randint(1, 2)
if i == 2:
n = random.randint(1, 3)
b.image = '踏板' + str(n)
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
dudu.x = b.x
dudu.bottom = b.top
if n_2 == 1:
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)
elif n_2 == 2:
b = Actor('踏板' + str(n) + '_' + 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)
def draw():
screen.blit('深渊喵背景', [0, 0])
dudu.draw()
for b in bricks:
b.draw()
screen.draw.text('score: ' + str(score), (20, 10))
score = 0
music.play('背景音乐')
def update():
global score, direction
if dudu.image == '嘟嘟':
score += 1
if keyboard.left:
if dudu.left > 0:
dudu.x -= 5
if keyboard.right:
if dudu.right < WIDTH:
dudu.x += 5
for b in bricks:
b.y -= 2
if len(b.image) == 5:
b.x += direction
if b.right >= WIDTH:
direction = -3
elif b.left <= 0:
direction = 3
if b.y < 0:
n_2 = random.randint(1, 2)
if n_2 == 1:
b.y = HEIGHT
n = random.randint(1, 4)
b.image = '踏板' + str(n)
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
elif n_2 == 2:
b.y = HEIGHT
n = random.randint(1, 4)
b.image = '踏板' + str(n) + '_' + str(n)
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
stand = 'no'
for b in bricks:
if b.colliderect(dudu) and dudu.bottom < b.y:
if len(b.image) == 5:
if dudu.right < WIDTH or dudu.left > 0:
dudu.x += direction
if b.image == '踏板4' or b.image == '踏板4_4':
dudu.image = '嘟嘟哭'
dudu.bottom = b.top
stand = 'yes'
if stand == 'no':
dudu.y += 8
if dudu.bottom > 700:
dudu.image = '嘟嘟哭'
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)
n_2 = random.randint(1, 2)
if i == 2:
n = random.randint(1, 3)
b.image = '踏板' + str(n)
min_x = b.width // 2
max_x = WIDTH - b.width // 2
b.x = random.randint(min_x, max_x)
dudu.x = b.x
dudu.bottom = b.top
if n_2 == 1:
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)
elif n_2 == 2:
b = Actor('踏板' + str(n) + '_' + 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)
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn