@adatechnology/game-vfx 0.19.0 → 0.20.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/README.md CHANGED
@@ -79,6 +79,7 @@ is the recipes plus these, what a world plays by default. Texts of every recipe
79
79
 
80
80
  ## Vehicle effects
81
81
 
82
+ `VEHICLE_EFFECTS` hold the glass of a car by its kind (`vehicle_glass_chip`: dust and grains off a laminated pane that cracks and stays; `vehicle_glass_shatter`: the glints and dust of a tempered pane letting go, whose dice the vehicle throws itself; never `glass_burst`, the shards of a shopfront) and
82
83
  `VEHICLE_EFFECTS` write the Garagem's recipes around a car: `vehicle_fire` and `vehicle_exhaust` (`engine_smoke`), `vehicle_leak` and `vehicle_leak_ignited` (`fuel_leak`). A normal bullet through a tank only leaks, so
83
84
  `vehicle_leak` is the page's pool and drips without the fire and the explosion (`FUEL_LEAK_ONLY`: the same `decal` and `emit` steps); `vehicle_leak_ignited` is the whole sequence (the spark, the fire running along
84
85
  the pool to the tank and the blast at 7.2 s), played when the leak catches fire.
@@ -4406,8 +4406,36 @@ var GameVfx = (() => {
4406
4406
  loop: 2,
4407
4407
  timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
4408
4408
  };
4409
+ var GLASS_PIECE = 11061464;
4410
+ var GLASS_DUST = 12572386;
4411
+ var HIT = [0, 0, 0];
4412
+ var VEHICLE_GLASS_CHIP = {
4413
+ id: "vehicle_glass_chip",
4414
+ pageId: "vehicle:vehicle_glass_chip",
4415
+ team: "vehicles",
4416
+ budget: { particles: 16, debris: 6 },
4417
+ loop: 2,
4418
+ timeline: [
4419
+ burst("add", 6, { p: HIT, box: [0.04, 0.04, 0.04], size: [8e-3, 0.02], life: [0.12, 0.3], c0: 16777215, a: 0.9, fi: 0.3 }),
4420
+ burst("normal", 6, { p: HIT, dir: NORMAL, sp: [0.3, 0.9], drag: 3, life: [0.4, 0.8], size: [0.04, 0.08], grow: 2, c0: GLASS_DUST, a: 0.18 }),
4421
+ repeat(6, debris({ p: HIT, box: [0.03, 0.03, 0.03], dir: NORMAL, cone: 0.6, sp: [0.4, 1.4], size: [rnd(2e-3, 4e-3), 2e-3, rnd(2e-3, 4e-3)], c: GLASS_PIECE, spin: 20, life: 6, bounce: 0.2 }))
4422
+ ]
4423
+ };
4424
+ var VEHICLE_GLASS_SHATTER = {
4425
+ id: "vehicle_glass_shatter",
4426
+ pageId: "vehicle:vehicle_glass_shatter",
4427
+ team: "vehicles",
4428
+ budget: { particles: 40, debris: 0 },
4429
+ loop: 2,
4430
+ timeline: [
4431
+ burst("add", 24, { p: HIT, box: [0.5, 0.3, 0.5], size: [0.01, 0.03], life: [0.15, 0.5], c0: 16777215, a: 0.9, fi: 0.3 }),
4432
+ burst("normal", 10, { p: [0, -0.15, 0], box: [0.5, 0.2, 0.5], sp: [0.1, 0.4], drag: 2, life: [0.6, 1.1], size: [0.08, 0.14], grow: 2.5, c0: GLASS_DUST, a: 0.14 })
4433
+ ]
4434
+ };
4409
4435
  var VEHICLE_EFFECTS = [
4410
4436
  BODYWORK_IMPACT,
4437
+ VEHICLE_GLASS_CHIP,
4438
+ VEHICLE_GLASS_SHATTER,
4411
4439
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
4412
4440
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
4413
4441
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
@@ -5928,6 +5956,112 @@ var GameVfx = (() => {
5928
5956
  store.add({ kind: "scrape", ...spec, y: spec.y + 2e-3 + nextLift(store) * 2e-4 });
5929
5957
  }
5930
5958
 
5959
+ // src/pools/chunk-motion.ts
5960
+ var RESTITUTION = -0.32;
5961
+ var GROUND_FRICTION = 0.5;
5962
+ var REST_SPEED = 0.6;
5963
+ var REST_SLIDE = 0.5;
5964
+ var TRAIL_SECONDS = 1.8;
5965
+ var TRAIL_STEP = 0.025;
5966
+ var QUARTER_TURN3 = Math.PI / 2;
5967
+ var TOP_FACING = 0.7;
5968
+ var MOVE2 = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
5969
+ function bounce(core, chunk, floor2) {
5970
+ chunk.y = floor2;
5971
+ if (chunk.blood && !chunk.splat && core.layers.mark) {
5972
+ chunk.splat = true;
5973
+ addBloodSplat(core.marks, core.ground, chunk.rng, { x: chunk.x, z: chunk.z, radius: chunk.rng.between(0.06, 0.13) });
5974
+ }
5975
+ chunk.vy *= RESTITUTION;
5976
+ chunk.vx *= GROUND_FRICTION;
5977
+ chunk.vz *= GROUND_FRICTION;
5978
+ chunk.ax *= GROUND_FRICTION;
5979
+ chunk.ay *= GROUND_FRICTION;
5980
+ chunk.az *= GROUND_FRICTION;
5981
+ if (Math.abs(chunk.vy) < REST_SPEED && Math.hypot(chunk.vx, chunk.vz) < REST_SLIDE) {
5982
+ chunk.rest = true;
5983
+ chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
5984
+ chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
5985
+ }
5986
+ }
5987
+ var chunkPad = (chunk) => Math.max(chunk.sx, chunk.sy, chunk.sz) * 0.45;
5988
+ function hitFace(chunk, out) {
5989
+ chunk.x = out.x;
5990
+ chunk.y = out.y;
5991
+ chunk.z = out.z;
5992
+ const into = chunk.vx * out.nx + chunk.vy * out.ny + chunk.vz * out.nz;
5993
+ if (into >= 0) return;
5994
+ const tx = chunk.vx - into * out.nx;
5995
+ const ty = chunk.vy - into * out.ny;
5996
+ const tz = chunk.vz - into * out.nz;
5997
+ const back = into * RESTITUTION;
5998
+ chunk.vx = tx * GROUND_FRICTION + back * out.nx;
5999
+ chunk.vy = ty * GROUND_FRICTION + back * out.ny;
6000
+ chunk.vz = tz * GROUND_FRICTION + back * out.nz;
6001
+ chunk.ax *= GROUND_FRICTION;
6002
+ chunk.ay *= GROUND_FRICTION;
6003
+ chunk.az *= GROUND_FRICTION;
6004
+ if (out.ny > TOP_FACING && Math.abs(back) < REST_SPEED && Math.sqrt(tx * tx + tz * tz) * GROUND_FRICTION < REST_SLIDE) {
6005
+ chunk.rest = true;
6006
+ chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
6007
+ chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
6008
+ }
6009
+ }
6010
+ function leaveTrail(core, chunk, dt) {
6011
+ chunk.trail -= dt;
6012
+ if (chunk.trail > 0) return;
6013
+ chunk.trail = TRAIL_STEP;
6014
+ const random = chunk.rng;
6015
+ addSpark(core, {
6016
+ x: chunk.x,
6017
+ y: chunk.y,
6018
+ z: chunk.z,
6019
+ vx: chunk.vx * 0.15,
6020
+ vy: chunk.vy * 0.15,
6021
+ vz: chunk.vz * 0.15,
6022
+ life: random.between(0.25, 0.45),
6023
+ w: 0.05 + chunk.sx * 0.2,
6024
+ st: 0.05,
6025
+ kind: 0,
6026
+ g: 0,
6027
+ drag: 1,
6028
+ source: chunk.source
6029
+ });
6030
+ if (random.next() < 0.25) {
6031
+ addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
6032
+ }
6033
+ }
6034
+ function updateChunks(core, dt) {
6035
+ const confiner = core.confiner;
6036
+ const confining = !confiner.empty;
6037
+ const chunks = core.chunks.items;
6038
+ for (let index = 0; index < chunks.length; index++) {
6039
+ const chunk = chunks[index];
6040
+ chunk.t += dt;
6041
+ if (chunk.rest) continue;
6042
+ MOVE2.x0 = chunk.x;
6043
+ MOVE2.y0 = chunk.y;
6044
+ MOVE2.z0 = chunk.z;
6045
+ chunk.vy -= core.gravity * dt;
6046
+ chunk.x += chunk.vx * dt;
6047
+ chunk.y += chunk.vy * dt;
6048
+ chunk.z += chunk.vz * dt;
6049
+ chunk.rx += chunk.ax * dt;
6050
+ chunk.ry += chunk.ay * dt;
6051
+ chunk.rz += chunk.az * dt;
6052
+ if (confining) {
6053
+ MOVE2.x1 = chunk.x;
6054
+ MOVE2.y1 = chunk.y;
6055
+ MOVE2.z1 = chunk.z;
6056
+ MOVE2.pad = chunkPad(chunk);
6057
+ if (confiner.confineMove(MOVE2, dt)) hitFace(chunk, confiner.out);
6058
+ }
6059
+ const floor2 = chunk.sy * 0.45 + core.groundAt(chunk.x, chunk.z);
6060
+ if (chunk.y < floor2) bounce(core, chunk, floor2);
6061
+ if (chunk.hot && chunk.t < TRAIL_SECONDS && core.layers.smoke) leaveTrail(core, chunk, dt);
6062
+ }
6063
+ }
6064
+
5931
6065
  // src/pools/rings.ts
5932
6066
  function createRingPool(capacity) {
5933
6067
  return new OrderedPool(capacity, () => ({ x: 0, z: 0, y0: 0, rise: 0, rk: 0, R0: 0, R1: 0, r: 0, roll: 0, t: 0, life: 0 }));
@@ -6062,6 +6196,18 @@ var GameVfx = (() => {
6062
6196
  puff3.z = out.z;
6063
6197
  slideInto(out, puff3);
6064
6198
  }
6199
+ function chunkBornFrom(core, chunk, ox, oy, oz) {
6200
+ const confiner = core.confiner;
6201
+ if (confiner.empty) return;
6202
+ BIRTH.x0 = ox;
6203
+ BIRTH.y0 = oy;
6204
+ BIRTH.z0 = oz;
6205
+ BIRTH.x1 = chunk.x;
6206
+ BIRTH.y1 = chunk.y;
6207
+ BIRTH.z1 = chunk.z;
6208
+ BIRTH.pad = chunkPad(chunk);
6209
+ if (confiner.confineMove(BIRTH, 0)) hitFace(chunk, confiner.out);
6210
+ }
6065
6211
  function composeFireballs(context) {
6066
6212
  const { core, def, random, x, y, z, size, scale, direction } = context;
6067
6213
  if (!core.layers.fire || !def.fireballs) return;
@@ -6246,7 +6392,7 @@ var GameVfx = (() => {
6246
6392
  const sy = plate ? s * 0.3 : s * random.between(0.6, 1);
6247
6393
  const color = hexToRgb(chunks.colors.length > 0 ? pick2(random, chunks.colors) : DEFAULT_CHUNK_COLOR);
6248
6394
  const hot = random.next() < chunks.hot;
6249
- addChunk(core, random, {
6395
+ const chunk = addChunk(core, random, {
6250
6396
  x: x + d.x * 0.2,
6251
6397
  y: y + 0.2,
6252
6398
  z: z + d.z * 0.2,
@@ -6260,10 +6406,11 @@ var GameVfx = (() => {
6260
6406
  plate,
6261
6407
  hot
6262
6408
  });
6409
+ chunkBornFrom(core, chunk, x, y, z);
6263
6410
  }
6264
6411
  }
6265
6412
  function composeRimDebris(context) {
6266
- const { core, random, x, z } = context;
6413
+ const { core, random, x, y, z } = context;
6267
6414
  const radius = context.def.mark.crater ?? 0;
6268
6415
  if (!core.layers.shrapnel) return;
6269
6416
  const speedScale = context.def.chunks.speed ?? 1;
@@ -6274,7 +6421,7 @@ var GameVfx = (() => {
6274
6421
  const s = random.between(0.12, 0.28);
6275
6422
  const vy2 = random.between(4, 10);
6276
6423
  const color = hexToRgb(random.next() < 0.6 ? ROCK_COLORS[0] : ROCK_COLORS[1]);
6277
- addChunk(core, random, {
6424
+ const chunk = addChunk(core, random, {
6278
6425
  x: x + Math.cos(angle) * 0.3,
6279
6426
  y: 0.1,
6280
6427
  z: z + Math.sin(angle) * 0.3,
@@ -6287,6 +6434,7 @@ var GameVfx = (() => {
6287
6434
  color,
6288
6435
  plate: true
6289
6436
  });
6437
+ chunkBornFrom(core, chunk, x, y, z);
6290
6438
  }
6291
6439
  }
6292
6440
  function composeMushroom(context, spec) {
@@ -6418,73 +6566,6 @@ var GameVfx = (() => {
6418
6566
  return scale;
6419
6567
  }
6420
6568
 
6421
- // src/pools/chunk-motion.ts
6422
- var RESTITUTION = -0.32;
6423
- var GROUND_FRICTION = 0.5;
6424
- var REST_SPEED = 0.6;
6425
- var REST_SLIDE = 0.5;
6426
- var TRAIL_SECONDS = 1.8;
6427
- var TRAIL_STEP = 0.025;
6428
- var QUARTER_TURN3 = Math.PI / 2;
6429
- function bounce(core, chunk, floor2) {
6430
- chunk.y = floor2;
6431
- if (chunk.blood && !chunk.splat && core.layers.mark) {
6432
- chunk.splat = true;
6433
- addBloodSplat(core.marks, core.ground, chunk.rng, { x: chunk.x, z: chunk.z, radius: chunk.rng.between(0.06, 0.13) });
6434
- }
6435
- chunk.vy *= RESTITUTION;
6436
- chunk.vx *= GROUND_FRICTION;
6437
- chunk.vz *= GROUND_FRICTION;
6438
- chunk.ax *= GROUND_FRICTION;
6439
- chunk.ay *= GROUND_FRICTION;
6440
- chunk.az *= GROUND_FRICTION;
6441
- if (Math.abs(chunk.vy) < REST_SPEED && Math.hypot(chunk.vx, chunk.vz) < REST_SLIDE) {
6442
- chunk.rest = true;
6443
- chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
6444
- chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
6445
- }
6446
- }
6447
- function leaveTrail(core, chunk, dt) {
6448
- chunk.trail -= dt;
6449
- if (chunk.trail > 0) return;
6450
- chunk.trail = TRAIL_STEP;
6451
- const random = chunk.rng;
6452
- addSpark(core, {
6453
- x: chunk.x,
6454
- y: chunk.y,
6455
- z: chunk.z,
6456
- vx: chunk.vx * 0.15,
6457
- vy: chunk.vy * 0.15,
6458
- vz: chunk.vz * 0.15,
6459
- life: random.between(0.25, 0.45),
6460
- w: 0.05 + chunk.sx * 0.2,
6461
- st: 0.05,
6462
- kind: 0,
6463
- g: 0,
6464
- drag: 1,
6465
- source: chunk.source
6466
- });
6467
- if (random.next() < 0.25) {
6468
- addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
6469
- }
6470
- }
6471
- function updateChunks(core, dt) {
6472
- for (const chunk of core.chunks.items) {
6473
- chunk.t += dt;
6474
- if (chunk.rest) continue;
6475
- chunk.vy -= core.gravity * dt;
6476
- chunk.x += chunk.vx * dt;
6477
- chunk.y += chunk.vy * dt;
6478
- chunk.z += chunk.vz * dt;
6479
- chunk.rx += chunk.ax * dt;
6480
- chunk.ry += chunk.ay * dt;
6481
- chunk.rz += chunk.az * dt;
6482
- const floor2 = chunk.sy * 0.45 + core.groundAt(chunk.x, chunk.z);
6483
- if (chunk.y < floor2) bounce(core, chunk, floor2);
6484
- if (chunk.hot && chunk.t < TRAIL_SECONDS && core.layers.smoke) leaveTrail(core, chunk, dt);
6485
- }
6486
- }
6487
-
6488
6569
  // src/screen.ts
6489
6570
  var DECAY = { shake: 5, white: 7, red: 2.2, side: 3, chroma: 3, desat: 0.7, gasSeconds: 5, beat: 6 };
6490
6571
  var INITIAL_FLASH_DECAY = 6;