comparison game/js/render.js @ 11:a77857594150

adjusted tower building, added preview dragging
author ark
date 2026-10-19 17:56 +0200
parents 2c4fed8baed9
children
comparison
equal deleted inserted replaced
10:22b604680c5a 11:a77857594150
70 var a = -Math.PI / 2 + side * Math.PI / 2; 70 var a = -Math.PI / 2 + side * Math.PI / 2;
71 A.draw(ctx, "p0", t.x + Math.cos(a) * mid, t.y + Math.sin(a) * mid, scale, a, 1, stretch); 71 A.draw(ctx, "p0", t.x + Math.cos(a) * mid, t.y + Math.sin(a) * mid, scale, a, 1, stretch);
72 } 72 }
73 } 73 }
74 74
75 function drawTower(ctx, t, alpha) { 75 // k scales the drawing, for the pulsing preview
76 var scale = cfg.scale.sprite; 76 function drawTower(ctx, t, alpha, k) {
77 var scale = cfg.scale.sprite * (k || 1);
77 ctx.globalAlpha = alpha; 78 ctx.globalAlpha = alpha;
78 if (t.def.projectile_speed === 0) drawSpikes(ctx, t, scale); 79 if (t.def.projectile_speed === 0) drawSpikes(ctx, t, scale);
79 A.draw(ctx, MM.tower.sprite(t), t.x, t.y, scale, t.angle); 80 A.draw(ctx, MM.tower.sprite(t), t.x, t.y, scale, t.angle);
80 ctx.globalAlpha = 1; 81 ctx.globalAlpha = 1;
81 } 82 }
140 drawTower(ctx, t, 1); 141 drawTower(ctx, t, 1);
141 } 142 }
142 if (game.preview) { 143 if (game.preview) {
143 var pv = MM.tower.create(game.shop, game.preview.x, game.preview.y, game.preview.sides); 144 var pv = MM.tower.create(game.shop, game.preview.x, game.preview.y, game.preview.sides);
144 drawRange(ctx, pv.x, pv.y, MM.tower.range(pv), s); 145 drawRange(ctx, pv.x, pv.y, MM.tower.range(pv), s);
145 drawTower(ctx, pv, 0.65); 146 // the preview pulses with the chosen shop item: it grows while
147 // the item shows one drawing and shrinks while it shows the other
148 var k = 0.5 - 0.5 * Math.cos(Math.PI * view.now / MM.ui.BUBBLE_FLIP);
149 drawTower(ctx, pv, MM.util.lerp(0.45, 0.8, k), MM.util.lerp(1, 1.08, k));
146 } 150 }
147 151
148 game.monsters.slice().sort(function (a, b) { return a.y - b.y; }) 152 game.monsters.slice().sort(function (a, b) { return a.y - b.y; })
149 .forEach(function (m) { drawMonster(ctx, m, game.time); }); 153 .forEach(function (m) { drawMonster(ctx, m, game.time); });
150 game.puffs.forEach(function (p) { drawPuff(ctx, p); }); 154 game.puffs.forEach(function (p) { drawPuff(ctx, p); });