24浏览
查看: 24|回复: 3

[项目] 【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏

[复制链接]
Kitronik ARCADE 是一款由英国教育科技公司 Kitronik 精心打造的可编程游戏机开发板,专为编程教学与创客实践而设计。该设备原生支持微软的 MakeCode Arcade 平台,用户可通过图形化或 JavaScript 编程方式,轻松创建、下载并运行复古风格的街机游戏。

它集成了彩色 LCD 显示屏、方向控制键、功能按键、蜂鸣器和震动马达等交互组件,提供完整的游戏输入输出体验。无论是初学者进行编程启蒙,还是创客群体开发交互式作品,Kitronik ARCADE 都能作为理想的硬件载体,助力创意实现。

凭借其开源友好、易于上手、兼容性强等特点,该开发板广泛应用于中小学编程课程、创客工作坊、游戏开发教学以及个人项目原型设计,深受教育者与技术爱好者的喜爱。

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图1

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图2

驴友花雕  中级技神
 楼主|

发表于 昨天 18:16

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏

作为学习、练习与尝试,这里创建一个Boss 冲刺的小游戏。
打开网页版:https://arcade.makecode.com/,设置项目名称:Boss 冲刺

MicroPython实验代码

  1. @namespace
  2. class SpriteKind:
  3.     Boss = SpriteKind.create()
  4.     BossProjectile = SpriteKind.create()
  5.     Camera = SpriteKind.create()
  6. """
  7. BERTHA
  8. """
  9. """
  10. DARYL
  11. """
  12. def createBoss(current: number):
  13.     global bossSpeed, bossHealth, timeBetweenBossFire, timeBetweenBossMove, theBoss, cameraSpeed, lastBossFireTime, bossHealthThreshold, bossLocations, currentFireIndex, darylHorizontalSpeed
  14.     if current == 0:
  15.         bossSpeed = 50
  16.         bossHealth = 100
  17.         timeBetweenBossFire = 100
  18.         timeBetweenBossMove = 2000
  19.         theBoss = sprites.create(img("""
  20.                 cccccccccccccccccccccccc
  21.                 cccccccccccccccccccccccc
  22.                 cccccccccccccccccccccccc
  23.                 cccccccccccccccccccccccc
  24.                 cccccccccccccccccccccccc
  25.                 cccccccccccccccccccccccc
  26.                 cccccccccccccccccccccccc
  27.                 cccccccccccccccccccccccc
  28.                 cccccccccccccccccccccccc
  29.                 cccccccccccccccccccccccc
  30.                 cccccccccccccccccccccccc
  31.                 cccccccccccccccccccccccc
  32.                 cccccccccccccccccccccccc
  33.                 cccccccccccccccccccccccc
  34.                 cccccccccccccccccccccccc
  35.                 cccccccccccccccccccccccc
  36.                 cccccccccccccccccccccccc
  37.                 cccccccccccccccccccccccc
  38.                 cccccccccccccccccccccccc
  39.                 cccccccccccccccccccccccc
  40.                 cccccccccccccccccccccccc
  41.                 cccccccccccccccccccccccc
  42.                 cccccccccccccccccccccccc
  43.                 cccccccccccccccccccccccc
  44.                 cccccccccccccccccccccccc
  45.                 cccccccccccccccccccccccc
  46.                 cccccccccccccccccccccccc
  47.                 cccccccccccccccccccccccc
  48.                 cccccccccccccccccccccccc
  49.                 cccccccccccccccccccccccc
  50.                 cccccccccccccccccccccccc
  51.                 cccccccccccccccccccccccc
  52.                 cccccccccccccccccccccccc
  53.                 cccccccccccccccccccccccc
  54.                 cccccccccccccccccccccccc
  55.                 cccccccccccccccccccccccc
  56.                 cccccccccccccccccccccccc
  57.                 cccccccccccccccccccccccc
  58.                 cccccccccccccccccccccccc
  59.                 cccccccccccccccccccccccc
  60.                 cccccccccccccccccccccccc
  61.                 cccccccccccccccccccccccc
  62.                 cccccccccccccccccccccccc
  63.                 cccccccccccccccccccccccc
  64.                 cccccccccccccccccccccccc
  65.                 cccccccccccccccccccccccc
  66.                 cccccccccccccccccccccccc
  67.                 cccccccccccccccccccccccc
  68.                 """),
  69.             SpriteKind.Boss)
  70.         theBoss.set_position(145, 58)
  71.         theBoss.set_velocity(0, 50)
  72.         resetHealth()
  73.     elif current == 1:
  74.         if bossHealth == 0:
  75.             bossHealth = 100
  76.             resetHealth()
  77.         cameraSpeed = 20
  78.         theBoss = sprites.create(img("""
  79.                 b b b b b
  80.                 b b b b b
  81.                 b b b b b
  82.                 b b b b b
  83.                 b b b b b
  84.                 """),
  85.             SpriteKind.Boss)
  86.         theBoss.set_flag(SpriteFlag.GHOST_THROUGH_WALLS, True)
  87.         theBoss.set_position(12, 59)
  88.         lastBossFireTime = game.runtime()
  89.         animation.run_image_animation(theBoss,
  90.             [img("""
  91.                     6666666666666666
  92.                     6666666666666666
  93.                     6666666666666666
  94.                     6666666666666666
  95.                     6666666666666666
  96.                     6666666666666666
  97.                     6666666666666666
  98.                     6666666666666666
  99.                     6666666666666666
  100.                     6666666666666666
  101.                     6666666666666666
  102.                     6666666666666666
  103.                     6666666666666666
  104.                     6666666666666666
  105.                     6666666666666666
  106.                     6666666666666666
  107.                     6666666666666666
  108.                     6666666666666666
  109.                     6666666666666666
  110.                     6666666666666666
  111.                     6666666666666666
  112.                     6666666666666666
  113.                     6666666666666666
  114.                     6666666666666666
  115.                     6666666666666666
  116.                     6666666666666666
  117.                     6666666666666666
  118.                     6666666666666666
  119.                     6666666666666666
  120.                     6666666666666666
  121.                     6666666666666666
  122.                     6666666666666666
  123.                     6666666666666666
  124.                     6666666666666666
  125.                     6666666666666666
  126.                     6666666666666666
  127.                     6666666666666666
  128.                     6666666666666666
  129.                     6666666666666666
  130.                     6666666666666666
  131.                     6666666666666666
  132.                     6666666666666666
  133.                     6666666666666666
  134.                     6666666666666666
  135.                     6666666666666666
  136.                     6666666666666666
  137.                     6666666666666666
  138.                     6666666666666666
  139.                     """),
  140.                 img("""
  141.                     ................
  142.                     ................
  143.                     ................
  144.                     ................
  145.                     ................
  146.                     ................
  147.                     ................
  148.                     ................
  149.                     ................
  150.                     ................
  151.                     ................
  152.                     ................
  153.                     ................
  154.                     ................
  155.                     ................
  156.                     ................
  157.                     ................
  158.                     ................
  159.                     ................
  160.                     ................
  161.                     ................
  162.                     ................
  163.                     ................
  164.                     ................
  165.                     ................
  166.                     ................
  167.                     ................
  168.                     ................
  169.                     ................
  170.                     ................
  171.                     ................
  172.                     ................
  173.                     ................
  174.                     ................
  175.                     ................
  176.                     ................
  177.                     ................
  178.                     ................
  179.                     ................
  180.                     ................
  181.                     ................
  182.                     ................
  183.                     ................
  184.                     ................
  185.                     ................
  186.                     ................
  187.                     ................
  188.                     ................
  189.                     """),
  190.                 img("""
  191.                     6666666666666666
  192.                     6666666666666666
  193.                     6666666666666666
  194.                     6666666666666666
  195.                     6666666666666666
  196.                     6666666666666666
  197.                     6666666666666666
  198.                     6666666666666666
  199.                     6666666666666666
  200.                     6666666666666666
  201.                     6666666666666666
  202.                     6666666666666666
  203.                     6666666666666666
  204.                     6666666666666666
  205.                     6666666666666666
  206.                     6666666666666666
  207.                     6666666666666666
  208.                     6666666666666666
  209.                     6666666666666666
  210.                     6666666666666666
  211.                     6666666666666666
  212.                     6666666666666666
  213.                     6666666666666666
  214.                     6666666666666666
  215.                     6666666666666666
  216.                     6666666666666666
  217.                     6666666666666666
  218.                     6666666666666666
  219.                     6666666666666666
  220.                     6666666666666666
  221.                     6666666666666666
  222.                     6666666666666666
  223.                     6666666666666666
  224.                     6666666666666666
  225.                     6666666666666666
  226.                     6666666666666666
  227.                     6666666666666666
  228.                     6666666666666666
  229.                     6666666666666666
  230.                     6666666666666666
  231.                     6666666666666666
  232.                     6666666666666666
  233.                     6666666666666666
  234.                     6666666666666666
  235.                     6666666666666666
  236.                     6666666666666666
  237.                     6666666666666666
  238.                     6666666666666666
  239.                     """),
  240.                 img("""
  241.                     ................
  242.                     ................
  243.                     ................
  244.                     ................
  245.                     ................
  246.                     ................
  247.                     ................
  248.                     ................
  249.                     ................
  250.                     ................
  251.                     ................
  252.                     ................
  253.                     ................
  254.                     ................
  255.                     ................
  256.                     ................
  257.                     ................
  258.                     ................
  259.                     ................
  260.                     ................
  261.                     ................
  262.                     ................
  263.                     ................
  264.                     ................
  265.                     ................
  266.                     ................
  267.                     ................
  268.                     ................
  269.                     ................
  270.                     ................
  271.                     ................
  272.                     ................
  273.                     ................
  274.                     ................
  275.                     ................
  276.                     ................
  277.                     ................
  278.                     ................
  279.                     ................
  280.                     ................
  281.                     ................
  282.                     ................
  283.                     ................
  284.                     ................
  285.                     ................
  286.                     ................
  287.                     ................
  288.                     ................
  289.                     """),
  290.                 img("""
  291.                     6666666666666666
  292.                     6666666666666666
  293.                     6666666666666666
  294.                     6666666666666666
  295.                     6666666666666666
  296.                     6666666666666666
  297.                     6666666666666666
  298.                     6666666666666666
  299.                     6666666666666666
  300.                     6666666666666666
  301.                     6666666666666666
  302.                     6666666666666666
  303.                     6666666666666666
  304.                     6666666666666666
  305.                     6666666666666666
  306.                     6666666666666666
  307.                     6666666666666666
  308.                     6666666666666666
  309.                     6666666666666666
  310.                     6666666666666666
  311.                     6666666666666666
  312.                     6666666666666666
  313.                     6666666666666666
  314.                     6666666666666666
  315.                     6666666666666666
  316.                     6666666666666666
  317.                     6666666666666666
  318.                     6666666666666666
  319.                     6666666666666666
  320.                     6666666666666666
  321.                     6666666666666666
  322.                     6666666666666666
  323.                     6666666666666666
  324.                     6666666666666666
  325.                     6666666666666666
  326.                     6666666666666666
  327.                     6666666666666666
  328.                     6666666666666666
  329.                     6666666666666666
  330.                     6666666666666666
  331.                     6666666666666666
  332.                     6666666666666666
  333.                     6666666666666666
  334.                     6666666666666666
  335.                     6666666666666666
  336.                     6666666666666666
  337.                     6666666666666666
  338.                     6666666666666666
  339.                     """),
  340.                 img("""
  341.                     ................
  342.                     ................
  343.                     ................
  344.                     ................
  345.                     ................
  346.                     ................
  347.                     ................
  348.                     ................
  349.                     ................
  350.                     ................
  351.                     ................
  352.                     ................
  353.                     ................
  354.                     ................
  355.                     ................
  356.                     ................
  357.                     ................
  358.                     ................
  359.                     ................
  360.                     ................
  361.                     ................
  362.                     ................
  363.                     ................
  364.                     ................
  365.                     ................
  366.                     ................
  367.                     ................
  368.                     ................
  369.                     ................
  370.                     ................
  371.                     ................
  372.                     ................
  373.                     ................
  374.                     ................
  375.                     ................
  376.                     ................
  377.                     ................
  378.                     ................
  379.                     ................
  380.                     ................
  381.                     ................
  382.                     ................
  383.                     ................
  384.                     ................
  385.                     ................
  386.                     ................
  387.                     ................
  388.                     ................
  389.                     """),
  390.                 img("""
  391.                     6666666666666666
  392.                     6666666666666666
  393.                     6666666666666666
  394.                     6666666666666666
  395.                     6666666666666666
  396.                     6666666666666666
  397.                     6666666666666666
  398.                     6666666666666666
  399.                     6666666666666666
  400.                     6666666666666666
  401.                     6666666666666666
  402.                     6666666666666666
  403.                     6666666666666666
  404.                     6666666666666666
  405.                     6666666666666666
  406.                     6666666666666666
  407.                     6666666666666666
  408.                     6666666666666666
  409.                     6666666666666666
  410.                     6666666666666666
  411.                     6666666666666666
  412.                     6666666666666666
  413.                     6666666666666666
  414.                     6666666666666666
  415.                     6666666666666666
  416.                     6666666666666666
  417.                     6666666666666666
  418.                     6666666666666666
  419.                     6666666666666666
  420.                     6666666666666666
  421.                     6666666666666666
  422.                     6666666666666666
  423.                     6666666666666666
  424.                     6666666666666666
  425.                     6666666666666666
  426.                     6666666666666666
  427.                     6666666666666666
  428.                     6666666666666666
  429.                     6666666666666666
  430.                     6666666666666666
  431.                     6666666666666666
  432.                     6666666666666666
  433.                     6666666666666666
  434.                     6666666666666666
  435.                     6666666666666666
  436.                     6666666666666666
  437.                     6666666666666666
  438.                     6666666666666666
  439.                     """)],
  440.             150,
  441.             False)
  442.         statusbar.set_color(6, 1)
  443.         initialize_camera()
  444.     elif current == 2:
  445.         bossHealth = 50
  446.         bossHealthThreshold = bossHealth / 3
  447.         tiles.set_tilemap(tilemap("""
  448.             level6
  449.             """))
  450.         tiles.place_on_tile(thePlayer, tiles.get_tile_location(2, 2))
  451.         bossLocations = tiles.get_tiles_by_type(assets.tile("""
  452.             tile3
  453.             """))
  454.         currentFireIndex = 0
  455.         lastBossFireTime = game.runtime()
  456.         statusbar.set_color(4, 1)
  457.         resetHealth()
  458.         initialize_chase()
  459.     elif current == 3:
  460.         bossHealth = 100
  461.         darylHorizontalSpeed = 60
  462.         tiles.set_tilemap(tilemap("""
  463.             level7
  464.             """))
  465.         theBoss = sprites.create(assets.image("""
  466.             daryl
  467.             """), SpriteKind.Boss)
  468.         theBoss.ay = gravity
  469.         theBoss.right = 155
  470.         statusbar.set_color(8, 1)
  471.         resetHealth()
  472.     else:
  473.         create_final_boss()
  474. def initialize_chase():
  475.     global bossSpawn, theBoss, lastBossFireTime
  476.     bossSpawn = bossLocations.shift()
  477.     theBoss = sprites.create(img("""
  478.             5 5 5 5 5 5 5 5 5 5 5
  479.             5 5 5 5 5 5 5 5 5 5 5
  480.             5 5 5 5 5 5 5 5 5 5 5
  481.             5 5 5 5 5 5 5 5 5 5 5
  482.             5 5 5 5 5 5 5 5 5 5 5
  483.             5 5 5 5 5 5 5 5 5 5 5
  484.             5 5 5 5 5 5 5 5 5 5 5
  485.             5 5 5 5 5 5 5 5 5 5 5
  486.             5 5 5 5 5 5 5 5 5 5 5
  487.             5 5 5 5 5 5 5 5 5 5 5
  488.             5 5 5 5 5 5 5 5 5 5 5
  489.             """),
  490.         SpriteKind.Boss)
  491.     tiles.place_on_tile(theBoss, bossSpawn)
  492.     animation.run_image_animation(theBoss,
  493.         assets.animation("""
  494.             chase animation
  495.             """),
  496.         150,
  497.         True)
  498.     theBoss.lifespan = 4000
  499.     bossLocations.append(bossSpawn)
  500.     lastBossFireTime += 2000
  501. def clearStage():
  502.     theBoss.destroy()
  503.     for value in sprites.all_of_kind(SpriteKind.BossProjectile):
  504.         value.destroy()
  505.     for value2 in sprites.all_of_kind(SpriteKind.projectile):
  506.         value2.destroy()
  507.     for value22 in sprites.all_of_kind(SpriteKind.Camera):
  508.         value22.destroy()
  509. def darylThrow(dir2: number):
  510.     global projectile
  511.     theBoss.say("Daryl Throw!", 500)
  512.     pause(500)
  513.     projectile = sprites.create_projectile_from_sprite(assets.image("""
  514.             daryl projectile
  515.             """),
  516.         theBoss,
  517.         2 * (dir2 * darylHorizontalSpeed),
  518.         0)
  519.     projectile.set_kind(SpriteKind.BossProjectile)
  520.     projectile = sprites.create_projectile_from_sprite(assets.image("""
  521.             daryl projectile
  522.             """),
  523.         theBoss,
  524.         2 * (dir2 * darylHorizontalSpeed),
  525.         -74)
  526.     projectile.set_kind(SpriteKind.BossProjectile)
  527.     pause(500)
  528. def resetHealth():
  529.     statusbar.max = bossHealth
  530.     statusbar.value = bossHealth
  531. def darylDash(dir3: number):
  532.     theBoss.say("Daryl Dash!", 500)
  533.     pause(500)
  534.     theBoss.vx = 2 * (dir3 * darylHorizontalSpeed)
  535.     pause(200)
  536. def on_on_overlap(sprite, otherSprite):
  537.     global bossHealth, timeBetweenBossMove, bossSpeed
  538.     sprite.destroy(effects.disintegrate, 10)
  539.     bossHealth += -1
  540.     statusbar.value += -1
  541.     if bossHealth == 0:
  542.         next_boss()
  543.     elif bossHealth == 50 and currentBoss == 0:
  544.         timeBetweenBossMove = 1000
  545.         bossSpeed = 100
  546. sprites.on_overlap(SpriteKind.projectile, SpriteKind.Boss, on_on_overlap)
  547. def on_a_pressed():
  548.     if thePlayer.is_hitting_tile(CollisionDirection.BOTTOM):
  549.         thePlayer.vy = jumpVelocity
  550. controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)
  551. # CHASE
  552. def on_on_destroyed(sprite2):
  553.     if currentBoss == 2 and bossHealth > 0:
  554.         initialize_chase()
  555. sprites.on_destroyed(SpriteKind.Boss, on_on_destroyed)
  556. def darylJump(dir4: number):
  557.     theBoss.say("Daryl Jump!", 500)
  558.     pause(500)
  559.     theBoss.vy = Math.random_range(1.5 * jumpVelocity, jumpVelocity)
  560.     theBoss.vx = dir4 * darylHorizontalSpeed
  561. def on_on_overlap2(sprite3, otherSprite2):
  562.     sprite3.destroy(effects.disintegrate, 10)
  563.     info.change_life_by(-1)
  564. sprites.on_overlap(SpriteKind.BossProjectile, SpriteKind.player, on_on_overlap2)
  565. def initialize_camera():
  566.     global camera_target
  567.     camera_target = sprites.create(img("""
  568.             . . . . . . . . . . . . . . . .
  569.             . . . . . . . . . . . . . . . .
  570.             . . . . . . . . . . . . . . . .
  571.             . . . . . . . . . . . . . . . .
  572.             . . . . . . . . . . . . . . . .
  573.             . . . . . . . . . . . . . . . .
  574.             . . . . . . . . . . . . . . . .
  575.             . . . . . . . 3 3 . . . . . . .
  576.             . . . . . . . 3 3 . . . . . . .
  577.             . . . . . . . . . . . . . . . .
  578.             . . . . . . . . . . . . . . . .
  579.             . . . . . . . . . . . . . . . .
  580.             . . . . . . . . . . . . . . . .
  581.             . . . . . . . . . . . . . . . .
  582.             . . . . . . . . . . . . . . . .
  583.             . . . . . . . . . . . . . . . .
  584.             """),
  585.         SpriteKind.Camera)
  586.     camera_target.set_flag(SpriteFlag.GHOST, True)
  587.     camera_target.set_flag(SpriteFlag.INVISIBLE, True)
  588.     camera_target.set_velocity(cameraSpeed, 0)
  589.     scene.camera_follow_sprite(camera_target)
  590. def on_overlap_tile(sprite4, location):
  591.     clearStage()
  592.     createBoss(currentBoss)
  593.     tiles.place_on_tile(thePlayer, tiles.get_tile_location(7, 4))
  594. scene.on_overlap_tile(SpriteKind.player,
  595.     assets.tile("""
  596.         tile2
  597.         """),
  598.     on_overlap_tile)
  599. def on_on_overlap3(sprite5, otherSprite3):
  600.     if currentBoss == 1:
  601.         sprite5.destroy(effects.disintegrate, 10)
  602.         sprites.change_data_number_by(otherSprite3, "health", -1)
  603.         if sprites.read_data_number(otherSprite3, "health") == 8:
  604.             otherSprite3.image.replace(5, 4)
  605.         elif sprites.read_data_number(otherSprite3, "health") == 4:
  606.             otherSprite3.image.replace(4, 2)
  607.         elif sprites.read_data_number(otherSprite3, "health") == 0:
  608.             otherSprite3.destroy()
  609. sprites.on_overlap(SpriteKind.projectile,
  610.     SpriteKind.BossProjectile,
  611.     on_on_overlap3)
  612. def on_on_overlap4(sprite6, otherSprite4):
  613.     if currentBoss == 1:
  614.         if game.runtime() > lastBossFireTime + 1000:
  615.             info.change_life_by(-1)
  616.             camera_target.vx = cameraSpeed / 4
  617.             scene.camera_shake(4, 500)
  618.             pause(1000)
  619.             camera_target.vx = cameraSpeed
  620.     else:
  621.         info.change_life_by(-1)
  622.         pause(500)
  623. sprites.on_overlap(SpriteKind.player, SpriteKind.Boss, on_on_overlap4)
  624. projectile2: Sprite = None
  625. darylDir = 0
  626. chosenAction = 0
  627. fireAngle = 0
  628. isBossAttacking = False
  629. lastFireTime = 0
  630. isFacingLeft = False
  631. camera_target: Sprite = None
  632. projectile: Sprite = None
  633. bossSpawn: tiles.Location = None
  634. darylHorizontalSpeed = 0
  635. currentFireIndex = 0
  636. bossLocations: List[tiles.Location] = []
  637. bossHealthThreshold = 0
  638. lastBossFireTime = 0
  639. cameraSpeed = 0
  640. theBoss: Sprite = None
  641. timeBetweenBossMove = 0
  642. timeBetweenBossFire = 0
  643. bossHealth = 0
  644. bossSpeed = 0
  645. statusbar: StatusBarSprite = None
  646. currentBoss = 0
  647. thePlayer: Sprite = None
  648. jumpVelocity = 0
  649. gravity = 0
  650. tiles.set_tilemap(tilemap("""
  651.     level5
  652.     """))
  653. gravity = 300
  654. jumpHeight = 34
  655. playerSpeed = 100
  656. projectileVelocity = 150
  657. timeBetweenFire = 100
  658. jumpVelocity = 0 - Math.sqrt(2 * (gravity * jumpHeight))
  659. thePlayer = sprites.create(assets.image("""
  660.         player character
  661.         """),
  662.     SpriteKind.player)
  663. thePlayer.ay = gravity
  664. controller.move_sprite(thePlayer, playerSpeed, 0)
  665. info.set_life(10)
  666. currentBoss = 0
  667. statusbar = statusbars.create(100, 11, StatusBarKind.health)
  668. statusbar.set_color(12, 1)
  669. statusbar.set_bar_border(1, 3)
  670. statusbar.right = 160
  671. statusbar.top = 0
  672. statusbar.set_flag(SpriteFlag.RELATIVE_TO_CAMERA, True)
  673. createBoss(currentBoss)
  674. def on_on_update():
  675.     global isFacingLeft, projectile, lastFireTime
  676.     if thePlayer.vx < 0:
  677.         isFacingLeft = True
  678.     elif thePlayer.vx > 0:
  679.         isFacingLeft = False
  680.     if controller.B.is_pressed():
  681.         if game.runtime() > lastFireTime + timeBetweenFire:
  682.             if controller.up.is_pressed():
  683.                 projectile = sprites.create_projectile_from_sprite(assets.image("""
  684.                         player projectile
  685.                         """),
  686.                     thePlayer,
  687.                     0,
  688.                     0 - projectileVelocity)
  689.             elif isFacingLeft:
  690.                 projectile = sprites.create_projectile_from_sprite(assets.image("""
  691.                         player projectile
  692.                         """),
  693.                     thePlayer,
  694.                     0 - projectileVelocity,
  695.                     0)
  696.             else:
  697.                 projectile = sprites.create_projectile_from_sprite(assets.image("""
  698.                         player projectile
  699.                         """),
  700.                     thePlayer,
  701.                     projectileVelocity,
  702.                     0)
  703.             projectile.vx += thePlayer.vx
  704.             lastFireTime = game.runtime()
  705. game.on_update(on_on_update)
  706. def on_on_update2():
  707.     global projectile, lastBossFireTime, fireAngle, currentFireIndex
  708.     if currentBoss == 0:
  709.         if isBossAttacking:
  710.             if game.runtime() > lastBossFireTime + timeBetweenBossFire:
  711.                 projectile = sprites.create_projectile_from_sprite(assets.image("""
  712.                         albert projectile
  713.                         """),
  714.                     theBoss,
  715.                     -75,
  716.                     0)
  717.                 projectile.set_kind(SpriteKind.BossProjectile)
  718.                 projectile.y += Math.random_range(-16, 16)
  719.                 lastBossFireTime = game.runtime()
  720.     elif currentBoss == 1:
  721.         theBoss.left = scene.camera_left() + 12
  722.         theBoss.y = Math.map(Math.sin(game.runtime() / 1000),
  723.             -1,
  724.             1,
  725.             32,
  726.             scene.screen_height() - 32)
  727.     elif currentBoss == 2:
  728.         if game.runtime() > lastBossFireTime + timeBetweenBossFire:
  729.             animation.stop_animation(animation.AnimationTypes.ALL, theBoss)
  730.             theBoss.set_image(assets.image("""
  731.                 chase
  732.                 """))
  733.             if bossHealth > bossHealthThreshold:
  734.                 fireAngle = 0.7854 / 2 * currentFireIndex
  735.                 projectile = sprites.create_projectile_from_sprite(assets.image("""
  736.                         chase projectile
  737.                         """),
  738.                     theBoss,
  739.                     Math.cos(fireAngle) * projectileVelocity,
  740.                     Math.sin(fireAngle) * projectileVelocity)
  741.                 currentFireIndex += 1
  742.                 projectile.set_kind(SpriteKind.BossProjectile)
  743.             else:
  744.                 for index in range(8):
  745.                     fireAngle = 0.7854 * index
  746.                     projectile = sprites.create_projectile_from_sprite(assets.image("""
  747.                             chase projectile
  748.                             """),
  749.                         theBoss,
  750.                         Math.cos(fireAngle) * projectileVelocity,
  751.                         Math.sin(fireAngle) * projectileVelocity)
  752.                     projectile.set_kind(SpriteKind.BossProjectile)
  753.             lastBossFireTime = game.runtime()
  754.     else:
  755.         pass
  756. game.on_update(on_on_update2)
  757. def on_on_update3():
  758.     if currentBoss == 1:
  759.         if thePlayer.right + 16 < scene.camera_left():
  760.             clearStage()
  761.             createBoss(currentBoss)
  762.             tiles.place_on_tile(thePlayer, tiles.get_tile_location(7, 4))
  763. game.on_update(on_on_update3)
  764. def on_forever():
  765.     global isBossAttacking, chosenAction, darylDir
  766.     if currentBoss == 0:
  767.         if theBoss.is_hitting_tile(CollisionDirection.BOTTOM) or theBoss.is_hitting_tile(CollisionDirection.TOP):
  768.             isBossAttacking = True
  769.             pause(timeBetweenBossMove)
  770.             isBossAttacking = False
  771.             if theBoss.is_hitting_tile(CollisionDirection.BOTTOM):
  772.                 theBoss.vy = 0 - bossSpeed
  773.             else:
  774.                 theBoss.vy = bossSpeed
  775.             pause(100)
  776.     elif currentBoss == 3:
  777.         if theBoss.is_hitting_tile(CollisionDirection.BOTTOM):
  778.             theBoss.vx = 0
  779.             chosenAction = Math.random_range(0, 2)
  780.             darylDir = 1
  781.             if thePlayer.x < theBoss.x:
  782.                 darylDir = -1
  783.             if chosenAction == 0:
  784.                 darylThrow(darylDir)
  785.             elif chosenAction == 1:
  786.                 darylDash(darylDir)
  787.             else:
  788.                 darylJump(darylDir)
  789. forever(on_forever)
  790. def on_update_interval():
  791.     global projectile2
  792.     if currentBoss == 1:
  793.         projectile2 = sprites.create_projectile_from_sprite(assets.image("""
  794.                 bertha projectile
  795.                 """),
  796.             theBoss,
  797.             10,
  798.             0)
  799.         projectile2.set_kind(SpriteKind.BossProjectile)
  800.         projectile2.follow(thePlayer, 35)
  801.         sprites.set_data_number(projectile2, "health", 12)
  802. game.on_update_interval(3000, on_update_interval)
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 昨天 18:23

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏

图形编程参考实验程序

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图1

通过模拟器,调试与模拟运行

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图2

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图3

实验场景记录

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图4

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图5

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图6

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图9

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图7

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图8

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 昨天 18:26

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏

【花雕动手做】基于Kitronik可编程开发板之Boss 冲刺游戏图1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail