猫史档案馆


【Python作品分享】捡金币【作品秀】

用户:刘骏森刘骏森查看:0 回复:0 评论:0 创建时间:2021-12-19T15:06:18


【作品展示】

center_image

 

【作品介绍】

按下鼠标跳跃

 

【作品源代码】

import pgzrun
from random import randint


WIDTH = 喵0
HEIGHT = 360
jump = False
jump_state = 'up'
move_speed = 5
game = 'start'
score = 0

mao = Actor('mao_walk1',(100,HEIGHT - 58))

coin = Actor('coin')
coin.pos = 1000, 300


def draw():

    screen.blit('rainbow', (0, 0))
    screen.draw.text('Score:' + str(score), color='blue',
                     topleft=(10, 10), fontsize=40)
    mao.draw()
    coin.draw()
    if coin.x < 0:
        screen.draw.text('Game over',color='red',
                    topleft=(WIDTH / 2,HEIGHT / 2),fontsize=70)
        mao.image = "mao_end"
        game = 'over'


def on_mouse_down():

    global jump
    jump = True 

def mao_jump():
    
    global jump,jump_state
    if jump_state == 'up':
        mao.image = "mao_jump"
        mao.y -= 5
        if mao.y <= HEIGHT / 2 - 10:
            jump_state = 'down'
    elif jump_state == 'down':
        mao.image = "mao_walk1"
        mao.y += 5
        if mao.y == HEIGHT - 58:
            jump = False
            jump_state = 'up'

def update():

    global score
    if game != 'over':
        coin.x -= move_speed
    if jump:
        mao_jump()
    if mao.colliderect(coin):
        if coin.x > 0:
            score += 1
        coin.x = randint(800,3000)
        coin.y = randint(150,200)
    

pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页