| 123 | |
| 124 | //expansão do especial |
| 125 | function new_circle() { |
| 126 | |
| 127 | c.strokeStyle = 'red'; |
| 128 | c.lineWidth = 5; |
| 129 | |
| 130 | var startTime = 0; |
| 131 | var animationTime = 5; // seconds |
| 132 | var fn = function (time) { |
| 133 | if (startTime) { |
| 134 | var t = (time - startTime) / 100; |
| 135 | if (t > animationTime) { |
| 136 | t = animationTime; |
| 137 | } |
| 138 | var i = canvas.height / 2 * t / animationTime; |
| 139 | c.beginPath(); |
| 140 | c.arc(canvas.width / 2, canvas.height / 2, i, 0, 2 * Math.PI); |
| 141 | |
| 142 | //explosoes com o toque |
| 143 | enemies.forEach((enemy, index) => { |
| 144 | const dist = Math.hypot(c.x - enemy.x, c.y - enemy.y) |
| 145 | if (dist - enemy.radius - c.radius < 1) { |
| 146 | for (let i = 0; i < c.radius * 2; i++) { |
| 147 | particles.push(new Particle(c.x, c.y, Math.random() * 2, enemy.color, { |
| 148 | x: (Math.random() - 0.5) * (Math.random() * 6), |
| 149 | y: (Math.random() - 0.5) * (Math.random() * 6), |
| 150 | })) |
| 151 | } |
| 152 | } |
| 153 | setTimeout(() => { |
| 154 | enemies.splice(index, 1) |
| 155 | projectiles.splice(projectileIndex, 1) |
| 156 | }, 0) |
| 157 | }) |
| 158 | c.fill(); |
| 159 | c.stroke(); |
| 160 | //----------------------- |
| 161 | if (t < animationTime) { |
| 162 | requestAnimationFrame(fn); |
| 163 | } |
| 164 | } else { // first call to requestAnimationFrame sets the start time |
| 165 | startTime = time; |
| 166 | requestAnimationFrame(fn); |
| 167 | } |
| 168 | }; |
| 169 | requestAnimationFrame(fn); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | |