comparison game/js/projectile.js @ 24:3f2811aebb3d 0.9.0

splash screen buttons, help button, info screen
author ark
date 2026-10-20 15:58 +0200
parents fe680946164b
children
comparison
equal deleted inserted replaced
23:2f555a54c332 24:3f2811aebb3d
1 // projectiles: fly towards their target and damage it on arrival, p2 also 1 // projectiles: fly towards their target and damage it on arrival. p2 does
2 // slows it 2 // no damage; it bursts where it lands and slows every monster nearby
3 3
4 window.MM = window.MM || {}; 4 window.MM = window.MM || {};
5 5
6 MM.projectile = (function () { 6 MM.projectile = (function () {
7 "use strict"; 7 "use strict";
17 ty: target.y, 17 ty: target.y,
18 target: target, 18 target: target,
19 damage: damage, 19 damage: damage,
20 slow: def.slow ? def.slow[tower.level - 1] : 0, 20 slow: def.slow ? def.slow[tower.level - 1] : 0,
21 slowTime: def.slow_time, 21 slowTime: def.slow_time,
22 splash: def.splash_radius || 0,
22 angle: Math.atan2(target.y - tower.y, target.x - tower.x), 23 angle: Math.atan2(target.y - tower.y, target.x - tower.x),
23 done: false 24 done: false
24 }; 25 };
25 } 26 }
26 27
27 // home in on the target. if it died first, fly on to its last position 28 // home in on the target. if it died first, fly on to its last position
28 // and disappear there without damage. 29 // and disappear there without damage; a splash still bursts there.
29 function update(p, game, dt) { 30 function update(p, game, dt) {
30 var t = p.target; 31 var t = p.target;
31 if (t && t.alive) { 32 if (t && t.alive) {
32 p.tx = t.x; 33 p.tx = t.x;
33 p.ty = t.y; 34 p.ty = t.y;
37 var dx = p.tx - p.x, dy = p.ty - p.y; 38 var dx = p.tx - p.x, dy = p.ty - p.y;
38 var d = Math.hypot(dx, dy); 39 var d = Math.hypot(dx, dy);
39 var step = p.speed * dt; 40 var step = p.speed * dt;
40 var reach = t ? Math.max(step, t.hitRadius) : step; 41 var reach = t ? Math.max(step, t.hitRadius) : step;
41 if (d <= reach) { 42 if (d <= reach) {
42 if (t) { 43 if (p.splash) {
44 game.freeze(p.tx, p.ty, p.splash, p.slow, p.slowTime);
45 } else if (t) {
43 if (p.slow) MM.monster.slow(t, p.slow, p.slowTime); 46 if (p.slow) MM.monster.slow(t, p.slow, p.slowTime);
44 game.damage(t, p.damage); 47 if (p.damage) game.damage(t, p.damage);
45 } 48 }
46 p.done = true; 49 p.done = true;
47 return; 50 return;
48 } 51 }
49 p.angle = Math.atan2(dy, dx); 52 p.angle = Math.atan2(dy, dx);