用户:定理查看:0 回复:1 评论:0 创建时间:2021-11-27T20:29:25
【作品展示】

【作品介绍】
飞机大战
【作品源代码】
import pgzrun
import random
WIDTH = 480
HEIGHT = 852
TITLE = '王牌战争'
background1 = Actor('background')
background1.x = WIDTH/2
background1.y = HEIGHT/2
background2 = Actor('background')
background2.x = WIDTH/2
background2.y = -HEIGHT/2
hero = Actor('hero')
hero.x = WIDTH/2
hero.y = HEIGHT*2/3
bullet = Actor('bullet')
bullet.x = 30000
bullet.y = 30000
enemy = Actor('enemy')
enemy.x = WIDTH/2
score = 0
sky = 2
isLoose = False
sounds.game_music.play(-1)
def draw():
background1.draw()
background2.draw()
hero.draw()
bullet.draw()
enemy.draw()
screen.draw.text("得分:"+str(score), (240, 500),
fontsize=30, fontname='s', color='black')
screen.draw.text("等级:999",(30,30),fontsize=20,
fontname='s',color='yellow')
if isLoose:
screen.draw.text('喵!', (50, HEIGHT/2), fontsize=300,
fontname='s', color='red')
def on_key_down():
if isLoose:
return
bullet.x = hero.x
bullet.y = hero.y
sounds.喵.play()
def update():
global score, sky, isLoose
if isLoose:
return
if background1.y > HEIGHT/2+HEIGHT:
background1.y = -HEIGHT/2
if background2.y > HEIGHT/2+HEIGHT:
background2.y = -HEIGHT/2
background1.y = background1.y+1
background2.y = background2.y+1
bullet.y = bullet.y-50
enemy.y = enemy.y+sky
if enemy.y > HEIGHT:
enemy.y = 0
enemy.x = random.randint(0, WIDTH)
if bullet.colliderect(enemy):
enemy.y = 0
enemy.x = random.randint(0, WIDTH)
score = score+1
bullet.y = -3780
sky = sky+1
sounds.got_enemy.play()
if hero.colliderect(enemy):
isLoose = True
hero.image = 'hero_blowup'
sounds.explode.play()
def on_mouse_move(pos, buttons):
if isLoose:
return
hero.x = pos[0]
hero.y = pos[1]
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn