@vibe-engine/cli 0.1.0 → 0.1.2
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/dist/assets.d.ts +1 -0
- package/dist/assets.js +13 -7
- package/dist/create.js +3 -0
- package/dist/main.js +11 -4
- package/dist/run.d.ts +2 -0
- package/dist/run.js +1 -1
- package/dist/session-daemon.d.ts +1 -0
- package/dist/session-daemon.js +103 -0
- package/dist/session-host.d.ts +29 -0
- package/dist/session-host.js +226 -0
- package/dist/session.d.ts +6 -0
- package/dist/session.js +256 -0
- package/dist/typecheck.d.ts +15 -0
- package/dist/typecheck.js +68 -0
- package/package.json +4 -4
- package/templates/arena-3d/AGENTS.md +4 -4
- package/templates/arena-3d/tests/arena.test.ts +1 -1
- package/templates/platformer-2d/AGENTS.md +4 -4
- package/templates/platformer-2d/tests/gameplay.test.ts +1 -1
- package/templates/shooter-2d-pvp/AGENTS.md +12 -11
- package/templates/shooter-2d-pvp/README.md +1 -1
- package/templates/shooter-2d-pvp/src/components/gun.component.ts +2 -13
- package/templates/shooter-2d-pvp/src/events/combat.events.ts +0 -2
- package/templates/shooter-2d-pvp/src/level/build.ts +2 -2
- package/templates/shooter-2d-pvp/src/listeners/effects.listener.ts +2 -22
- package/templates/shooter-2d-pvp/src/listeners/players.listener.ts +3 -2
- package/templates/shooter-2d-pvp/src/maps/arena.map.ts +1 -1
- package/templates/shooter-2d-pvp/src/rules/damage.ts +4 -19
- package/templates/shooter-2d-pvp/src/scenes/arena.scene.ts +2 -2
- package/templates/shooter-2d-pvp/src/systems/combat.system.ts +3 -13
- package/templates/shooter-2d-pvp/src/systems/gun.system.ts +9 -30
- package/templates/shooter-2d-pvp/src/systems/view.system.ts +1 -1
- package/templates/shooter-2d-pvp/tests/pvp.test.ts +26 -38
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineListener, type World } from '@vibe-engine/core';
|
|
2
|
-
import { CameraShake, ParticleBurst,
|
|
3
|
-
import {
|
|
4
|
-
import { BulletImpact, FighterHit, FighterJumped, FighterKilled, FighterLanded, FighterRespawned, KnifeSwung, RifleFired, RocketExploded, RocketFired, ShotFired, WeaponSwapped } from '../events/combat.events.ts';
|
|
2
|
+
import { CameraShake, ParticleBurst, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { BulletImpact, FighterHit, FighterJumped, FighterKilled, FighterLanded, FighterRespawned, KnifeSwung, RifleFired, ShotFired, WeaponSwapped } from '../events/combat.events.ts';
|
|
5
4
|
|
|
6
5
|
const pos = (world: World, id: string) => (world.exists(id) ? world.entity(id).read(Transform2D) : null);
|
|
7
6
|
/** Tremor só para quem está envolvido: o seu tiro, você levando ou dando dano. */
|
|
@@ -48,24 +47,5 @@ export const Effects = defineListener('arena.effects', (on) => {
|
|
|
48
47
|
if (mine(world, e.fighter, e.by)) emit(CameraShake, { amount: 3.5, seconds: 0.3 });
|
|
49
48
|
});
|
|
50
49
|
on(FighterRespawned, (e, { world, emit }) => { const p = pos(world, e.fighter); if (p) emit(ParticleBurst, { x: p.x, y: p.y, preset: 'smoke' }); });
|
|
51
|
-
on(RocketFired, (e, { world, audio, emit }) => {
|
|
52
|
-
audio.play('audio/shoot', { volume: 0.6, pitch: 0.45, at: e.gun });
|
|
53
|
-
const g = pos(world, e.gun);
|
|
54
|
-
if (g) emit(ParticleBurst, { x: g.x - e.dir.x * 8, y: g.y - e.dir.y * 8, preset: 'smoke' });
|
|
55
|
-
if (mine(world, e.gun)) emit(CameraShake, { amount: 1.5, seconds: 0.1 });
|
|
56
|
-
});
|
|
57
|
-
on(RocketExploded, (e, { world, audio, emit }) => {
|
|
58
|
-
audio.play('audio/enemy-defeat', { volume: 0.9, pitch: 0.6, at: { x: e.x, y: e.y } }); // shortcut: estrondo com o som de derrota grave até ter um som próprio
|
|
59
|
-
emit(ParticleBurst, { x: e.x, y: e.y, preset: 'explosion', config: { count: 30, speed: [60, 200] } });
|
|
60
|
-
emit(ParticleBurst, { x: e.x, y: e.y, preset: 'smoke', config: { count: 4 } });
|
|
61
|
-
const me = pos(world, `fighter-${world.localPlayer}`);
|
|
62
|
-
if (me && Math.hypot(me.x - e.x, me.y - e.y) < 160) emit(CameraShake, { amount: 3, seconds: 0.25 });
|
|
63
|
-
});
|
|
64
|
-
// Terra voando de cada tile que a explosão arrancou (cor do chão, para cima).
|
|
65
|
-
on(TilesDestroyed, (e, { world, emit }) => {
|
|
66
|
-
const map = pos(world, e.map);
|
|
67
|
-
if (!map) return;
|
|
68
|
-
for (const c of e.cells) emit(ParticleBurst, { x: map.x + (c.x + 0.5) * TILE, y: map.y + (c.y + 0.5) * TILE, preset: 'dust', config: { count: 3, color: ['#b0764a', '#6b4a32'], speed: [40, 110], gravity: 260 } });
|
|
69
|
-
});
|
|
70
50
|
on(BulletImpact, (e, { emit }) => emit(ParticleBurst, { x: e.x, y: e.y, preset: 'sparks', config: { count: 6 } }));
|
|
71
51
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineListener } from '@vibe-engine/core';
|
|
2
2
|
import { Collider2D, Label2D, RigidBody2D, Sprite, Transform2D } from '@vibe-engine/2d';
|
|
3
|
-
import { NetPlayerJoined, NetPlayerLeft } from '@vibe-engine/net';
|
|
3
|
+
import { NetOwner, NetPlayerJoined, NetPlayerLeft } from '@vibe-engine/net';
|
|
4
4
|
import { COLORS, Fighter } from '../components/fighter.component.ts';
|
|
5
5
|
import { Arena, Gun } from '../components/gun.component.ts';
|
|
6
6
|
import { spawnPoints } from '../level/build.ts';
|
|
@@ -22,8 +22,9 @@ export const Players = defineListener('arena.players', (on) => {
|
|
|
22
22
|
Collider2D.box({ width: 14, height: 18, offset: { x: 0, y: 3 }, friction: 0 }),
|
|
23
23
|
Fighter({ owner: player, color, name, spawn: at, invulnerable: 90 }),
|
|
24
24
|
Label2D({ text: name, offset: { x: 0, y: -13 }, size: 16, background: '#f4f4f2b3', owner: player }), // o próprio sai com as cores trocadas
|
|
25
|
+
NetOwner({ player }), // nos outros clientes, desenhado interpolado (desliza) em vez de previsto
|
|
25
26
|
]);
|
|
26
|
-
world.spawn(`gun-${player}`, [Transform2D(at), Sprite({ asset: 'sprites/pistol', layer: 4, anchor: { x: 0.25, y: 0.5 } }), Gun({ owner: player })]);
|
|
27
|
+
world.spawn(`gun-${player}`, [Transform2D(at), Sprite({ asset: 'sprites/pistol', layer: 4, anchor: { x: 0.25, y: 0.5 } }), Gun({ owner: player }), NetOwner({ player })]);
|
|
27
28
|
});
|
|
28
29
|
on(NetPlayerLeft, ({ player }, { world }) => {
|
|
29
30
|
if (world.exists(`fighter-${player}`)) world.despawn(`fighter-${player}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineMap } from '@vibe-engine/core';
|
|
2
2
|
|
|
3
|
-
/** A arena. `S` = ponto de nascimento (um por jogador, em ordem de entrada); `%` = rocha (
|
|
3
|
+
/** A arena. `S` = ponto de nascimento (um por jogador, em ordem de entrada); `%` = rocha (borda e fundo). `vibe map show arena`. */
|
|
4
4
|
export default defineMap('arena', {
|
|
5
5
|
legend: { '#': 'ground', '=': 'plank', '%': 'bedrock', S: 'spawn' },
|
|
6
6
|
needsBelow: { S: ['ground', 'plank', 'bedrock'] },
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/** Dano
|
|
1
|
+
/** Dano e morte, usados pela bala, pelo rifle e pela faca (rodam igual no servidor e na predição do cliente). */
|
|
2
2
|
import type { EntityRef, EventDef, World } from '@vibe-engine/core';
|
|
3
|
-
import { RigidBody2D, Sprite, Transform2D
|
|
3
|
+
import { RigidBody2D, Sprite, Transform2D } from '@vibe-engine/2d';
|
|
4
4
|
import { Fighter } from '../components/fighter.component.ts';
|
|
5
|
-
import { Arena
|
|
6
|
-
import { FighterHit, FighterKilled
|
|
5
|
+
import { Arena } from '../components/gun.component.ts';
|
|
6
|
+
import { FighterHit, FighterKilled } from '../events/combat.events.ts';
|
|
7
7
|
|
|
8
8
|
type Emit = <P>(event: EventDef<P>, payload: P) => void;
|
|
9
9
|
|
|
@@ -39,18 +39,3 @@ export function kill(world: World, e: EntityRef, by: string, emit: Emit) {
|
|
|
39
39
|
e.write(Sprite).alpha = 0;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* O foguete explode onde está: abre um buraco no cenário (a rocha fica) e fere quem estiver no raio.
|
|
44
|
-
* `overlap` sem `by`: ninguém mira uma explosão, então não há lag compensation. Os tiles saem antes,
|
|
45
|
-
* então a parede que a explosão derrubou não protege ninguém.
|
|
46
|
-
*/
|
|
47
|
-
export function explode(world: World, rocket: EntityRef, emit: Emit): void {
|
|
48
|
-
const r = rocket.read(Rocket);
|
|
49
|
-
const at = rocket.read(Transform2D);
|
|
50
|
-
const tiles = destroyTiles(world.entity('arena-map'), { x: at.x, y: at.y, radius: r.radius }, emit);
|
|
51
|
-
const hits = overlap(world, { at, radius: r.radius, filter: (e) => e.has(Fighter) && e.read(Fighter).respawn === 0 });
|
|
52
|
-
let landed = 0;
|
|
53
|
-
for (const h of hits) if (hurt(world, world.entity(h.entity), r.owner, r.damage, world.entity(h.entity).read(Transform2D).x - at.x, emit)) landed++;
|
|
54
|
-
emit(RocketExploded, { rocket: rocket.id, owner: r.owner, x: at.x, y: at.y, radius: r.radius, tiles: tiles.length, hits: landed });
|
|
55
|
-
world.despawn(rocket.id);
|
|
56
|
-
}
|
|
@@ -2,14 +2,14 @@ import { defineScene } from '@vibe-engine/core';
|
|
|
2
2
|
import map from '../maps/arena.map.ts';
|
|
3
3
|
import { buildArena } from '../level/build.ts';
|
|
4
4
|
import { FighterController } from '../systems/fighter-controller.system.ts';
|
|
5
|
-
import { BulletLifetime, GunControl,
|
|
5
|
+
import { BulletLifetime, GunControl, TracerFade } from '../systems/gun.system.ts';
|
|
6
6
|
import { Combat, MatchRules, Respawn } from '../systems/combat.system.ts';
|
|
7
7
|
import { ConnectionStatus, LocalView } from '../systems/view.system.ts';
|
|
8
8
|
import { Players } from '../listeners/players.listener.ts';
|
|
9
9
|
import { Effects } from '../listeners/effects.listener.ts';
|
|
10
10
|
|
|
11
11
|
export default defineScene({
|
|
12
|
-
systems: [FighterController, GunControl, BulletLifetime,
|
|
12
|
+
systems: [FighterController, GunControl, BulletLifetime, TracerFade, Combat, Respawn, MatchRules, LocalView],
|
|
13
13
|
listeners: [Players, Effects, ConnectionStatus],
|
|
14
14
|
setup: (ctx) => buildArena(ctx, map),
|
|
15
15
|
});
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { defineSystem } from '@vibe-engine/core';
|
|
2
2
|
import { RigidBody2D, Sprite, Tilemap, Transform2D, TriggerEnter, pairWith } from '@vibe-engine/2d';
|
|
3
3
|
import { Fighter } from '../components/fighter.component.ts';
|
|
4
|
-
import { Arena, Bullet
|
|
4
|
+
import { Arena, Bullet } from '../components/gun.component.ts';
|
|
5
5
|
import { BulletImpact, FighterRespawned, MatchOver } from '../events/combat.events.ts';
|
|
6
|
-
import {
|
|
6
|
+
import { hurt, kill } from '../rules/damage.ts';
|
|
7
7
|
|
|
8
8
|
const SPAWN_SHIELD = 90;
|
|
9
9
|
|
|
10
|
-
/** Bala × lutador (dano, knockback, morte, placar), bala × cenário
|
|
10
|
+
/** Bala × lutador (dano, knockback, morte, placar), bala × cenário. Autoritativo no servidor; o cliente prevê e é corrigido. */
|
|
11
11
|
export const Combat = defineSystem('combat.hits', {
|
|
12
12
|
stage: 'postPhysics',
|
|
13
13
|
reads: [TriggerEnter],
|
|
14
14
|
update({ world, events, emit }) {
|
|
15
|
-
const exploded = new Set<string>(); // despawn só vale no fim do stage: um foguete que toca duas coisas no mesmo tick explode uma vez
|
|
16
15
|
for (const hit of events.read(TriggerEnter)) {
|
|
17
|
-
const blast = pairWith(world, hit, Rocket);
|
|
18
|
-
if (blast) {
|
|
19
|
-
const [rocket, target] = blast;
|
|
20
|
-
if (exploded.has(rocket.id)) continue;
|
|
21
|
-
const f = target.has(Fighter) ? target.read(Fighter) : null;
|
|
22
|
-
// Explode no cenário ou num lutador vivo que não seja quem atirou (a saída do cano não conta).
|
|
23
|
-
if (target.has(Tilemap) || (f && f.owner !== rocket.read(Rocket).owner && f.respawn === 0)) { exploded.add(rocket.id); explode(world, rocket, emit); }
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
16
|
const shot = pairWith(world, hit, Bullet);
|
|
27
17
|
if (!shot) continue;
|
|
28
18
|
const [bullet, target] = shot;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { defineSystem, type EntityRef } from '@vibe-engine/core';
|
|
2
2
|
import { Collider2D, Grounded, RigidBody2D, Sprite, Transform2D, overlap, raycast } from '@vibe-engine/2d';
|
|
3
|
+
import { NetOwner } from '@vibe-engine/net';
|
|
3
4
|
import { Fighter } from '../components/fighter.component.ts';
|
|
4
|
-
import { Arena, Bullet, Gun,
|
|
5
|
-
import { KnifeSwung, RifleFired,
|
|
6
|
-
import {
|
|
5
|
+
import { Arena, Bullet, Gun, Tracer } from '../components/gun.component.ts';
|
|
6
|
+
import { KnifeSwung, RifleFired, ShotFired, WeaponSwapped } from '../events/combat.events.ts';
|
|
7
|
+
import { hurt } from '../rules/damage.ts';
|
|
7
8
|
|
|
8
|
-
const NEXT_WEAPON = { pistol: 'rifle', rifle: '
|
|
9
|
+
const NEXT_WEAPON = { pistol: 'rifle', rifle: 'pistol' } as const;
|
|
9
10
|
const KNIFE = { radius: 20, angle: 1.1, damage: 2, cooldown: 24 };
|
|
10
11
|
/** Só lutadores vivos são alvo (morto fica escondido fora do mapa). */
|
|
11
12
|
const alive = (e: EntityRef) => e.has(Fighter) && e.read(Fighter).respawn === 0;
|
|
@@ -46,8 +47,8 @@ export const GunControl = defineSystem('gun.control', {
|
|
|
46
47
|
t.x = p.x + dir.x * (4 - gun.kick);
|
|
47
48
|
t.y = p.y + 5 + dir.y * (4 - gun.kick);
|
|
48
49
|
t.rotation = Math.atan2(dir.y, dir.x);
|
|
49
|
-
t.scaleX = gun.weapon === 'rifle' ? 1.6 :
|
|
50
|
-
t.scaleY =
|
|
50
|
+
t.scaleX = gun.weapon === 'rifle' ? 1.6 : 1; // shortcut: o rifle é a pistola esticada até ter arte própria
|
|
51
|
+
t.scaleY = dir.x < 0 ? -1 : 1;
|
|
51
52
|
if (gun.cooldown > 0) gun.cooldown--;
|
|
52
53
|
if (gun.knifeCooldown > 0) gun.knifeCooldown--;
|
|
53
54
|
if (f.respawn > 0 || !playing) continue;
|
|
@@ -81,27 +82,12 @@ export const GunControl = defineSystem('gun.control', {
|
|
|
81
82
|
Transform2D({ x: muzzle.x, y: muzzle.y, rotation: t.rotation }),
|
|
82
83
|
Sprite({ width: length, height: 1, color: '#fff6c8', anchor: { x: 0, y: 0.5 }, layer: 5 }),
|
|
83
84
|
Tracer(),
|
|
85
|
+
NetOwner({ player: gun.owner }),
|
|
84
86
|
]);
|
|
85
87
|
emit(RifleFired, { gun: g.id, from: muzzle, to, hit: hit?.entity ?? '' });
|
|
86
88
|
continue;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
if (gun.weapon === 'bazooka') {
|
|
90
|
-
gun.cooldown = gun.bazookaRate;
|
|
91
|
-
gun.kick = 6;
|
|
92
|
-
body.velocity.x -= dir.x * gun.recoil * 2.5;
|
|
93
|
-
const id = `rocket-${gun.owner}-${gun.shots}`;
|
|
94
|
-
world.spawn(id, [
|
|
95
|
-
Transform2D({ ...muzzle, rotation: t.rotation }),
|
|
96
|
-
Sprite({ width: 8, height: 4, color: '#2a2a2a', layer: 4 }), // shortcut: retângulo até ter arte própria
|
|
97
|
-
RigidBody2D({ type: 'kinematic', velocity: { x: dir.x * gun.rocketSpeed, y: dir.y * gun.rocketSpeed } }),
|
|
98
|
-
Collider2D.circle({ radius: 3, trigger: true }),
|
|
99
|
-
Rocket({ owner: gun.owner }),
|
|
100
|
-
]);
|
|
101
|
-
emit(RocketFired, { gun: g.id, rocket: id, dir: { x: dir.x, y: dir.y } });
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
91
|
gun.cooldown = gun.rate;
|
|
106
92
|
gun.kick = 3;
|
|
107
93
|
body.velocity.x -= dir.x * gun.recoil;
|
|
@@ -113,6 +99,7 @@ export const GunControl = defineSystem('gun.control', {
|
|
|
113
99
|
RigidBody2D({ type: 'kinematic', velocity: { x: dir.x * gun.bulletSpeed, y: dir.y * gun.bulletSpeed } }),
|
|
114
100
|
Collider2D.circle({ radius: 2, trigger: true }),
|
|
115
101
|
Bullet({ owner: gun.owner }),
|
|
102
|
+
NetOwner({ player: gun.owner }), // a bala dos outros sai do cano que você vê (no passado)
|
|
116
103
|
]);
|
|
117
104
|
emit(ShotFired, { gun: g.id, bullet: id, dir: { x: dir.x, y: dir.y } });
|
|
118
105
|
}
|
|
@@ -126,14 +113,6 @@ export const BulletLifetime = defineSystem('gun.bullet-lifetime', {
|
|
|
126
113
|
},
|
|
127
114
|
});
|
|
128
115
|
|
|
129
|
-
/** Foguete que não acertou nada explode no fim do alcance. */
|
|
130
|
-
export const RocketLifetime = defineSystem('gun.rocket-lifetime', {
|
|
131
|
-
query: [Rocket],
|
|
132
|
-
update({ entities, world, emit }) {
|
|
133
|
-
for (const e of entities) if (--e.write(Rocket).ttl <= 0) explode(world, e, emit);
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
116
|
/** O traço do rifle esmaece e some. */
|
|
138
117
|
export const TracerFade = defineSystem('gun.tracer-fade', {
|
|
139
118
|
query: [Tracer, Sprite],
|
|
@@ -5,7 +5,7 @@ import { Fighter } from '../components/fighter.component.ts';
|
|
|
5
5
|
import { Arena, Connection, Gun } from '../components/gun.component.ts';
|
|
6
6
|
|
|
7
7
|
/** Câmera e HUD são de cada cliente (`net: 'local'`): seguem e mostram o lutador de `localPlayer`. */
|
|
8
|
-
const WEAPON_NAMES: Record<string, string> = { pistol: 'pistola', rifle: 'rifle'
|
|
8
|
+
const WEAPON_NAMES: Record<string, string> = { pistol: 'pistola', rifle: 'rifle' };
|
|
9
9
|
|
|
10
10
|
export const LocalView = defineSystem('view.local', {
|
|
11
11
|
stage: 'update',
|
|
@@ -4,7 +4,7 @@ import assert from 'node:assert/strict';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { createWorld, loadProject, openScene } from '@vibe-engine/cli';
|
|
6
6
|
import { UiButton, UiInput, UiText, memorySaveStore, type World } from '@vibe-engine/core';
|
|
7
|
-
import { Label2D,
|
|
7
|
+
import { Label2D, Transform2D, RigidBody2D } from '@vibe-engine/2d';
|
|
8
8
|
import { NetJoinRoom, NetJoined, NetPlayerJoined, createRoomClient, createRoomHub, createClock, createLoopback, createNetClient, createNetServer, type NetClient } from '@vibe-engine/net';
|
|
9
9
|
import { Fighter } from '../src/components/fighter.component.ts';
|
|
10
10
|
import { Arena, Gun, Tracer } from '../src/components/gun.component.ts';
|
|
@@ -171,43 +171,6 @@ test('bandwidth: after the first snapshot only changes travel (field-level delta
|
|
|
171
171
|
function totalBytes() { return m.links.reduce((n, l) => n + l.stats.bytes, 0); }
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
test('bazooka: the server rocket blows a hole in the ground (bedrock stays), p2 falls in, every client sees the hole, a direct hit takes 3 hp', async () => {
|
|
175
|
-
const m = await match();
|
|
176
|
-
m.run(120); // escudo de nascimento acaba
|
|
177
|
-
const place = (p: string, x: number, y: number) => { const t = m.sw.entity(`fighter-${p}`).write(Transform2D); t.x = x; t.y = y; m.sw.entity(`fighter-${p}`).write(RigidBody2D).velocity = { x: 0, y: 0 }; };
|
|
178
|
-
place('p1', 200, 15 * 18 - 12); // no fundo de rocha, à esquerda do bloco das colunas 14–17
|
|
179
|
-
place('p2', 259, 13 * 18 - 12); // em cima do bloco, na coluna 14 (x 252–270)
|
|
180
|
-
m.run(30);
|
|
181
|
-
m.a.client.input.press('swap');
|
|
182
|
-
m.run(10);
|
|
183
|
-
m.a.client.input.press('swap');
|
|
184
|
-
m.run(20);
|
|
185
|
-
assert.equal(m.sw.entity('gun-p1').read(Gun).weapon, 'bazooka', 'Q cycles pistol → rifle → bazooka');
|
|
186
|
-
const tile = (w: World, layer: string, x: number, y: number) => { const tm = w.entity('arena-map').read(Tilemap); return tm.layers.find((l) => l.name === layer)!.tiles[y * tm.width + x]!; };
|
|
187
|
-
assert.ok(tile(m.sw, 'ground', 14, 13) >= 0);
|
|
188
|
-
m.a.client.input.set('aim', [1, 0]);
|
|
189
|
-
m.sw.entity('fighter-p2').write(Fighter).invulnerable = 60; // sem knockback: o teste quer ver p2 cair no buraco
|
|
190
|
-
m.a.client.input.press('fire'); // o foguete passa por baixo de p2 e bate no lado do bloco
|
|
191
|
-
m.run(40);
|
|
192
|
-
assert.equal(tile(m.sw, 'ground', 14, 13), -1, 'hole in the block');
|
|
193
|
-
assert.equal(tile(m.sw, 'ground', 14, 14), -1);
|
|
194
|
-
assert.ok(tile(m.sw, 'ground', 17, 13) >= 0, 'outside the radius stays');
|
|
195
|
-
assert.equal(tile(m.sw, 'bedrock', 14, 15), 29, 'bedrock is indestructible');
|
|
196
|
-
assert.ok(m.sw.entity('fighter-p2').read(Transform2D).y > 15 * 18 - 20, `p2 fell into the hole (y ${m.sw.entity('fighter-p2').read(Transform2D).y})`);
|
|
197
|
-
m.run(30);
|
|
198
|
-
const serverMap = JSON.stringify(m.sw.entity('arena-map').read(Tilemap));
|
|
199
|
-
assert.equal(JSON.stringify(m.b.world.entity('arena-map').read(Tilemap)), serverMap, 'p2 sees the same hole');
|
|
200
|
-
assert.equal(JSON.stringify(m.a.world.entity('arena-map').read(Tilemap)), serverMap, 'the shooter (predicted, then reconciled) too');
|
|
201
|
-
|
|
202
|
-
// Agora no mesmo nível: tiro direto.
|
|
203
|
-
place('p2', 262, 15 * 18 - 12);
|
|
204
|
-
m.run(80); // recarga da bazuca
|
|
205
|
-
const before = fighter(m.sw, 'p2').hp;
|
|
206
|
-
m.a.client.input.press('fire');
|
|
207
|
-
m.run(30);
|
|
208
|
-
assert.equal(fighter(m.sw, 'p2').hp, before - 3, `the blast took 3 hp (hp ${fighter(m.sw, 'p2').hp})`);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
174
|
test('player names: typed in the lobby (saved for the next visit), sent as profile, shown above each fighter and on both scoreboards', async () => {
|
|
212
175
|
const project = await loadProject(root);
|
|
213
176
|
const clock = createClock();
|
|
@@ -256,3 +219,28 @@ test('player names: no name typed means the fighter is called by its color', asy
|
|
|
256
219
|
assert.equal(fighter(w, 'p2').name, 'blue');
|
|
257
220
|
assert.equal(w.entity('fighter-p2').read(Label2D).text, 'blue');
|
|
258
221
|
});
|
|
222
|
+
|
|
223
|
+
test('interpolation: the other player slides smoothly on my screen (no correction jumps) even zigzagging over a jittery link', async () => {
|
|
224
|
+
const clock = createClock();
|
|
225
|
+
const sw = await openScene(root, { scene: 'arena' });
|
|
226
|
+
const server = createNetServer(sw);
|
|
227
|
+
const cs: Array<{ world: World; client: NetClient }> = [];
|
|
228
|
+
for (const seed of [1, 2]) {
|
|
229
|
+
const net = createLoopback(clock, { latencyMs: 50, jitterMs: 20, seed });
|
|
230
|
+
server.connect(net.server);
|
|
231
|
+
const world = await openScene(root, { scene: 'arena' });
|
|
232
|
+
cs.push({ world, client: createNetClient(world, net.client) });
|
|
233
|
+
}
|
|
234
|
+
const tick = () => { clock.advance(1000 / 60); server.tick(); for (const c of cs) c.client.tick(); };
|
|
235
|
+
for (let i = 0; i < 150; i++) tick();
|
|
236
|
+
const [me, other] = cs as [typeof cs[0], typeof cs[0]];
|
|
237
|
+
const shown: number[] = [];
|
|
238
|
+
for (let i = 0; i < 400; i++) {
|
|
239
|
+
if (i % 23 === 0) other.client.input.set('move', Math.floor(i / 23) % 2 ? -1 : 1);
|
|
240
|
+
tick();
|
|
241
|
+
shown.push(me.world.entity('fighter-p2').read(Transform2D).x + (me.world.visualOffsets.get('fighter-p2')?.x ?? 0));
|
|
242
|
+
}
|
|
243
|
+
const worst = Math.max(...shown.slice(1).map((v, i) => Math.abs(v - shown[i]!)));
|
|
244
|
+
assert.ok(worst < 2.6, `biggest on-screen step of the other fighter ${worst.toFixed(2)} px/tick (walk speed ≈ 2.2; extrapolation gave ~6.5)`);
|
|
245
|
+
assert.equal(me.client.stats.corrections, 0, 'remote fighters are drawn from server positions, never corrected');
|
|
246
|
+
});
|