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

splash screen buttons, help button, info screen
author ark
date 2026-10-20 15:58 +0200
parents 2f555a54c332
children 75deda08db90
comparison
equal deleted inserted replaced
23:2f555a54c332 24:3f2811aebb3d
118 ctx.globalAlpha = u < 0.5 ? 1 : 2 - 2 * u; 118 ctx.globalAlpha = u < 0.5 ? 1 : 2 - 2 * u;
119 A.draw(ctx, name, p.x, p.y, cfg.scale.sprite, null, k, k); 119 A.draw(ctx, name, p.x, p.y, cfg.scale.sprite, null, k, k);
120 ctx.globalAlpha = 1; 120 ctx.globalAlpha = 1;
121 } 121 }
122 122
123 // freeze splash: drawn across the splash diameter. it grows from 60 % to
124 // full size over the first half of its time and fades out over the
125 // second half
126 function drawFreeze(ctx, f) {
127 var u = f.t / cfg.animation.freeze_splash;
128 var s = cfg.sprites.freeze;
129 var k = MM.util.lerp(0.6, 1, MM.util.easeOut(Math.min(1, u * 2)));
130 ctx.globalAlpha = 0.85 * (u < 0.5 ? 1 : 2 - 2 * u);
131 A.draw(ctx, "freeze", f.x, f.y, 2 * f.r / Math.max(s[0], s[1]), null, k, k);
132 ctx.globalAlpha = 1;
133 }
134
123 // draw the map area. L is the layout from ui.js, view holds the canvas 135 // draw the map area. L is the layout from ui.js, view holds the canvas
124 // pixel ratio, wall clock and tap feedback. 136 // pixel ratio, wall clock and tap feedback.
125 function draw(ctx, game, L, view) { 137 function draw(ctx, game, L, view) {
126 var map = game.map, s = L.scale, dpr = view.dpr; 138 var map = game.map, s = L.scale, dpr = view.dpr;
127 ctx.setTransform(dpr * s, 0, 0, dpr * s, dpr * L.ox, dpr * L.oy); 139 ctx.setTransform(dpr * s, 0, 0, dpr * s, dpr * L.ox, dpr * L.oy);
147 // the item shows one drawing and shrinks while it shows the other 159 // 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); 160 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)); 161 drawTower(ctx, pv, MM.util.lerp(0.45, 0.8, k), MM.util.lerp(1, 1.08, k));
150 } 162 }
151 163
164 // the splashes lie on the ground, under the monsters
165 game.freezes.forEach(function (f) { drawFreeze(ctx, f); });
152 game.monsters.slice().sort(function (a, b) { return a.y - b.y; }) 166 game.monsters.slice().sort(function (a, b) { return a.y - b.y; })
153 .forEach(function (m) { drawMonster(ctx, m, game.time); }); 167 .forEach(function (m) { drawMonster(ctx, m, game.time); });
154 game.puffs.forEach(function (p) { drawPuff(ctx, p); }); 168 game.puffs.forEach(function (p) { drawPuff(ctx, p); });
155 if (dbg.show_hit_areas) { 169 if (dbg.show_hit_areas) {
156 game.monsters.forEach(function (m) { 170 game.monsters.forEach(function (m) {
157 circle(ctx, m.x, m.y, m.hitRadius, null, "rgba(255, 0, 0, 0.8)", 1 / s); 171 circle(ctx, m.x, m.y, m.hitRadius, null, "rgba(255, 0, 0, 0.8)", 1 / s);
172 });
173 game.freezes.forEach(function (f) {
174 circle(ctx, f.x, f.y, f.r, null, "rgba(0, 90, 255, 0.8)", 1 / s);
158 }); 175 });
159 } 176 }
160 177
161 game.projectiles.forEach(function (p) { 178 game.projectiles.forEach(function (p) {
162 A.draw(ctx, p.kind, p.x, p.y, cfg.scale.sprite, p.angle); 179 A.draw(ctx, p.kind, p.x, p.y, cfg.scale.sprite, p.angle);