* 发射烟花 * @param {number} position X位置 * @param {number} launchHeight 爆炸所在高度
(position, launchHeight)
| 1689 | * @param {number} launchHeight 爆炸所在高度 |
| 1690 | */ |
| 1691 | launch(position, launchHeight) { |
| 1692 | const width = stageW; |
| 1693 | const height = stageH; |
| 1694 | //与屏幕两侧保持外壳的距离。 |
| 1695 | const hpad = 60; |
| 1696 | //与屏幕顶部的距离,以保持烟花爆裂。 |
| 1697 | const vpad = 50; |
| 1698 | //最小爆发高度,以舞台高度的百分比表示 |
| 1699 | const minHeightPercent = 0.45; |
| 1700 | //以像素为单位的最小突发高度 |
| 1701 | const minHeight = height - height * minHeightPercent; |
| 1702 | |
| 1703 | const launchX = position * (width - hpad * 2) + hpad; |
| 1704 | const launchY = height; |
| 1705 | const burstY = minHeight - launchHeight * (minHeight - vpad); |
| 1706 | |
| 1707 | const launchDistance = launchY - burstY; |
| 1708 | // Using a custom power curve to approximate Vi needed to reach launchDistance under gravity and air drag. |
| 1709 | // Magic numbers came from testing. |
| 1710 | //使用自定义功率曲线来逼近在重力和空气阻力下达到发射距离所需的Vi。 |
| 1711 | //神奇的数字来自测试。 |
| 1712 | const launchVelocity = Math.pow(launchDistance * 0.04, 0.64); |
| 1713 | |
| 1714 | const comet = (this.comet = Star.add( |
| 1715 | launchX, |
| 1716 | launchY, |
| 1717 | typeof this.color === "string" && this.color !== "random" ? this.color : COLOR.White, |
| 1718 | Math.PI, |
| 1719 | launchVelocity * (this.horsetail ? 1.2 : 1), |
| 1720 | // Hang time is derived linearly from Vi; exact number came from testing |
| 1721 | launchVelocity * (this.horsetail ? 100 : 400) |
| 1722 | )); |
| 1723 | |
| 1724 | // making comet "heavy" limits air drag |
| 1725 | // //让彗星“重”限制空气阻力 |
| 1726 | comet.heavy = true; |
| 1727 | // comet spark trail |
| 1728 | comet.spinRadius = MyMath.random(0.32, 0.85); |
| 1729 | comet.sparkFreq = 32 / quality; |
| 1730 | if (isHighQuality) comet.sparkFreq = 8; |
| 1731 | comet.sparkLife = 320; |
| 1732 | comet.sparkLifeVariation = 3; |
| 1733 | if (this.glitter === "willow" || this.fallingLeaves) { |
| 1734 | comet.sparkFreq = 20 / quality; |
| 1735 | comet.sparkSpeed = 0.5; |
| 1736 | comet.sparkLife = 500; |
| 1737 | } |
| 1738 | if (this.color === INVISIBLE) { |
| 1739 | comet.sparkColor = COLOR.Gold; |
| 1740 | } |
| 1741 | |
| 1742 | // Randomly make comet "burn out" a bit early. |
| 1743 | // This is disabled for horsetail shells, due to their very short airtime. |
| 1744 | if (Math.random() > 0.4 && !this.horsetail) { |
| 1745 | comet.secondColor = INVISIBLE; |
| 1746 | comet.transitionTime = Math.pow(Math.random(), 1.5) * 700 + 500; |
| 1747 | } |
| 1748 |
no test coverage detected