@maco-online/paint-tanks-rules 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ai-host.d.ts +15 -0
  3. package/dist/ai-host.js +1 -0
  4. package/dist/balance-config.d.ts +50 -0
  5. package/dist/balance-config.js +41 -0
  6. package/dist/boss-ai.d.ts +9 -0
  7. package/dist/boss-ai.js +213 -0
  8. package/dist/bosses.d.ts +34 -0
  9. package/dist/bosses.js +47 -0
  10. package/dist/constants.d.ts +133 -0
  11. package/dist/constants.js +163 -0
  12. package/dist/enemy-ai.d.ts +11 -0
  13. package/dist/enemy-ai.js +361 -0
  14. package/dist/game-factory.d.ts +16 -0
  15. package/dist/game-factory.js +78 -0
  16. package/dist/game-state.d.ts +256 -0
  17. package/dist/game-state.js +1 -0
  18. package/dist/index.d.ts +25 -0
  19. package/dist/index.js +27 -0
  20. package/dist/labels.d.ts +12 -0
  21. package/dist/labels.js +129 -0
  22. package/dist/levels.d.ts +45 -0
  23. package/dist/levels.js +209 -0
  24. package/dist/movement.d.ts +25 -0
  25. package/dist/movement.js +158 -0
  26. package/dist/online/match.d.ts +28 -0
  27. package/dist/online/match.js +176 -0
  28. package/dist/online/prediction.d.ts +41 -0
  29. package/dist/online/prediction.js +97 -0
  30. package/dist/online/protocol.d.ts +124 -0
  31. package/dist/online/protocol.js +54 -0
  32. package/dist/online/room-game.d.ts +5 -0
  33. package/dist/online/room-game.js +20 -0
  34. package/dist/online/view.d.ts +43 -0
  35. package/dist/online/view.js +347 -0
  36. package/dist/pathfinding.d.ts +8 -0
  37. package/dist/pathfinding.js +45 -0
  38. package/dist/power-ups.d.ts +28 -0
  39. package/dist/power-ups.js +66 -0
  40. package/dist/random.d.ts +1 -0
  41. package/dist/random.js +1 -0
  42. package/dist/sim-effects.d.ts +30 -0
  43. package/dist/sim-effects.js +1 -0
  44. package/dist/simulation.d.ts +74 -0
  45. package/dist/simulation.js +768 -0
  46. package/dist/sound-names.d.ts +4 -0
  47. package/dist/sound-names.js +1 -0
  48. package/dist/spawning.d.ts +3 -0
  49. package/dist/spawning.js +56 -0
  50. package/dist/tank-rules.d.ts +20 -0
  51. package/dist/tank-rules.js +39 -0
  52. package/dist/visibility.d.ts +20 -0
  53. package/dist/visibility.js +39 -0
  54. package/package.json +43 -3
  55. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 maco-online contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ import type { Boss, Bullet, Enemy, Game, Particle, Player } from './game-state.ts';
2
+ import type { SoundName } from './sound-names.ts';
3
+ /**
4
+ * What the enemy and boss AI need from the simulation. The AI decides and mutates the `Game`; shooting, scoring
5
+ * and effects stay with the simulation, which implements this interface.
6
+ */
7
+ export interface AiHost {
8
+ readonly game: Game;
9
+ efire: (shooter: Enemy | Boss, vx: number, vy: number, shot?: Pick<Bullet, 'bounce' | 'rainbow'>) => void;
10
+ killEnemy: (enemy: Enemy | Boss, self: boolean, by?: Bullet) => void;
11
+ breakTile: (row: number, column: number, tile: number) => void;
12
+ hitPlayer: (player: Player) => void;
13
+ burst: (x: number, y: number, color: string, count: number, type?: Particle['type']) => void;
14
+ sound: (name: SoundName) => void;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Cân bằng độ khó theo màn của Paint Tanks: tốc độ di chuyển, tốc độ đạn bay và máu của tank địch thường và boss.
3
+ *
4
+ * Giá trị thực tế = giá trị gốc của màn (công thức trong `diffOf`, `levels.ts`) × hệ số `rampFactor` của file này.
5
+ * Hệ số luôn nằm trong khoảng (0, 1], nên giá trị gốc chính là MỨC TỐI ĐA: các màn đầu dễ hơn,
6
+ * tăng dần theo màn và từ `fullLevel` trở đi bằng đúng giá trị gốc (không bao giờ vượt).
7
+ *
8
+ * Muốn chỉnh độ khó chỉ cần sửa `BALANCE` bên dưới; không cần đụng tới AI hay công thức độ khó.
9
+ * Đơn vị tốc độ gốc: pixel / frame (game chạy 60 frame/giây, một ô bản đồ = 32 px).
10
+ */
11
+ /** Hình dạng đường tăng giữa màn 1 và `fullLevel`. */
12
+ export type RampCurve =
13
+ /** Tăng đều: mỗi màn tăng một lượng như nhau. */
14
+ 'linear'
15
+ /** Tăng nhanh ở các màn đầu, về sau chậm dần rồi chạm mức tối đa. */
16
+ | 'easeOut'
17
+ /** Tăng chậm ở các màn đầu, về sau nhanh dần rồi chạm mức tối đa. */
18
+ | 'easeIn';
19
+ /** Một đường tăng từ `startFactor` ở màn 1 lên 100% giá trị gốc ở màn `fullLevel`. */
20
+ export interface LevelRamp {
21
+ /** Hệ số ở màn 1, trong khoảng (0, 1]. Ví dụ 0.6 = bằng 60% giá trị gốc. */
22
+ startFactor: number;
23
+ /** Màn đầu tiên đạt 100% giá trị gốc; các màn sau giữ nguyên mức tối đa. Phải >= 1. */
24
+ fullLevel: number;
25
+ curve: RampCurve;
26
+ }
27
+ export interface BalanceConfig {
28
+ /** Tank địch thường: dust, racer, box, sniper, bomb và lính do boss gọi ra. */
29
+ enemy: {
30
+ /** Tốc độ di chuyển. */
31
+ move: LevelRamp;
32
+ /** Tốc độ đạn bay (sniper vẫn nhanh hơn các loại khác đúng như cũ). */
33
+ bullet: LevelRamp;
34
+ };
35
+ /** Boss xuất hiện ở các màn chia hết cho 5 (5, 10, 15, ...). */
36
+ boss: {
37
+ /** Tốc độ di chuyển (các hệ số nổi giận / hồi cuối của boss vẫn nhân thêm như cũ). */
38
+ move: LevelRamp;
39
+ /** Tốc độ đạn bay, gồm cả loạt đạn tỏa tròn khi boss nổi điên. */
40
+ bullet: LevelRamp;
41
+ /** Máu. Boss cuối ở màn 100 (140 máu) luôn giữ nguyên vì màn 100 đã sau điểm đạt mức tối đa. */
42
+ health: LevelRamp;
43
+ };
44
+ }
45
+ export declare const BALANCE: BalanceConfig;
46
+ /**
47
+ * Hệ số nhân của màn `level`, luôn trong khoảng [startFactor, 1].
48
+ * Tham số không hợp lệ (ngoài khoảng cho phép) được kéo về khoảng hợp lệ để không bao giờ vượt giá trị gốc.
49
+ */
50
+ export declare function rampFactor(ramp: LevelRamp, level: number): number;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Cân bằng độ khó theo màn của Paint Tanks: tốc độ di chuyển, tốc độ đạn bay và máu của tank địch thường và boss.
3
+ *
4
+ * Giá trị thực tế = giá trị gốc của màn (công thức trong `diffOf`, `levels.ts`) × hệ số `rampFactor` của file này.
5
+ * Hệ số luôn nằm trong khoảng (0, 1], nên giá trị gốc chính là MỨC TỐI ĐA: các màn đầu dễ hơn,
6
+ * tăng dần theo màn và từ `fullLevel` trở đi bằng đúng giá trị gốc (không bao giờ vượt).
7
+ *
8
+ * Muốn chỉnh độ khó chỉ cần sửa `BALANCE` bên dưới; không cần đụng tới AI hay công thức độ khó.
9
+ * Đơn vị tốc độ gốc: pixel / frame (game chạy 60 frame/giây, một ô bản đồ = 32 px).
10
+ */
11
+ export const BALANCE = {
12
+ enemy: {
13
+ // Màn 1 chạy bằng 60% tốc độ gốc, tăng đều cho tới màn 90 thì bằng tốc độ gốc.
14
+ move: { startFactor: 0.6, fullLevel: 90, curve: 'linear' },
15
+ // Màn 1 đạn bằng 60% tốc độ gốc để người chơi kịp làm quen cách né, tăng đều tới màn 90.
16
+ bullet: { startFactor: 0.6, fullLevel: 90, curve: 'linear' }
17
+ },
18
+ boss: {
19
+ // Màn 1 bằng 65% tốc độ gốc, chậm hơn chút so với tank thường ở những màn đầu.
20
+ move: { startFactor: 0.65, fullLevel: 90, curve: 'linear' },
21
+ // Màn 1 đạn bằng 60% tốc độ gốc, tăng đều tới màn 90.
22
+ bullet: { startFactor: 0.6, fullLevel: 90, curve: 'linear' },
23
+ // Màn 1 chỉ bằng 50% máu gốc, tăng đều tới màn 90; boss đầu tiên (màn 5) có khoảng 52% máu gốc.
24
+ health: { startFactor: 0.5, fullLevel: 90, curve: 'linear' }
25
+ }
26
+ };
27
+ const CURVES = {
28
+ linear: t => t,
29
+ easeOut: t => 1 - (1 - t) ** 2,
30
+ easeIn: t => t ** 2
31
+ };
32
+ /**
33
+ * Hệ số nhân của màn `level`, luôn trong khoảng [startFactor, 1].
34
+ * Tham số không hợp lệ (ngoài khoảng cho phép) được kéo về khoảng hợp lệ để không bao giờ vượt giá trị gốc.
35
+ */
36
+ export function rampFactor(ramp, level) {
37
+ const start = Math.min(1, Math.max(0.01, ramp.startFactor));
38
+ const span = Math.max(1, ramp.fullLevel) - 1;
39
+ const progress = span === 0 ? 1 : Math.min(1, Math.max(0, (level - 1) / span));
40
+ return start + (1 - start) * CURVES[ramp.curve](progress);
41
+ }
@@ -0,0 +1,9 @@
1
+ import type { AiHost } from './ai-host.ts';
2
+ import type { Boss, Game } from './game-state.ts';
3
+ /** The boss of the part of the house level `lv` takes place in. */
4
+ export declare function bossSpecOf(lv: number): import("./bosses.ts").BossSpec;
5
+ /** How fast a boss shot flies on this level, before the volley's own speed factor. */
6
+ export declare function bossShotSpeed(g: Game): number;
7
+ export declare function spawnBoss(host: AiHost): void;
8
+ export declare function bossSmash(host: AiHost, b: Boss): void;
9
+ export declare function bossAI(host: AiHost, b: Boss): void;
@@ -0,0 +1,213 @@
1
+ import { BOSS_BULLET_MAX, BOSS_TELEGRAPH, BOSSES, bossVolley, patternOf } from "./bosses.js";
2
+ import { COL, DX, DY, N, PET, T, TIERS, W } from "./constants.js";
3
+ import { tierOf } from "./levels.js";
4
+ import { rnd } from "./random.js";
5
+ import { spawnEnemy } from "./spawning.js";
6
+ import { huntablePlayers, isActive, someoneCloaked } from "./visibility.js";
7
+ /** The boss of the part of the house level `lv` takes place in. */
8
+ export function bossSpecOf(lv) {
9
+ return BOSSES[TIERS[tierOf(lv)].key];
10
+ }
11
+ /** How fast a boss shot flies on this level, before the volley's own speed factor. */
12
+ export function bossShotSpeed(g) {
13
+ return Math.min(BOSS_BULLET_MAX, g.D.bossEb * 0.85);
14
+ }
15
+ export function spawnBoss(host) {
16
+ const g = host.game;
17
+ const D = g.D;
18
+ const spec = bossSpecOf(g.lv);
19
+ const s = 60;
20
+ const x = W / 2 - s / 2;
21
+ const y = 2;
22
+ g.boss = {
23
+ boss: true,
24
+ kind: 'boss',
25
+ id: spec.id,
26
+ x,
27
+ y,
28
+ s,
29
+ dir: 2,
30
+ hp: D.bossHp,
31
+ maxHp: D.bossHp,
32
+ color: spec.color,
33
+ cd: 90,
34
+ flash: 0,
35
+ anim: 0,
36
+ spd: D.bossSpd,
37
+ tx: W / 2,
38
+ ty: 120,
39
+ dodgeDir: 0,
40
+ retarget: 40,
41
+ sc: 0,
42
+ shielded: false,
43
+ inv: 0,
44
+ last: false,
45
+ still: 0,
46
+ dodgeT: 0,
47
+ axis: true,
48
+ charge: 0,
49
+ volley: 0,
50
+ plan: [],
51
+ queue: []
52
+ };
53
+ bossSmash(host, g.boss);
54
+ host.burst(W / 2, 32, COL.ink2, 20, 'bubble');
55
+ host.sound('bossIn');
56
+ }
57
+ export function bossSmash(host, b) {
58
+ const g = host.game;
59
+ for (let r = Math.max(0, Math.floor(b.y / T)); r <= Math.min(N - 1, Math.floor((b.y + b.s - 0.01) / T)); r++) {
60
+ for (let c = Math.max(0, Math.floor(b.x / T)); c <= Math.min(N - 1, Math.floor((b.x + b.s - 0.01) / T)); c++) {
61
+ const v = g.map[r][c];
62
+ if ((v >= 1 && v <= 3) || v === 7) {
63
+ host.breakTile(r, c, v);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ export function bossAI(host, b) {
69
+ const g = host.game;
70
+ const D = g.D;
71
+ if (b.flash > 0) {
72
+ b.flash--;
73
+ }
74
+ if (b.inv > 0) {
75
+ b.inv--;
76
+ }
77
+ const ratio = b.hp / b.maxHp;
78
+ const rage = ratio < 0.5;
79
+ if (D.bossShield) {
80
+ const cyc = rage ? 300 : 380;
81
+ b.sc = (b.sc + 1) % cyc;
82
+ b.shielded = b.sc > cyc - 100;
83
+ }
84
+ if (D.bossLast && !b.last && ratio <= 0.2) {
85
+ b.last = true;
86
+ b.inv = 140;
87
+ const n = g.lv >= 75 ? 3 : 2;
88
+ for (let i = 0; i < n; i++) {
89
+ spawnEnemy(g, i === 1 ? 2 : i === 2 ? 1 : 0, i % 2 ? 'racer' : g.lv >= 30 ? 'sniper' : 'dust', true);
90
+ }
91
+ const v = bossShotSpeed(g) * 0.95;
92
+ for (let i = 0; i < 12; i++) {
93
+ const a = (i / 12) * Math.PI * 2;
94
+ host.efire(b, Math.cos(a) * v, Math.sin(a) * v);
95
+ }
96
+ g.banner = { key: 'bannerTeddyFurious', boss: b.id, life: 110 };
97
+ }
98
+ const cx = b.x + b.s / 2;
99
+ const cy = b.y + b.s / 2;
100
+ const ps = huntablePlayers(g);
101
+ if (--b.retarget <= 0 || b.still > 20) {
102
+ if (ps.length && Math.random() < 0.65) {
103
+ const p = ps[Math.floor(Math.random() * ps.length)];
104
+ b.tx = p.x + 13;
105
+ b.ty = p.y + 13;
106
+ }
107
+ else {
108
+ b.tx = rnd(40, W - 40);
109
+ b.ty = rnd(40, 9 * T);
110
+ }
111
+ b.retarget = rnd(50, 110);
112
+ b.still = 0;
113
+ b.axis = Math.random() < 0.5;
114
+ }
115
+ if (D.dodge && !b.dodgeT) {
116
+ const th = g.bullets.find(o => o.owner &&
117
+ ((Math.abs(o.x - cx) < 34 &&
118
+ ((o.vy < 0 && o.y > cy && o.y - cy < 130) || (o.vy > 0 && o.y < cy && cy - o.y < 130))) ||
119
+ (Math.abs(o.y - cy) < 34 &&
120
+ ((o.vx > 0 && o.x < cx && cx - o.x < 130) || (o.vx < 0 && o.x > cx && o.x - cx < 130)))));
121
+ if (th && Math.random() < D.dodge) {
122
+ b.dodgeT = 26;
123
+ b.dodgeDir = th.vx !== 0 ? (cy > W / 3 ? 0 : 2) : cx > W / 2 ? 3 : 1;
124
+ }
125
+ }
126
+ const sp = b.spd * (rage ? 1.35 : 1) * (b.last ? 1.2 : 1);
127
+ const dx = b.tx - cx;
128
+ const dy = b.ty - cy;
129
+ let dir = -1;
130
+ if (b.dodgeT > 0) {
131
+ b.dodgeT--;
132
+ dir = b.dodgeDir;
133
+ }
134
+ else {
135
+ const ax = Math.abs(dx) > 6;
136
+ const ay = Math.abs(dy) > 6;
137
+ if (ax && (b.axis || !ay)) {
138
+ dir = dx > 0 ? 1 : 3;
139
+ }
140
+ else if (ay) {
141
+ dir = dy > 0 ? 2 : 0;
142
+ }
143
+ }
144
+ if (b.charge > 0) {
145
+ // Holding still while it shows where the next volley goes.
146
+ }
147
+ else if (dir >= 0) {
148
+ b.dir = dir;
149
+ const nx = Math.max(0, Math.min(W - b.s, b.x + DX[dir] * sp));
150
+ const ny = Math.max(0, Math.min(10 * T - b.s, b.y + DY[dir] * sp));
151
+ if (Math.abs(nx - b.x) + Math.abs(ny - b.y) < 0.01) {
152
+ b.still++;
153
+ b.dodgeT = 0;
154
+ }
155
+ else {
156
+ b.x = nx;
157
+ b.y = ny;
158
+ b.anim += sp;
159
+ b.still = 0;
160
+ bossSmash(host, b);
161
+ }
162
+ }
163
+ else {
164
+ b.still++;
165
+ }
166
+ if (b.charge > 0) {
167
+ if (--b.charge === 0) {
168
+ b.queue.push(...b.plan);
169
+ b.plan = [];
170
+ }
171
+ }
172
+ else if (--b.cd <= 0) {
173
+ let tx = PET[0] * T + 16;
174
+ let ty = PET[1] * T + 16;
175
+ if ((ps.length || someoneCloaked(g)) && Math.random() < 0.7) {
176
+ if (!ps.length) {
177
+ // Every player is cloaked: the volley goes somewhere in the room, so the puppy is not shot at more often.
178
+ tx = rnd(40, W - 40);
179
+ ty = rnd(40, 9 * T);
180
+ }
181
+ let best = 1e9;
182
+ for (const p of ps) {
183
+ const dd = Math.hypot(p.x + 13 - cx, p.y + 13 - cy);
184
+ if (dd < best) {
185
+ best = dd;
186
+ tx = p.x + 13;
187
+ ty = p.y + 13;
188
+ }
189
+ }
190
+ }
191
+ const aim = Math.atan2(ty - cy, tx - cx);
192
+ b.plan = bossVolley(patternOf(bossSpecOf(g.lv), b.volley), aim, rage, b.volley);
193
+ b.volley++;
194
+ b.charge = BOSS_TELEGRAPH;
195
+ host.sound('charge');
196
+ const lasts = Math.max(...b.plan.map(s => s.delay));
197
+ b.cd = (b.last ? 40 : rage ? 55 : 80) * (1.3 - 0.5 * Math.min(1, D.e)) + lasts;
198
+ }
199
+ if (b.queue.length) {
200
+ const v = bossShotSpeed(g);
201
+ for (const s of b.queue) {
202
+ if (--s.delay < 0) {
203
+ host.efire(b, Math.cos(s.angle) * v * s.speed, Math.sin(s.angle) * v * s.speed);
204
+ }
205
+ }
206
+ b.queue = b.queue.filter(s => s.delay >= 0);
207
+ }
208
+ for (const p of g.players.filter(isActive)) {
209
+ if (p.shield <= 0 && p.x < b.x + b.s - 4 && p.x + p.s > b.x + 4 && p.y < b.y + b.s - 4 && p.y + p.s > b.y + 4) {
210
+ host.hitPlayer(p);
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,34 @@
1
+ import type { TierKey } from './constants.ts';
2
+ /** One boss per part of the house; names live in the `bosses` messages. */
3
+ export type BossId = 'sleepy' | 'bubble' | 'chef' | 'remote' | 'dusty' | 'nightmare';
4
+ export type BossPattern = 'fan' | 'ring' | 'sweep' | 'cross' | 'spiral';
5
+ export interface BossSpec {
6
+ id: BossId;
7
+ /** Body color, from the Design System palette; Blue and Yellow stay for the players. */
8
+ color: string;
9
+ /** Attack patterns used in turn, one per volley. */
10
+ patterns: readonly BossPattern[];
11
+ }
12
+ export declare const BOSSES: Readonly<Record<TierKey, BossSpec>>;
13
+ /** Frames the boss stands still and shows where it will shoot before every volley. */
14
+ export declare const BOSS_TELEGRAPH = 30;
15
+ /** Fastest a boss shot may fly, in pixels per frame, so a volley can always be outrun once it is shown. */
16
+ export declare const BOSS_BULLET_MAX = 3;
17
+ /**
18
+ * Smallest angle between shots fired together, or one after the other: at 120 px from the boss it leaves a 40 px
19
+ * gap, wide enough for a 26 px tank to slip through.
20
+ */
21
+ export declare const BOSS_SHOT_GAP = 0.36;
22
+ /** A shot of a volley: its direction, how many frames after the volley starts it leaves, and its speed factor. */
23
+ export interface BossShot {
24
+ angle: number;
25
+ delay: number;
26
+ speed: number;
27
+ }
28
+ /** The pattern a boss uses for its `volley`-th volley. */
29
+ export declare function patternOf(spec: BossSpec, volley: number): BossPattern;
30
+ /**
31
+ * The shots of one volley aimed at angle `aim`. A raging boss fires more shots, but never closer together than
32
+ * `BOSS_SHOT_GAP`. `volley` counts the boss's volleys so far and turns rings, crosses and sweeps between volleys.
33
+ */
34
+ export declare function bossVolley(pattern: BossPattern, aim: number, rage: boolean, volley: number): BossShot[];
package/dist/bosses.js ADDED
@@ -0,0 +1,47 @@
1
+ import { COL } from "./constants.js";
2
+ export const BOSSES = {
3
+ bedroom: { id: 'sleepy', color: COL.body, patterns: ['fan'] },
4
+ bathroom: { id: 'bubble', color: COL.soft, patterns: ['ring'] },
5
+ kitchen: { id: 'chef', color: COL.muted, patterns: ['sweep'] },
6
+ livingRoom: { id: 'remote', color: COL.green, patterns: ['cross'] },
7
+ attic: { id: 'dusty', color: COL.muted, patterns: ['spiral'] },
8
+ nightmare: { id: 'nightmare', color: COL.ink2, patterns: ['fan', 'ring', 'sweep', 'cross', 'spiral'] }
9
+ };
10
+ /** Frames the boss stands still and shows where it will shoot before every volley. */
11
+ export const BOSS_TELEGRAPH = 30;
12
+ /** Fastest a boss shot may fly, in pixels per frame, so a volley can always be outrun once it is shown. */
13
+ export const BOSS_BULLET_MAX = 3;
14
+ /**
15
+ * Smallest angle between shots fired together, or one after the other: at 120 px from the boss it leaves a 40 px
16
+ * gap, wide enough for a 26 px tank to slip through.
17
+ */
18
+ export const BOSS_SHOT_GAP = 0.36;
19
+ const ring = (count, offset) => Array.from({ length: count }, (_, i) => offset + (i * Math.PI * 2) / count);
20
+ /** The pattern a boss uses for its `volley`-th volley. */
21
+ export function patternOf(spec, volley) {
22
+ return spec.patterns[volley % spec.patterns.length];
23
+ }
24
+ /**
25
+ * The shots of one volley aimed at angle `aim`. A raging boss fires more shots, but never closer together than
26
+ * `BOSS_SHOT_GAP`. `volley` counts the boss's volleys so far and turns rings, crosses and sweeps between volleys.
27
+ */
28
+ export function bossVolley(pattern, aim, rage, volley) {
29
+ const shot = (angle, delay = 0, speed = 1) => ({ angle, delay, speed });
30
+ const flip = volley % 2 ? -1 : 1;
31
+ if (pattern === 'fan') {
32
+ const n = rage ? 4 : 3;
33
+ return Array.from({ length: n }, (_, i) => shot(aim + (i - (n - 1) / 2) * BOSS_SHOT_GAP));
34
+ }
35
+ if (pattern === 'ring') {
36
+ return ring(rage ? 10 : 8, aim + volley * 0.4).map(a => shot(a, 0, 0.75));
37
+ }
38
+ if (pattern === 'sweep') {
39
+ const n = rage ? 7 : 5;
40
+ return Array.from({ length: n }, (_, i) => shot(aim + flip * (i - (n - 1) / 2) * BOSS_SHOT_GAP, i * 6));
41
+ }
42
+ if (pattern === 'cross') {
43
+ return ring(rage ? 8 : 4, volley % 2 ? Math.PI / 4 : 0).map(a => shot(a));
44
+ }
45
+ const steps = rage ? 5 : 4;
46
+ return ring(3, aim).flatMap(a => Array.from({ length: steps }, (_, k) => shot(a + flip * k * BOSS_SHOT_GAP, k * 12)));
47
+ }
@@ -0,0 +1,133 @@
1
+ /** A map cell as `[column, row]`. */
2
+ export type Cell = readonly [column: number, row: number];
3
+ /** Playable tanks, chosen in the garage. */
4
+ export type TankKind = 'ducky' | 'bunny' | 'robo' | 'dino' | 'bee' | 'crab' | 'firetruck' | 'penguin' | 'turtle' | 'frog' | 'unicorn' | 'swordfish' | 'octopus' | 'giraffe' | 'elephant' | 'mole' | 'cat' | 'bear' | 'piggy';
5
+ export type EnemyKind = 'dust' | 'racer' | 'box' | 'sniper' | 'bomb' | 'rainbow';
6
+ /** Everything `drawTank` can paint. */
7
+ export type SpriteKind = TankKind | EnemyKind | 'boss';
8
+ /** Where one press of fire sends shots: ahead, two side by side, ahead and behind, or a fan of three. */
9
+ export type ShotPattern = 'single' | 'twin' | 'foreAft' | 'fan3';
10
+ /** How a tank's shots look, splash and sound; the first four are the original tanks' own. */
11
+ export type ShotStyle = 'ducky' | 'bunny' | 'robo' | 'dino' | 'needle' | 'shell' | 'water' | 'ice' | 'leaf' | 'rainbow' | 'ink' | 'heavy' | 'spark' | 'heart' | 'coin';
12
+ /**
13
+ * A playable tank. Every special ability is data read by the simulation, so local play and the online room play
14
+ * it the same way; leave a field out for the ordinary behaviour.
15
+ */
16
+ export interface TankSpec {
17
+ id: TankKind;
18
+ cost: number;
19
+ speed: number;
20
+ /** Frames between shots, before power level 3 shortens it. */
21
+ cd: number;
22
+ pattern?: ShotPattern;
23
+ /** Most of this tank's shots on the field at once, before power level 3 adds a volley; two volleys by default. */
24
+ cap?: number;
25
+ /** Factor on the speed of its shots. */
26
+ shotSpeed?: number;
27
+ /** Radius of its shots before power level 4. */
28
+ radius?: number;
29
+ /** A big paint blob: wider, and 2 damage to candy and gifts. */
30
+ big?: boolean;
31
+ /** Damage to an ordinary enemy, doubled at power level 4; a boss always takes 1. */
32
+ dmg?: number;
33
+ /** Pixels a shot travels before it fades, so a faster shot does not reach further. */
34
+ range?: number;
35
+ /** Times a shot bounces off a solid tile or the edge of the field. */
36
+ bounce?: number;
37
+ /** Enemies a shot passes through before it stops; it never hits the same one twice. */
38
+ pierce?: number;
39
+ /**
40
+ * Radius around a hit enemy in which other ordinary enemies lose 1; the splash spares players, the puppy and tiles,
41
+ * though a bomb tank it destroys still blows up as usual.
42
+ */
43
+ splash?: number;
44
+ /** Its shots break blocks, like shots at power level 4. */
45
+ breaksBlock?: boolean;
46
+ /** A hit ordinary enemy moves at `factor` of its speed for `frames`. */
47
+ slow?: {
48
+ factor: number;
49
+ frames: number;
50
+ };
51
+ /** A bomb tank it destroys goes out without exploding. */
52
+ defuse?: boolean;
53
+ /** Frames between enemy shots it can stop with its front. */
54
+ guard?: number;
55
+ /** Drives over water. */
56
+ swim?: boolean;
57
+ /** Frames without firing after which far enemies stop seeing it, as under the cloak. */
58
+ stealth?: number;
59
+ /** Its shots shield a teammate they reach and heal the puppy, each with its own frames of cooldown. */
60
+ support?: {
61
+ shield: number;
62
+ shieldEvery: number;
63
+ healEvery: number;
64
+ };
65
+ /** Radius in which stars and fruit drift toward it. */
66
+ magnet?: number;
67
+ style: ShotStyle;
68
+ }
69
+ export interface EnemySpec {
70
+ speed: number;
71
+ hp: number;
72
+ color: string;
73
+ pts: number;
74
+ }
75
+ /** Part of the house a level takes place in; names live in the `tiers` messages. */
76
+ export type TierKey = 'bedroom' | 'bathroom' | 'kitchen' | 'livingRoom' | 'attic' | 'nightmare';
77
+ export interface Tier {
78
+ key: TierKey;
79
+ to: number;
80
+ /** Tile value and its weight when a map is generated. */
81
+ mats: ReadonlyArray<readonly [tile: number, weight: number]>;
82
+ /** Range of obstacle shapes per map. */
83
+ sh: readonly [min: number, max: number];
84
+ }
85
+ export declare const T = 32;
86
+ export declare const N = 13;
87
+ export declare const W: number;
88
+ export declare const MAXL = 100;
89
+ export declare const COL: {
90
+ blue: string;
91
+ yellow: string;
92
+ green: string;
93
+ red: string;
94
+ ink: string;
95
+ ink2: string;
96
+ body: string;
97
+ muted: string;
98
+ soft: string;
99
+ hair2: string;
100
+ surf: string;
101
+ };
102
+ /** Most players one team can field: two share a keyboard locally, up to five play together online. */
103
+ export declare const MAX_TEAM = 5;
104
+ /** Tank colour of each player, in player order; the first two are the local P1 and P2 colours. */
105
+ export declare const PLAYER_COLORS: readonly string[];
106
+ /** Paint colour by bullet owner: 0 is an enemy shot, `n` is player `n`. */
107
+ export declare const PAINT: readonly string[];
108
+ /** Bonus for clearing a level, before the lives and puppy hearts left are added and the level multiplier applies. */
109
+ export declare const WIN_POINTS = 1000;
110
+ /** Stars for clearing a level, on top of those picked up. */
111
+ export declare const WIN_STARS = 5;
112
+ export declare const TANKS: readonly TankSpec[];
113
+ /** The spec of tank `kind`. */
114
+ export declare function tankSpec(kind: TankKind): TankSpec;
115
+ export declare const ENEMY: Record<EnemyKind, EnemySpec>;
116
+ /** First level where rainbow tanks, whose shots bounce once, may appear. */
117
+ export declare const RAINBOW_FROM = 20;
118
+ /** Speed of a rainbow tank's shot against other enemy shots, slow enough to follow it around a bounce. */
119
+ export declare const RAINBOW_SHOT_SPEED = 0.8;
120
+ export declare const TIERS: readonly Tier[];
121
+ export declare const SPAWNS: readonly Cell[];
122
+ /** Starting cells of the local players; map generation checks that each one can reach the puppy. */
123
+ export declare const STARTS: readonly Cell[];
124
+ /**
125
+ * Starting cells of a whole team, beginning with `STARTS`. The others sit on the bottom rows, which every map
126
+ * keeps clear and joined to the first two, so map generation does not need to know about them.
127
+ */
128
+ export declare const TEAM_STARTS: readonly Cell[];
129
+ export declare const PET: Cell;
130
+ export declare const KMAP: Readonly<Record<string, number>>;
131
+ export declare const KEY = "paintTanks.v2.";
132
+ export declare const DX: readonly number[];
133
+ export declare const DY: readonly number[];