猫史档案馆


【Python作品分享】飞机大战

用户:老牛LUg5老牛LUg5查看:0 回复:0 评论:0 创建时间:2021-04-24T08:59:15


【作品展示】

center_image

 

【作品介绍】

测试

 

【作品源代码】

import pgzrun,random
WIDTH=480
HEIGHT=700
TITLE='牛哥飞机大战'

enemy=Actor('enemy')
enemy.x=WIDTH/2
enemy.y=0

background1=Actor('background')
background1.x=480/2
background1.y=852/2
background2 = Actor('background')
background2.x=480/2
background2.y=-852/2

bullet=Actor('bullet')
bullet.x=WIDTH/2
bullet.y=-HEIGHT

hero = Actor('hero')
hero.x=WIDTH/2
hero.y=HEIGHT * 2/3

score=0

isloose=False

def draw():
    background1.draw()
    background2.draw()
    hero.draw()
    bullet.draw()
    enemy.draw()
    screen.draw.text("得分:"+str(score),(200,HEIGHT-50),fontsize=30,fontname='s',color='black')
    if isloose:
        screen.draw.text('游戏失败',(50,HEIGHT/2),fontsize=90,fontname='s',color='red')

def update():
    global score,isloose
    if isloose:
        return

    if background1.y > 852/2+852:
        background1.y=-852/2
    if background2.y > 852/2+852:
        background2.y=-852/2
    bullet.y=-HEIGHT
    background1.y += 1
    background2.y += 1
    
    if bullet.y>-HEIGHT:
        bullet.y=bullet.y - 10

    enemy.y +=3
    if enemy.y>HEIGHT:
        enemy.y=0
        enemy.x=random.randint(50,WIDTH-50)
    
    if bullet.colliderect(enemy):
        enemy.y = 0
        enemy.x = random.randint(0, WIDTH)
        score = score + 1
        bullet.y = -HEIGHT

    if hero.colliderect(enemy):
        isloose = True
        hero.image = 'hero_blowup'

def on_mouse_move(pos,rel,buttons):
    if isloose:
        return
    hero.x=pos[0]
    hero.y=pos[1]

def on_mouse_down():
    if isloose:
        return
    bullet.x = hero.x
    bullet.y = hero.y-70

pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页