@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.
- package/LICENSE +21 -0
- package/dist/ai-host.d.ts +15 -0
- package/dist/ai-host.js +1 -0
- package/dist/balance-config.d.ts +50 -0
- package/dist/balance-config.js +41 -0
- package/dist/boss-ai.d.ts +9 -0
- package/dist/boss-ai.js +213 -0
- package/dist/bosses.d.ts +34 -0
- package/dist/bosses.js +47 -0
- package/dist/constants.d.ts +133 -0
- package/dist/constants.js +163 -0
- package/dist/enemy-ai.d.ts +11 -0
- package/dist/enemy-ai.js +361 -0
- package/dist/game-factory.d.ts +16 -0
- package/dist/game-factory.js +78 -0
- package/dist/game-state.d.ts +256 -0
- package/dist/game-state.js +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +27 -0
- package/dist/labels.d.ts +12 -0
- package/dist/labels.js +129 -0
- package/dist/levels.d.ts +45 -0
- package/dist/levels.js +209 -0
- package/dist/movement.d.ts +25 -0
- package/dist/movement.js +158 -0
- package/dist/online/match.d.ts +28 -0
- package/dist/online/match.js +176 -0
- package/dist/online/prediction.d.ts +41 -0
- package/dist/online/prediction.js +97 -0
- package/dist/online/protocol.d.ts +124 -0
- package/dist/online/protocol.js +54 -0
- package/dist/online/room-game.d.ts +5 -0
- package/dist/online/room-game.js +20 -0
- package/dist/online/view.d.ts +43 -0
- package/dist/online/view.js +347 -0
- package/dist/pathfinding.d.ts +8 -0
- package/dist/pathfinding.js +45 -0
- package/dist/power-ups.d.ts +28 -0
- package/dist/power-ups.js +66 -0
- package/dist/random.d.ts +1 -0
- package/dist/random.js +1 -0
- package/dist/sim-effects.d.ts +30 -0
- package/dist/sim-effects.js +1 -0
- package/dist/simulation.d.ts +74 -0
- package/dist/simulation.js +768 -0
- package/dist/sound-names.d.ts +4 -0
- package/dist/sound-names.js +1 -0
- package/dist/spawning.d.ts +3 -0
- package/dist/spawning.js +56 -0
- package/dist/tank-rules.d.ts +20 -0
- package/dist/tank-rules.js +39 -0
- package/dist/visibility.d.ts +20 -0
- package/dist/visibility.js +39 -0
- package/package.json +43 -3
- package/README.md +0 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export const T = 32;
|
|
2
|
+
export const N = 13;
|
|
3
|
+
export const W = T * N;
|
|
4
|
+
export const MAXL = 100;
|
|
5
|
+
export const COL = {
|
|
6
|
+
blue: '#0052ff',
|
|
7
|
+
yellow: '#f4b000',
|
|
8
|
+
green: '#05b169',
|
|
9
|
+
red: '#cf202f',
|
|
10
|
+
ink: '#0a0b0d',
|
|
11
|
+
ink2: '#16181c',
|
|
12
|
+
body: '#5b616e',
|
|
13
|
+
muted: '#7c828a',
|
|
14
|
+
soft: '#a8acb3',
|
|
15
|
+
hair2: '#eef0f3',
|
|
16
|
+
surf: '#f7f7f7'
|
|
17
|
+
};
|
|
18
|
+
/** Most players one team can field: two share a keyboard locally, up to five play together online. */
|
|
19
|
+
export const MAX_TEAM = 5;
|
|
20
|
+
/** Tank colour of each player, in player order; the first two are the local P1 and P2 colours. */
|
|
21
|
+
export const PLAYER_COLORS = [COL.blue, COL.yellow, '#7c3aed', '#e5398a', '#0891b2'];
|
|
22
|
+
/** Paint colour by bullet owner: 0 is an enemy shot, `n` is player `n`. */
|
|
23
|
+
export const PAINT = ['', ...PLAYER_COLORS];
|
|
24
|
+
/** Bonus for clearing a level, before the lives and puppy hearts left are added and the level multiplier applies. */
|
|
25
|
+
export const WIN_POINTS = 1000;
|
|
26
|
+
/** Stars for clearing a level, on top of those picked up. */
|
|
27
|
+
export const WIN_STARS = 5;
|
|
28
|
+
export const TANKS = [
|
|
29
|
+
{ id: 'ducky', cost: 0, speed: 1.5, cd: 24, style: 'ducky' },
|
|
30
|
+
{ id: 'bunny', cost: 15, speed: 2.1, cd: 22, style: 'bunny' },
|
|
31
|
+
{ id: 'robo', cost: 40, speed: 1.5, cd: 40, cap: 2, pattern: 'twin', style: 'robo' },
|
|
32
|
+
{ id: 'dino', cost: 80, speed: 1.3, cd: 30, big: true, style: 'dino' },
|
|
33
|
+
{ id: 'bee', cost: 20, speed: 1.4, cd: 20, shotSpeed: 1.2, radius: 3, style: 'needle' },
|
|
34
|
+
{ id: 'crab', cost: 25, speed: 1.5, cd: 30, pattern: 'foreAft', cap: 4, style: 'shell' },
|
|
35
|
+
{ id: 'firetruck', cost: 30, speed: 1.4, cd: 12, cap: 3, radius: 3.5, range: 96, defuse: true, style: 'water' },
|
|
36
|
+
{ id: 'penguin', cost: 45, speed: 1.5, cd: 28, slow: { factor: 0.6, frames: 90 }, style: 'ice' },
|
|
37
|
+
{ id: 'turtle', cost: 50, speed: 1.1, cd: 26, guard: 90, style: 'shell' },
|
|
38
|
+
{ id: 'frog', cost: 55, speed: 1.5, cd: 26, swim: true, style: 'leaf' },
|
|
39
|
+
{ id: 'unicorn', cost: 60, speed: 1.5, cd: 30, bounce: 1, style: 'rainbow' },
|
|
40
|
+
{ id: 'swordfish', cost: 70, speed: 1.4, cd: 30, pierce: 1, style: 'needle' },
|
|
41
|
+
{ id: 'octopus', cost: 75, speed: 1.5, cd: 30, pattern: 'fan3', style: 'ink' },
|
|
42
|
+
{ id: 'giraffe', cost: 90, speed: 1.5, cd: 40, cap: 1, shotSpeed: 1.6, dmg: 2, style: 'leaf' },
|
|
43
|
+
{ id: 'elephant', cost: 100, speed: 1.2, cd: 30, splash: 24, style: 'heavy' },
|
|
44
|
+
{ id: 'mole', cost: 110, speed: 1.5, cd: 28, breaksBlock: true, style: 'heavy' },
|
|
45
|
+
{ id: 'cat', cost: 120, speed: 1.6, cd: 24, stealth: 120, style: 'spark' },
|
|
46
|
+
{ id: 'bear', cost: 130, speed: 1.5, cd: 28, support: { shield: 90, shieldEvery: 300, healEvery: 1200 }, style: 'heart' },
|
|
47
|
+
{ id: 'piggy', cost: 150, speed: 1.5, cd: 28, magnet: 40, style: 'coin' }
|
|
48
|
+
];
|
|
49
|
+
/** The spec of tank `kind`. */
|
|
50
|
+
export function tankSpec(kind) {
|
|
51
|
+
return TANKS.find(t => t.id === kind) ?? TANKS[0];
|
|
52
|
+
}
|
|
53
|
+
export const ENEMY = {
|
|
54
|
+
dust: { speed: 0.8, hp: 1, color: COL.muted, pts: 100 },
|
|
55
|
+
racer: { speed: 1.45, hp: 1, color: COL.green, pts: 150 },
|
|
56
|
+
box: { speed: 0.65, hp: 3, color: COL.ink2, pts: 250 },
|
|
57
|
+
sniper: { speed: 0.9, hp: 2, color: COL.red, pts: 300 },
|
|
58
|
+
bomb: { speed: 1.25, hp: 1, color: COL.ink, pts: 200 },
|
|
59
|
+
rainbow: { speed: 0.9, hp: 1, color: COL.body, pts: 200 }
|
|
60
|
+
};
|
|
61
|
+
/** First level where rainbow tanks, whose shots bounce once, may appear. */
|
|
62
|
+
export const RAINBOW_FROM = 20;
|
|
63
|
+
/** Speed of a rainbow tank's shot against other enemy shots, slow enough to follow it around a bounce. */
|
|
64
|
+
export const RAINBOW_SHOT_SPEED = 0.8;
|
|
65
|
+
export const TIERS = [
|
|
66
|
+
{
|
|
67
|
+
key: 'bedroom',
|
|
68
|
+
to: 10,
|
|
69
|
+
mats: [
|
|
70
|
+
[1, 6],
|
|
71
|
+
[2, 2],
|
|
72
|
+
[3, 1],
|
|
73
|
+
[4, 1],
|
|
74
|
+
[6, 2],
|
|
75
|
+
[7, 1]
|
|
76
|
+
],
|
|
77
|
+
sh: [13, 17]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: 'bathroom',
|
|
81
|
+
to: 25,
|
|
82
|
+
mats: [
|
|
83
|
+
[1, 4],
|
|
84
|
+
[2, 2],
|
|
85
|
+
[3, 1],
|
|
86
|
+
[4, 4],
|
|
87
|
+
[6, 1],
|
|
88
|
+
[7, 1]
|
|
89
|
+
],
|
|
90
|
+
sh: [13, 17]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: 'kitchen',
|
|
94
|
+
to: 50,
|
|
95
|
+
mats: [
|
|
96
|
+
[1, 2],
|
|
97
|
+
[2, 6],
|
|
98
|
+
[3, 2],
|
|
99
|
+
[4, 1],
|
|
100
|
+
[6, 2],
|
|
101
|
+
[7, 1]
|
|
102
|
+
],
|
|
103
|
+
sh: [15, 19]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: 'livingRoom',
|
|
107
|
+
to: 75,
|
|
108
|
+
mats: [
|
|
109
|
+
[1, 3],
|
|
110
|
+
[2, 3],
|
|
111
|
+
[3, 4],
|
|
112
|
+
[4, 1],
|
|
113
|
+
[6, 3],
|
|
114
|
+
[7, 1]
|
|
115
|
+
],
|
|
116
|
+
sh: [15, 19]
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: 'attic',
|
|
120
|
+
to: 95,
|
|
121
|
+
mats: [
|
|
122
|
+
[1, 4],
|
|
123
|
+
[2, 3],
|
|
124
|
+
[3, 3],
|
|
125
|
+
[4, 2],
|
|
126
|
+
[6, 3],
|
|
127
|
+
[7, 1]
|
|
128
|
+
],
|
|
129
|
+
sh: [16, 20]
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: 'nightmare',
|
|
133
|
+
to: 100,
|
|
134
|
+
mats: [
|
|
135
|
+
[1, 3],
|
|
136
|
+
[2, 1],
|
|
137
|
+
[3, 2],
|
|
138
|
+
[4, 1],
|
|
139
|
+
[6, 5]
|
|
140
|
+
],
|
|
141
|
+
sh: [8, 11]
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
export const SPAWNS = [
|
|
145
|
+
[0, 0],
|
|
146
|
+
[6, 0],
|
|
147
|
+
[12, 0]
|
|
148
|
+
];
|
|
149
|
+
/** Starting cells of the local players; map generation checks that each one can reach the puppy. */
|
|
150
|
+
export const STARTS = [
|
|
151
|
+
[4, 12],
|
|
152
|
+
[8, 12]
|
|
153
|
+
];
|
|
154
|
+
/**
|
|
155
|
+
* Starting cells of a whole team, beginning with `STARTS`. The others sit on the bottom rows, which every map
|
|
156
|
+
* keeps clear and joined to the first two, so map generation does not need to know about them.
|
|
157
|
+
*/
|
|
158
|
+
export const TEAM_STARTS = [...STARTS, [2, 12], [10, 12], [0, 12]];
|
|
159
|
+
export const PET = [6, 12];
|
|
160
|
+
export const KMAP = { ArrowUp: 0, ArrowRight: 1, ArrowDown: 2, ArrowLeft: 3, KeyW: 0, KeyD: 1, KeyS: 2, KeyA: 3 };
|
|
161
|
+
export const KEY = 'paintTanks.v2.';
|
|
162
|
+
export const DX = [0, 1, 0, -1];
|
|
163
|
+
export const DY = [-1, 0, 1, 0];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AiHost } from './ai-host.ts';
|
|
2
|
+
import type { Enemy, Game } from './game-state.ts';
|
|
3
|
+
export declare function frontTile(g: Game, e: Enemy): number;
|
|
4
|
+
export declare function aimDir(g: Game, e: Enemy): number;
|
|
5
|
+
export declare function los(g: Game, x0: number, y0: number, x1: number, y1: number, soft: boolean): boolean;
|
|
6
|
+
export declare function threat(g: Game, e: Enemy): number;
|
|
7
|
+
/** Share of its speed an enemy moves at: less while a slowing shot still holds it. */
|
|
8
|
+
export declare function slowFactor(e: Enemy): number;
|
|
9
|
+
export declare function bombAI(host: AiHost, e: Enemy): void;
|
|
10
|
+
export declare function enemyAI(host: AiHost, e: Enemy): void;
|
|
11
|
+
export declare function pickDir(g: Game, e: Enemy): number;
|
package/dist/enemy-ai.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { DX, DY, N, PET, RAINBOW_SHOT_SPEED, T, W } from "./constants.js";
|
|
2
|
+
import { isAligned, isBlocked, move, turn } from "./movement.js";
|
|
3
|
+
import { rnd } from "./random.js";
|
|
4
|
+
import { hiddenFrom, huntablePlayers, isActive, someoneCloaked } from "./visibility.js";
|
|
5
|
+
export function frontTile(g, e) {
|
|
6
|
+
const cx = e.x + e.s / 2 + DX[e.dir] * (e.s / 2 + 4);
|
|
7
|
+
const cy = e.y + e.s / 2 + DY[e.dir] * (e.s / 2 + 4);
|
|
8
|
+
const c = Math.floor(cx / T);
|
|
9
|
+
const r = Math.floor(cy / T);
|
|
10
|
+
return c < 0 || r < 0 || c >= N || r >= N ? -1 : g.map[r][c];
|
|
11
|
+
}
|
|
12
|
+
export function aimDir(g, e) {
|
|
13
|
+
const cx = e.x + 13;
|
|
14
|
+
const cy = e.y + 13;
|
|
15
|
+
for (const p of g.players) {
|
|
16
|
+
if (!isActive(p) || hiddenFrom(g, p, cx, cy)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const tx = p.x + 13;
|
|
20
|
+
const ty = p.y + 13;
|
|
21
|
+
if (Math.abs(tx - cx) < 10 && los(g, cx, cy, tx, ty, false)) {
|
|
22
|
+
return ty > cy ? 2 : 0;
|
|
23
|
+
}
|
|
24
|
+
if (Math.abs(ty - cy) < 10 && los(g, cx, cy, tx, ty, false)) {
|
|
25
|
+
return tx > cx ? 1 : 3;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const tx = PET[0] * T + 16;
|
|
29
|
+
const ty = PET[1] * T + 16;
|
|
30
|
+
const soft = e.kind !== 'sniper';
|
|
31
|
+
if (Math.abs(tx - cx) < 10 && los(g, cx, cy, tx, ty, soft)) {
|
|
32
|
+
return ty > cy ? 2 : 0;
|
|
33
|
+
}
|
|
34
|
+
if (Math.abs(ty - cy) < 10 && los(g, cx, cy, tx, ty, soft)) {
|
|
35
|
+
return tx > cx ? 1 : 3;
|
|
36
|
+
}
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
export function los(g, x0, y0, x1, y1, soft) {
|
|
40
|
+
const n = Math.ceil(Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0)) / 10);
|
|
41
|
+
for (let i = 1; i < n; i++) {
|
|
42
|
+
const x = x0 + ((x1 - x0) * i) / n;
|
|
43
|
+
const y = y0 + ((y1 - y0) * i) / n;
|
|
44
|
+
const row = g.map[Math.floor(y / T)];
|
|
45
|
+
const v = row ? row[Math.floor(x / T)] : 0;
|
|
46
|
+
if (v === 3) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (!soft && (v === 1 || v === 2 || v === 7)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
export function threat(g, e) {
|
|
56
|
+
const cx = e.x + 13;
|
|
57
|
+
const cy = e.y + 13;
|
|
58
|
+
for (const b of g.bullets) {
|
|
59
|
+
if (!b.owner || b.dead) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (b.vx === 0 && Math.abs(b.x - cx) < 15) {
|
|
63
|
+
const dy = cy - b.y;
|
|
64
|
+
if (dy * b.vy > 0 && Math.abs(dy) < 130) {
|
|
65
|
+
return b.y < cy ? 0 : 2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (b.vy === 0 && Math.abs(b.y - cy) < 15) {
|
|
69
|
+
const dx = cx - b.x;
|
|
70
|
+
if (dx * b.vx > 0 && Math.abs(dx) < 130) {
|
|
71
|
+
return b.x < cx ? 3 : 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return -1;
|
|
76
|
+
}
|
|
77
|
+
/** Share of its speed an enemy moves at: less while a slowing shot still holds it. */
|
|
78
|
+
export function slowFactor(e) {
|
|
79
|
+
return e.slow ? (e.slowF ?? 1) : 1;
|
|
80
|
+
}
|
|
81
|
+
export function bombAI(host, e) {
|
|
82
|
+
const g = host.game;
|
|
83
|
+
const cx = e.x + 13;
|
|
84
|
+
const cy = e.y + 13;
|
|
85
|
+
let near = 1e9;
|
|
86
|
+
let touch = false;
|
|
87
|
+
for (const p of g.players) {
|
|
88
|
+
if (p.alive && !p.respawn) {
|
|
89
|
+
const dx = Math.abs(p.x + 13 - cx);
|
|
90
|
+
const dy = Math.abs(p.y + 13 - cy);
|
|
91
|
+
near = Math.min(near, Math.hypot(dx, dy));
|
|
92
|
+
if (dx < 31 && dy < 31) {
|
|
93
|
+
touch = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const pdx = Math.abs(PET[0] * T + 16 - cx);
|
|
98
|
+
const pdy = Math.abs(PET[1] * T + 16 - cy);
|
|
99
|
+
const pd = Math.hypot(pdx, pdy);
|
|
100
|
+
e.fuse = near < 72 || pd < 60;
|
|
101
|
+
if (touch || (pdx < 36 && pdy < 36)) {
|
|
102
|
+
host.killEnemy(e, true);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const sp = Math.min(2.2, e.speed * (e.fuse ? 1.25 : 1)) * slowFactor(e);
|
|
106
|
+
const cell = Math.floor(cx / T) + Math.floor(cy / T) * N;
|
|
107
|
+
if (isAligned(e, sp) && cell !== e.cell) {
|
|
108
|
+
e.cell = cell;
|
|
109
|
+
e.turnT = 1;
|
|
110
|
+
}
|
|
111
|
+
e.age = (e.age || 0) + 1;
|
|
112
|
+
if (e.age > 2400) {
|
|
113
|
+
host.killEnemy(e, true);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (e.route !== undefined && e.route > 0) {
|
|
117
|
+
e.route--;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
let d = -1;
|
|
121
|
+
for (const p of huntablePlayers(g)) {
|
|
122
|
+
const tx = p.x + 13;
|
|
123
|
+
const ty = p.y + 13;
|
|
124
|
+
if (Math.abs(tx - cx) < 10 && los(g, cx, cy, tx, ty, false)) {
|
|
125
|
+
d = ty > cy ? 2 : 0;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (Math.abs(ty - cy) < 10 && los(g, cx, cy, tx, ty, false)) {
|
|
129
|
+
d = tx > cx ? 1 : 3;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (d >= 0 && d !== e.dir) {
|
|
134
|
+
turn(g, e, d);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const mv = move(g, e, sp);
|
|
138
|
+
const ft = mv ? 0 : frontTile(g, e);
|
|
139
|
+
if (mv) {
|
|
140
|
+
e.anim += sp;
|
|
141
|
+
e.stuck = 0;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
e.stuck++;
|
|
145
|
+
if ((e.fuse && e.stuck > 6) || (e.stuck > 40 && [1, 2, 7].includes(ft))) {
|
|
146
|
+
host.killEnemy(e, true);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!mv && e.stuck % 10 === 1 && e.stuck > 20 && ![1, 2, 7].includes(ft)) {
|
|
151
|
+
const opts = [0, 1, 2, 3].filter(d => d !== e.dir && !isBlocked(g, e, e.x + DX[d] * 2, e.y + DY[d] * 2));
|
|
152
|
+
if (opts.length) {
|
|
153
|
+
turn(g, e, opts[Math.floor(Math.random() * opts.length)]);
|
|
154
|
+
e.turnT = rnd(25, 45);
|
|
155
|
+
e.route = 30;
|
|
156
|
+
e.stuck = 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if ((!mv && e.stuck % 10 === 1) || --e.turnT <= 0) {
|
|
160
|
+
turn(g, e, pickDir(g, e));
|
|
161
|
+
e.turnT = rnd(20, 50);
|
|
162
|
+
if (!mv) {
|
|
163
|
+
e.route = 20;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (e.stuck > 200) {
|
|
167
|
+
host.killEnemy(e, true);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export function enemyAI(host, e) {
|
|
171
|
+
const g = host.game;
|
|
172
|
+
const D = g.D;
|
|
173
|
+
if (e.spawning > 0) {
|
|
174
|
+
e.spawning--;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (e.flash > 0) {
|
|
178
|
+
e.flash--;
|
|
179
|
+
}
|
|
180
|
+
if (e.slow) {
|
|
181
|
+
e.slow--;
|
|
182
|
+
}
|
|
183
|
+
if (g.freeze > 0) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (e.kind === 'bomb') {
|
|
187
|
+
bombAI(host, e);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const sp = Math.min(2.6, e.speed * (e.angry ? 1.3 : 1)) * slowFactor(e);
|
|
191
|
+
if (isAligned(e, sp)) {
|
|
192
|
+
const cell = Math.floor((e.x + 13) / T) + Math.floor((e.y + 13) / T) * N;
|
|
193
|
+
if (cell !== e.cell) {
|
|
194
|
+
e.cell = cell;
|
|
195
|
+
if (Math.random() < D.smart) {
|
|
196
|
+
e.turnT = 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (e.dodgeT > 0) {
|
|
201
|
+
e.dodgeT--;
|
|
202
|
+
if (move(g, e, sp)) {
|
|
203
|
+
e.anim += sp;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
e.dodgeT = 0;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (D.edodge && g.t % 5 === 0) {
|
|
211
|
+
const th = threat(g, e);
|
|
212
|
+
if (th >= 0 && Math.random() < D.edodge * (e.kind === 'racer' ? 0.5 : 0.35)) {
|
|
213
|
+
if (e.dir === th) {
|
|
214
|
+
e.cd = Math.min(e.cd, 1);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const opts = th % 2 ? [0, 2] : [1, 3];
|
|
218
|
+
if (Math.random() < 0.5) {
|
|
219
|
+
opts.reverse();
|
|
220
|
+
}
|
|
221
|
+
for (const d of opts) {
|
|
222
|
+
if (!isBlocked(g, e, e.x + DX[d] * 6, e.y + DY[d] * 6)) {
|
|
223
|
+
turn(g, e, d);
|
|
224
|
+
e.dodgeT = 16;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (--e.aimT <= 0) {
|
|
232
|
+
e.aimT = 8;
|
|
233
|
+
const a = e.kind === 'sniper' ? 1 : Math.min(1, D.aim * (e.angry ? 1.3 : 1));
|
|
234
|
+
if (Math.random() < a * 0.5) {
|
|
235
|
+
const d = aimDir(g, e);
|
|
236
|
+
if (d >= 0) {
|
|
237
|
+
turn(g, e, d);
|
|
238
|
+
if (e.dir === d) {
|
|
239
|
+
e.cd = Math.min(e.cd, e.kind === 'sniper' ? 4 : 12);
|
|
240
|
+
if (e.kind === 'sniper') {
|
|
241
|
+
e.hold = 24;
|
|
242
|
+
}
|
|
243
|
+
else if (Math.random() < D.smart * 0.4) {
|
|
244
|
+
e.hold = 10;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (e.hold > 0) {
|
|
251
|
+
e.hold--;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const mv = move(g, e, sp);
|
|
255
|
+
if (mv) {
|
|
256
|
+
e.anim += sp;
|
|
257
|
+
e.stuck = 0;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
e.stuck++;
|
|
261
|
+
const v = frontTile(g, e);
|
|
262
|
+
if (v === 1 || v === 2 || v === 7) {
|
|
263
|
+
e.cd = Math.min(e.cd, 14);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (e.stuck > 40 || (!mv && e.stuck % 12 === 1 && ![1, 2, 7].includes(frontTile(g, e))) || --e.turnT <= 0) {
|
|
267
|
+
turn(g, e, pickDir(g, e));
|
|
268
|
+
e.turnT = rnd(30, 90) * (1 - 0.6 * Math.min(1, D.e));
|
|
269
|
+
if (e.stuck > 40) {
|
|
270
|
+
e.stuck = 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (--e.cd <= 0 && g.t - (e.ls ?? -999) >= (e.kind === 'sniper' ? 42 : 26) * (e.angry ? 0.7 : 1)) {
|
|
276
|
+
e.ls = g.t;
|
|
277
|
+
if (e.kind === 'rainbow') {
|
|
278
|
+
const v = D.eb * RAINBOW_SHOT_SPEED;
|
|
279
|
+
host.efire(e, DX[e.dir] * v, DY[e.dir] * v, { bounce: 1, rainbow: true });
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
const v = e.kind === 'sniper' ? D.eb + 1 : D.eb;
|
|
283
|
+
host.efire(e, DX[e.dir] * v, DY[e.dir] * v);
|
|
284
|
+
}
|
|
285
|
+
e.cd = rnd(...D.fire) * (e.angry ? 0.55 : 1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
export function pickDir(g, e) {
|
|
289
|
+
const D = g.D;
|
|
290
|
+
const cx = e.x + 13;
|
|
291
|
+
const cy = e.y + 13;
|
|
292
|
+
const c = Math.floor(cx / T);
|
|
293
|
+
const r = Math.floor(cy / T);
|
|
294
|
+
const fld = e.kind === 'bomb'
|
|
295
|
+
? g.bfield && g.bfield[r][c] < 1e5
|
|
296
|
+
? g.bfield
|
|
297
|
+
: g.pfield || g.field
|
|
298
|
+
: e.role === 'hunt' && g.pfield
|
|
299
|
+
? g.pfield
|
|
300
|
+
: g.field;
|
|
301
|
+
if ((e.kind === 'bomb' || Math.random() < D.smart) && fld && e.stuck <= 40) {
|
|
302
|
+
let best = -1;
|
|
303
|
+
let bv = 1e9;
|
|
304
|
+
for (let d = 0; d < 4; d++) {
|
|
305
|
+
const nc = c + DX[d];
|
|
306
|
+
const nr = r + DY[d];
|
|
307
|
+
if (nc < 0 || nr < 0 || nc >= N || nr >= N) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
let v = fld[nr][nc];
|
|
311
|
+
if (v >= 1e5) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
v += Math.random() * (e.role === 'flank' ? 2 : 0.5);
|
|
315
|
+
if (e.role === 'flank') {
|
|
316
|
+
v -= e.bias * (nc - 6) * 0.4;
|
|
317
|
+
}
|
|
318
|
+
if (d === (e.dir + 2) % 4) {
|
|
319
|
+
v += 1.2;
|
|
320
|
+
}
|
|
321
|
+
for (const o of g.enemies) {
|
|
322
|
+
if (o !== e && Math.floor((o.x + 13) / T) === nc && Math.floor((o.y + 13) / T) === nr) {
|
|
323
|
+
v += 4;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (v < bv) {
|
|
327
|
+
bv = v;
|
|
328
|
+
best = d;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (best >= 0) {
|
|
332
|
+
return best;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const ps = huntablePlayers(g);
|
|
336
|
+
let tx, ty;
|
|
337
|
+
if (Math.random() < 0.5 || (!ps.length && !someoneCloaked(g))) {
|
|
338
|
+
tx = PET[0] * T + 16;
|
|
339
|
+
ty = PET[1] * T + 16;
|
|
340
|
+
}
|
|
341
|
+
else if (ps.length) {
|
|
342
|
+
const p = ps[Math.floor(Math.random() * ps.length)];
|
|
343
|
+
tx = p.x + 13;
|
|
344
|
+
ty = p.y + 13;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// Every player is cloaked: search somewhere instead of heading for the puppy more often.
|
|
348
|
+
tx = rnd(16, W - 16);
|
|
349
|
+
ty = rnd(16, W - 16);
|
|
350
|
+
}
|
|
351
|
+
const dx = tx - cx;
|
|
352
|
+
const dy = ty - cy;
|
|
353
|
+
const pref = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 1 : 3) : dy > 0 ? 2 : 0;
|
|
354
|
+
const cand = Math.random() < 0.6 ? [pref, 0, 1, 2, 3] : [Math.floor(Math.random() * 4), pref, 0, 1, 2, 3];
|
|
355
|
+
for (const d of cand) {
|
|
356
|
+
if (!isBlocked(g, e, e.x + DX[d] * 2, e.y + DY[d] * 2)) {
|
|
357
|
+
return d;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return Math.floor(Math.random() * 4);
|
|
361
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TankKind } from './constants.ts';
|
|
2
|
+
import type { Game } from './game-state.ts';
|
|
3
|
+
/** What the player carried over from the level they just cleared. */
|
|
4
|
+
export interface CarryOver {
|
|
5
|
+
lv: number;
|
|
6
|
+
up: number[];
|
|
7
|
+
}
|
|
8
|
+
export interface NewGameOptions {
|
|
9
|
+
lv: number;
|
|
10
|
+
difficultyScale: number;
|
|
11
|
+
/** The tank of each player, in player order; one to `MAX_TEAM` players. */
|
|
12
|
+
tanks: readonly TankKind[];
|
|
13
|
+
carry: CarryOver | null;
|
|
14
|
+
}
|
|
15
|
+
/** A fresh game of level `lv`: its map, the players on their starting cells, and nothing else on the field. */
|
|
16
|
+
export declare function createGame({ lv, difficultyScale, tanks, carry }: NewGameOptions): Game;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MAX_TEAM, PLAYER_COLORS, T, TANKS, TEAM_STARTS } from "./constants.js";
|
|
2
|
+
import { diffOf, genMap, teamDifficulty } from "./levels.js";
|
|
3
|
+
/** A fresh game of level `lv`: its map, the players on their starting cells, and nothing else on the field. */
|
|
4
|
+
export function createGame({ lv, difficultyScale, tanks, carry }) {
|
|
5
|
+
if (tanks.length > MAX_TEAM) {
|
|
6
|
+
throw new RangeError(`A team has at most ${MAX_TEAM} players`);
|
|
7
|
+
}
|
|
8
|
+
const D = teamDifficulty(diffOf(lv, difficultyScale), tanks.length);
|
|
9
|
+
const map = genMap(lv);
|
|
10
|
+
const hp = map.map(r => r.map(v => (v === 2 ? 2 : v === 7 ? 3 : 1)));
|
|
11
|
+
const players = tanks.map((kind, i) => {
|
|
12
|
+
const k = TANKS.find(t => t.id === kind) || TANKS[0];
|
|
13
|
+
const [c, r] = TEAM_STARTS[i];
|
|
14
|
+
return {
|
|
15
|
+
player: true,
|
|
16
|
+
up: (carry && carry.lv === lv - 1 && carry.up[i]) || 1,
|
|
17
|
+
idx: i,
|
|
18
|
+
kind: k.id,
|
|
19
|
+
spec: k,
|
|
20
|
+
s: 26,
|
|
21
|
+
x: c * T + 3,
|
|
22
|
+
y: r * T + 3,
|
|
23
|
+
sx: c * T + 3,
|
|
24
|
+
sy: r * T + 3,
|
|
25
|
+
dir: 0,
|
|
26
|
+
speed: k.speed,
|
|
27
|
+
cd: 0,
|
|
28
|
+
lives: D.lives,
|
|
29
|
+
alive: true,
|
|
30
|
+
respawn: 0,
|
|
31
|
+
shield: 120,
|
|
32
|
+
cloak: 0,
|
|
33
|
+
anim: 0,
|
|
34
|
+
color: PLAYER_COLORS[i]
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
state: 'play',
|
|
39
|
+
t: 0,
|
|
40
|
+
lv,
|
|
41
|
+
D,
|
|
42
|
+
mult: 1 + lv / 20,
|
|
43
|
+
map,
|
|
44
|
+
hp,
|
|
45
|
+
players,
|
|
46
|
+
enemies: [],
|
|
47
|
+
bullets: [],
|
|
48
|
+
parts: [],
|
|
49
|
+
picks: [],
|
|
50
|
+
texts: [],
|
|
51
|
+
boss: null,
|
|
52
|
+
bossDone: false,
|
|
53
|
+
bossT: null,
|
|
54
|
+
toSpawn: D.count,
|
|
55
|
+
total: D.count,
|
|
56
|
+
kills: 0,
|
|
57
|
+
spawnT: 50,
|
|
58
|
+
spawnIdx: 0,
|
|
59
|
+
petHp: D.pet,
|
|
60
|
+
petFlash: 0,
|
|
61
|
+
freeze: 0,
|
|
62
|
+
stars: 0,
|
|
63
|
+
score: 0,
|
|
64
|
+
rush: false,
|
|
65
|
+
field: null,
|
|
66
|
+
pfield: null,
|
|
67
|
+
bfield: null,
|
|
68
|
+
fieldDirty: true,
|
|
69
|
+
banner: { key: D.boss ? 'bannerBoss' : 'bannerProtect', params: { level: lv }, life: 120 },
|
|
70
|
+
endT: 0,
|
|
71
|
+
result: null,
|
|
72
|
+
shake: 0,
|
|
73
|
+
spawnCount: 0,
|
|
74
|
+
bombSeen: false,
|
|
75
|
+
carrierSeen: false,
|
|
76
|
+
rainbowSeen: false
|
|
77
|
+
};
|
|
78
|
+
}
|