猫史档案馆


【Python作品分享】见缝插针【作品秀】

用户:嘉速度嘉速度查看:0 回复:0 评论:0 创建时间:2021-10-24T17:46:53


【作品展示】

center_image

 

【作品介绍】

游戏规则:失败后,必须退出才能从新开始游戏

 

【作品源代码】

import pgzrun
TITLE = "Pytho见缝插针 ----by 炫宇"

starNeedle = Actor('needle', anchor=(170+50,1.5))
starNeedle.x = 200
starNeedle.y = 300
needles = []


rotateSpeed = 1 # 旋转速度,默认是1,后面游戏结束后改为0
score = 0 # 游戏得分

def draw():
    screen.fill('yellow')
    starNeedle.draw()    
    for needle in needles:
        needle.draw()
    screen.draw.filled_circle((400, 300), 80, 'red')
    screen.draw.text(str(score), (50, 250), fontsize = 50, color = 'green')
    
    if rotateSpeed == 0:
        screen.draw.text("Game Over!",(10, 320),fontsize=35,color="red")

def update():
    for needle in needles:
        needle.angle += rotateSpeed

def on_key_down():
    global rotateSpeed, score
    if rotateSpeed >0:
        music.play_once('弹簧')

    newNeedle = Actor('needle', anchor=(170+50, 1.5))
    newNeedle.x = 400
    newNeedle.y = 300
    
    for needle in needles:
        if newNeedle.colliderect(needle):
            print('游戏失败')
            rotateSpeed = 0
            music.play_once('溜走')
        if rotateSpeed > 0:
            score += 1

    needles.append(newNeedle)

pgzrun.go()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页