孩子的第三个作品:
from pgzrun import * music.play("麻宫雅典娜.mp3") WIDTH = 1280 HEIGHT = 720
bg = Actor("bg.png") #{ jump_speed1 = 12 jump1 = False jump_speed2 = 12 jump2 = False #---------------------------------------------------------------- life_show1 = Actor("life_show1.png", [120, 50]) shoot1 = False
life_show2 = Actor("life_show2.png", [1150, 50]) shoot2 = False #}
win_1 = Actor("win_1.png", [3000, 360]) win_2 = Actor("win_2.png", [3000, 360])
ninja1 = Actor("角色5.png", [200, 460])? ninja2 = Actor("角色6.png", [1080, 460])?
dart1 = Actor("武器2.png", [1500, 300]) dart2 = Actor("武器6.png", [1500, 300])
life1 = 20 life2 = 20
def draw(): ? ? bg.draw()
? ? ninja1.draw() ? ? ninja2.draw() ? ? dart1.draw() ? ? dart2.draw() ? ?? ? ? life_show1.draw() ? ? life_show2.draw() ? ? screen.draw.text(str(life1), [120, 32], color='white', fontsize=35,fontname="ziti.ttf") ? ? screen.draw.text(str(life2), [1120, 32], color='white', fontsize=35,fontname="ziti.ttf") ? ? win_1.draw() ? ? win_2.draw()
def update(): ? ? global jump1, jump_speed1, jump2, jump_speed2, shoot1, shoot2, life1, life2 ? ? #ninja1的跳跃逻辑 ? ? #{ ? ? if keyboard.w == True: ? ? ? ? jump1 = True
? ? if jump1 == True: ? ? ? ? ninja1.y = ninja1.y - jump_speed1 ? ? ? ? jump_speed1 = jump_speed1 - 0.28
? ? ? ? if ninja1.bottom > 560: ? ? ? ? ? ? ninja1.bottom = 560 ? ? ? ? ? ? jump1 = False ? ? ? ? ? ? ? jump_speed1 = 12?
? ?? ? ? if keyboard.a == True: ? ? ? ? ninja1.x = ninja1.x - 6 ? ? elif keyboard.d == True: ? ? ? ? ninja1.x = ninja1.x + 6 ? ? #} ? ? ? ? dart1.angle = dart1.angle + 8 ? ? dart2.angle = dart2.angle + 8 ? ?? ? ? if keyboard.s == True: ? ? ? ? shoot1 = True ? ? ? ? dart1.x = ninja1.x - 88 ? ? ? ? dart1.y = ninja1.y - 15 ? ? ? ? sounds.shoot.play() ? ? ? ?? ? ? if shoot1 == True: ? ? ? ? ? ? ? ? dart1.x = dart1.x + 18 ? ? ? if dart1.colliderect(ninja2): ? ? ? ? life2 = life2 - 1 ? ? ? ? dart1.left = 2000 ? ? ? ? sounds.hit.play() ? ?? ? ? if life2 == 0 : ? ? ? ? win_1.left = 0 ? ? ? ? music.stop() ? ? # ---------------------------------------------------------------------------------------------------------------# ? ? #ninja2的跳跃逻辑 ? ? #{ ? ? if keyboard.up == True: ? ? ? ? jump2 = True ? ?? ? ? if jump2 == True: ? ? ? ? ninja2.y = ninja2.y - jump_speed2 ? ? ? ? jump_speed2 = jump_speed2 - 0.28
? ? ? ? if ninja2.bottom > 573: ? ? ? ? ? ? ninja2.bottom = 573 ? ? ? ? ? ? jump2 = False ? ? ? ? ? ? jump_speed2 = 12 ? ?? ? ? if keyboard.left == True: ? ? ? ? ninja2.x = ninja2.x - 6 ? ? elif keyboard.right == True: ? ? ? ? ninja2.x = ninja2.x + 6 ? ? #} ? ?? ? ? #ninja2的飞镖发射以及输赢规则 ? ? if keyboard.down == True: ? ? ? ? sounds.shoot.play() ? ? ? ? shoot2 = True ? ? ? ? dart2.x = ninja2.x + 70 ? ? ? ? dart2.y = ninja2.y - 50 ? ? if shoot2 == True: ? ? ? ? dart2.x = dart2.x - 18 ? ? ? ?? ? ? if dart2.colliderect(ninja1): ? ? ? ? life1 = life1 - 1 ? ? ? ? dart2.right = -1000 ? ? ? ? sounds.hit.play() ? ? if life1 == 0: ? ? ? ? win_2.left = 0 ? ? ? ? music.stop() go()
|