@vibe-engine/cli 0.1.0 → 0.1.1

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/create.js CHANGED
@@ -45,6 +45,9 @@ export const create = defineCommand({
45
45
  }
46
46
  }
47
47
  writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
48
+ // O pnpm 10+ segura pacotes recém-publicados (minimumReleaseAge): sem isto, um jogo criado logo depois de uma versão nova da engine não instala.
49
+ if (PUBLISHED)
50
+ writeFileSync(join(dir, 'pnpm-workspace.yaml'), '# Versões novas da engine (@vibe-engine/*) entram na hora; o resto segue a política do pnpm.\nminimumReleaseAgeExclude:\n - "@vibe-engine/*"\n');
48
51
  const configPath = join(dir, 'vibe.config.ts');
49
52
  writeFileSync(configPath, readFileSync(configPath, 'utf8').replace(/name: '[^']*'/, `name: '${name}'`));
50
53
  return { dir: relative(io.cwd, dir) || '.', template, files, next: [`cd ${relative(io.cwd, dir)}`, 'pnpm install', 'pnpm dev'] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-engine/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "vibe CLI: create, dev, run --headless, test, check, build and serve vibe-engine games",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -35,12 +35,12 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@vibe-engine/core": "0.1.0",
38
+ "@vibe-engine/core": "0.1.1",
39
39
  "vite": "8.4.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@vibe-engine/2d": "0.1.0",
43
- "@vibe-engine/net": "0.1.0"
42
+ "@vibe-engine/2d": "0.1.1",
43
+ "@vibe-engine/net": "0.1.1"
44
44
  },
45
45
  "files": [
46
46
  "dist",
@@ -96,7 +96,7 @@ test('3D: same seed and inputs give the same hash (deterministic Rapier 3D)', as
96
96
  });
97
97
 
98
98
  test('vibe run --headless --json on the 3D template', () => {
99
- const bin = fileURLToPath(import.meta.resolve('@vibe-engine/cli').replace(/index\.ts$/, 'bin.ts'));
99
+ const bin = fileURLToPath(import.meta.resolve('@vibe-engine/cli').replace(/index\.(ts|js)$/, 'bin.$1')); // src no checkout da engine, dist instalado do npm
100
100
  const out = JSON.parse(execFileSync(process.execPath, [bin, 'run', '--headless', '--frames', '60', '--entities', 'player', '--json'], { cwd: root, encoding: 'utf8' }));
101
101
  assert.equal(out.scene, 'arena');
102
102
  assert.ok('Grounded3D' in out.entities.player && 'Transform3D' in out.entities.player);
@@ -485,7 +485,7 @@ test('same seed and inputs give equal snapshots (replay of a recording)', async
485
485
  });
486
486
 
487
487
  test('vibe run --headless --json works on the template', () => {
488
- const bin = fileURLToPath(import.meta.resolve('@vibe-engine/cli').replace(/index\.ts$/, 'bin.ts'));
488
+ const bin = fileURLToPath(import.meta.resolve('@vibe-engine/cli').replace(/index\.(ts|js)$/, 'bin.$1')); // src no checkout da engine, dist instalado do npm
489
489
  const out = JSON.parse(execFileSync(process.execPath, [bin, 'run', '--headless', '--scene', 'level-1', '--frames', '60', '--entities', 'player', '--json'], { cwd: root, encoding: 'utf8' }));
490
490
  assert.equal(out.scene, 'level-1');
491
491
  assert.ok('Grounded' in out.entities.player && 'Transform2D' in out.entities.player);
@@ -156,15 +156,15 @@ The full reference ships **with the installed engine version**, in `node_modules
156
156
  <!-- vibe-engine:end -->
157
157
  ## This project
158
158
 
159
- Online PvP in arenas of up to 6 players (three are always open in the lobby; more can be created there): players run, jump and shoot where the mouse points. Q cycles pistol (bullets) → rifle (instant shot, 2 damage, slower) → bazooka (a rocket that explodes on walls and fighters: it blows a hole in the ground and takes 3 hp in a 30 px radius), and K or the right mouse button swings a knife (short arc, 2 damage). A bullet takes 1 of 5 hp; every hit knocks back; at 0 the player dies, the shooter scores a kill, and the dead player respawns after 2 s with a short shield. Falling off the map also kills (credit to the last hitter).
159
+ Online PvP in arenas of up to 6 players (three are always open in the lobby; more can be created there): players run, jump and shoot where the mouse points. Q swaps pistol (bullets) ↔ rifle (instant shot, 2 damage, slower), and K or the right mouse button swings a knife (short arc, 2 damage). A bullet takes 1 of 5 hp; every hit knocks back; at 0 the player dies, the shooter scores a kill, and the dead player respawns after 2 s with a short shield. Falling off the map also kills (credit to the last hitter).
160
160
 
161
161
  **How multiplayer works here.** The server is authoritative: it runs this same game headless (`vibe serve`; `vibe dev` starts it next to the browser preview and restarts it when code changes). Each browser tab is a client: it sends only input, predicts its own moves on the same tick, and reconciles with the server snapshot (restore + re-simulate). So:
162
162
 
163
163
  - Game rules are **shared** code and run on both sides. Read input with `inputOf(owner)`, never `input`: every fighter belongs to a player id (`p1`, `p2`...).
164
164
  - Players appear through the `NetPlayerJoined` event (`src/listeners/players.listener.ts`), which spawns `fighter-<player>` and `gun-<player>`; `NetPlayerLeft` removes them. The event carries the player's `profile` (the name typed in the lobby, already cleaned by the server): it becomes `Fighter.name` (no name: the color) and a `Label2D` above the fighter (the local player's own label is drawn with swapped colors).
165
165
  - Camera and UI are local to each client (`net: 'local'` components are not replicated). `view.local` points the camera at `fighter-<localPlayer>` and writes the small top-right HUD (`hud/hp`: health + weapon, `hud/board`: kill limit and scoreboard). Controls are listed in the lobby. `localPlayer` is in the system context.
166
- - Ids created during play must be the same on client and server: bullets are `bullet-<player>-<n>`, rockets `rocket-<player>-<n>` and rifle tracers `tracer-<player>-<n>`, from a counter in `Gun`.
167
- - Rifle and knife use `raycast`/`overlap` with `by: gun.owner`: the server accepts what that player saw (lag compensation), so a hit on a target that just turned around still counts, within limits. Bullets and rockets are simulated on the server and need nothing extra; the explosion uses `overlap` without `by` (nobody aims it).
166
+ - Ids created during play must be the same on client and server: bullets are `bullet-<player>-<n>` and rifle tracers `tracer-<player>-<n>`, from a counter in `Gun`.
167
+ - Rifle and knife use `raycast`/`overlap` with `by: gun.owner`: the server accepts what that player saw (lag compensation), so a hit on a target that just turned around still counts, within limits. Bullets are simulated on the server and need nothing extra.
168
168
  - Health, kills and deaths are decided by the server; a client that edits them locally is overwritten by the next snapshot.
169
169
 
170
170
  Files:
@@ -173,9 +173,9 @@ Files:
173
173
  - `src/scenes/lobby.scene.ts` + `src/systems/lobby.system.ts` + `src/ui/lobby.ui.ts`: the lobby is game code. A name field (`lobby/name`, a `UiInput`) is prefilled from `src/saves/player.save.ts` and saved on every change; Enter joins quickly; every join sends `profile: { name }`. It asks with events (`emit(NetListRooms, {})` every 2 s, `emit(NetJoinRoom, { room } | { type } | { create: { type, name, rules } }, with profile)`) and gets answers as events (`NetRoomsListed`, `NetJoined`, `NetFailed` with the reason, such as a full room or invalid rules). Buttons are `lobby/rooms/<room-id>`; update existing entities instead of despawning and spawning the same id in one step.
174
174
  - Connection: a dropped player keeps their seat for 10 s and comes back as the same player (`NetPlayerAway` / `NetPlayerBack` on the server, `NetConnection` on the client, shown in the HUD from the local `connection` entity). Esc (`leave`, a `local` action) emits `NetLeaveRoom`: the seat is freed and the client goes back to the lobby. The session is kept in the tab, so a reload returns to the same room.
175
175
  - `match.rules`: reaching `killLimit` sets `Arena.status = 'over'` with the winner, and a new match starts 4 s later.
176
- - `src/maps/arena.map.ts`: the arena as text; `S` cells are spawn points (player `pN` uses the (N-1)th); `%` is bedrock, a layer marked `indestructible` in `src/level/build.ts`, so explosions never open the border or the floor. `src/level/build.ts` builds the `Tilemap`, camera and HUD.
177
- - `src/systems/`: `fighter.controller` (platformer movement with game feel, squash & stretch), `gun.control` (aim, weapon swap, fire rate, recoil, bullets, rockets, rifle raycast, knife arc), `gun.tracer-fade`, `gun.bullet-lifetime`, `gun.rocket-lifetime` (a rocket explodes at the end of its range), `combat.hits` (bullet × fighter, bullet × walls, rocket × either; damage, knockback, death, score and `explode` live in `src/rules/damage.ts`, shared by bullet, rifle, knife and bazooka; `explode` calls `destroyTiles` and the destroyed cells reach the clients in the snapshot), `fighter.respawn` (falling off, respawn, shield blink), `view.local` (camera, HUD, scoreboard and win banner with player names).
178
- - `src/listeners/effects.listener.ts`: sound, particles, camera shake and hit-stop for jumps, shots, rockets, explosions (dirt from each destroyed tile via `TilesDestroyed`), hits, deaths and respawns (shake only when the local player is involved). Sounds are positioned (`at:`), so an enemy shot off to the left is heard on the left.
176
+ - `src/maps/arena.map.ts`: the arena as text; `S` cells are spawn points (player `pN` uses the (N-1)th); `%` is the rock border and floor (its own tile layer). `src/level/build.ts` builds the `Tilemap`, camera and HUD.
177
+ - `src/systems/`: `fighter.controller` (platformer movement with game feel, squash & stretch), `gun.control` (aim, weapon swap, fire rate, recoil, bullets, rifle raycast, knife arc), `gun.tracer-fade`, `gun.bullet-lifetime`, `combat.hits` (bullet × fighter, bullet × walls; damage, knockback, death and score live in `src/rules/damage.ts`, shared by bullet, rifle and knife), `fighter.respawn` (falling off, respawn, shield blink), `view.local` (camera, HUD, scoreboard and win banner with player names).
178
+ - `src/listeners/effects.listener.ts`: sound, particles, camera shake and hit-stop for jumps, shots, knife swings, hits, deaths and respawns (shake only when the local player is involved). Sounds are positioned (`at:`), so an enemy shot off to the left is heard on the left.
179
179
  - `assets/`: Kenney Pixel Platformer sheets (CC0) with one animation set per color (`green-walk`, `blue-idle`...); sounds generated by code (CC0).
180
- - `tests/pvp.test.ts`: 1 server + 2 clients over an emulated network (100 ms RTT), headless: join and spawn, shooting until a kill, score, respawn, authority, rifle and knife hits, bazooka (hole in the ground, bedrock kept, the target falls in, both clients see the hole, blast damage), player names (typed in the lobby, saved, sent as profile, on the fighters and both scoreboards; no name falls back to the color). Run `pnpm test` after every change.
180
+ - `tests/pvp.test.ts`: 1 server + 2 clients over an emulated network (100 ms RTT), headless: join and spawn, shooting until a kill, score, respawn, authority, rifle and knife hits, player names (typed in the lobby, saved, sent as profile, on the fighters and both scoreboards; no name falls back to the color). Run `pnpm test` after every change.
181
181
  - Play: `pnpm dev`, open the URL in two tabs (or two machines with `vibe serve --host 0.0.0.0` and `net.url`).
@@ -1,6 +1,6 @@
1
1
  # shooter-2d-pvp
2
2
 
3
- Template multiplayer da vibe-engine: arena 2D de plataforma com tiro, até 4 jogadores por sala, com lobby e salas com regras próprias (abates para vencer, tempo de respawn, gravidade). O servidor é autoritativo, o cliente prediz e reconcilia, e o game feel vem do platformer (coyote time, jump buffer, recoil, knockback, shake, hit-stop, partículas e sons).
3
+ Template multiplayer da vibe-engine: arena 2D de plataforma com tiro, até 6 jogadores por sala, com lobby e salas com regras próprias (abates para vencer, tempo de respawn, gravidade). O servidor é autoritativo, o cliente prediz e reconcilia, e o game feel vem do platformer (coyote time, jump buffer, recoil, knockback, shake, hit-stop, partículas e sons).
4
4
 
5
5
  ```sh
6
6
  pnpm dev # vibe dev: browser + servidor do jogo; abra em duas abas para jogar contra você mesmo
@@ -3,18 +3,15 @@ import { defineComponent, t } from '@vibe-engine/core';
3
3
  /**
4
4
  * A arma de um lutador (`gun-<player>`). Segurar o tiro dispara a cada `rate` ticks.
5
5
  * `pistol` atira balas (simuladas no servidor); `rifle` é tiro instantâneo (raycast com
6
- * lag compensation: vale o que o atirador viu); `bazooka` atira foguetes (simulados no servidor)
7
- * que explodem no cenário: abrem buraco no chão (`destroyTiles`) e ferem em área. A faca é de todo lutador (`knifeCooldown`).
6
+ * lag compensation: vale o que o atirador viu). A faca é de todo lutador (`knifeCooldown`).
8
7
  */
9
8
  export const Gun = defineComponent('Gun', {
10
9
  owner: t.string({ doc: 'id do jogador' }),
11
- weapon: t.enum(['pistol', 'rifle', 'bazooka'] as const, { default: 'pistol' }),
10
+ weapon: t.enum(['pistol', 'rifle'] as const, { default: 'pistol' }),
12
11
  rate: t.int({ default: 12, min: 1, doc: 'pistola' }),
13
12
  rifleRate: t.int({ default: 45, min: 1 }),
14
13
  rifleRange: t.number({ default: 420, unit: 'px' }),
15
14
  rifleDamage: t.int({ default: 2, min: 1 }),
16
- bazookaRate: t.int({ default: 70, min: 1 }),
17
- rocketSpeed: t.number({ default: 240, unit: 'px/s' }),
18
15
  knifeCooldown: t.int({ min: 0 }),
19
16
  cooldown: t.int({ min: 0 }),
20
17
  bulletSpeed: t.number({ default: 340, unit: 'px/s' }),
@@ -33,14 +30,6 @@ export const Bullet = defineComponent('Bullet', {
33
30
  damage: t.int({ default: 1, min: 1 }),
34
31
  });
35
32
 
36
- /** Foguete da bazuca (`rocket-<player>-<n>`): explode ao tocar cenário ou lutador, ou quando `ttl` acaba. */
37
- export const Rocket = defineComponent('Rocket', {
38
- owner: t.string(),
39
- ttl: t.int({ default: 90, min: 0 }),
40
- radius: t.number({ default: 30, unit: 'px', doc: 'raio da explosão (tiles e dano)' }),
41
- damage: t.int({ default: 3, min: 1 }),
42
- });
43
-
44
33
  /** A partida (entidade `arena`): tamanho, regras da sala e estado. */
45
34
  export const Arena = defineComponent('Arena', {
46
35
  width: t.number({ unit: 'px' }),
@@ -11,5 +11,3 @@ export const RifleFired = defineEvent<{ gun: string; from: { x: number; y: numbe
11
11
  export const KnifeSwung = defineEvent<{ fighter: string; x: number; y: number; dir: { x: number; y: number }; hits: number }>('knife.swung');
12
12
  export const WeaponSwapped = defineEvent<{ gun: string; weapon: string }>('gun.swapped');
13
13
  export const BulletImpact = defineEvent<{ x: number; y: number }>('bullet.impact');
14
- export const RocketFired = defineEvent<{ gun: string; rocket: string; dir: { x: number; y: number } }>('gun.rocket-fired');
15
- export const RocketExploded = defineEvent<{ rocket: string; owner: string; x: number; y: number; radius: number; tiles: number; hits: number }>('rocket.exploded');
@@ -32,8 +32,8 @@ export function buildArena({ spawn, params }: SceneSetupContext, map: GridMap):
32
32
  }),
33
33
  },
34
34
  planks: { match: 'plank', collides: true, tiles: edges({ single: 47, left: 48, mid: 49, right: 50 }) },
35
- // Borda e fundo: `destroyTiles` (bazuca) não remove esta camada.
36
- bedrock: { match: 'bedrock', collides: true, indestructible: true, tiles: 29 },
35
+ // Borda e fundo.
36
+ bedrock: { match: 'bedrock', collides: true, tiles: 29 },
37
37
  },
38
38
  }))]);
39
39
  const size = { width: map.width * TILE, height: map.height * TILE };
@@ -1,7 +1,6 @@
1
1
  import { defineListener, type World } from '@vibe-engine/core';
2
- import { CameraShake, ParticleBurst, TilesDestroyed, Transform2D } from '@vibe-engine/2d';
3
- import { TILE } from '../level/build.ts';
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 { defineMap } from '@vibe-engine/core';
2
2
 
3
- /** A arena. `S` = ponto de nascimento (um por jogador, em ordem de entrada); `%` = rocha (a bazuca não destrói). `vibe map show arena`. */
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, morte e explosão, usados pela bala, pelo rifle, pela faca e pela bazuca (rodam igual no servidor e na predição do cliente). */
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, destroyTiles, overlap } from '@vibe-engine/2d';
3
+ import { RigidBody2D, Sprite, Transform2D } from '@vibe-engine/2d';
4
4
  import { Fighter } from '../components/fighter.component.ts';
5
- import { Arena, Rocket } from '../components/gun.component.ts';
6
- import { FighterHit, FighterKilled, RocketExploded } from '../events/combat.events.ts';
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, RocketLifetime, TracerFade } from '../systems/gun.system.ts';
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, RocketLifetime, TracerFade, Combat, Respawn, MatchRules, LocalView],
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, Rocket } from '../components/gun.component.ts';
4
+ import { Arena, Bullet } from '../components/gun.component.ts';
5
5
  import { BulletImpact, FighterRespawned, MatchOver } from '../events/combat.events.ts';
6
- import { explode, hurt, kill } from '../rules/damage.ts';
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 e foguete × qualquer um dos dois (explosão). Autoritativo no servidor; o cliente prevê e é corrigido. */
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,11 @@
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
3
  import { Fighter } from '../components/fighter.component.ts';
4
- import { Arena, Bullet, Gun, Rocket, Tracer } from '../components/gun.component.ts';
5
- import { KnifeSwung, RifleFired, RocketFired, ShotFired, WeaponSwapped } from '../events/combat.events.ts';
6
- import { explode, hurt } from '../rules/damage.ts';
4
+ import { Arena, Bullet, Gun, Tracer } from '../components/gun.component.ts';
5
+ import { KnifeSwung, RifleFired, ShotFired, WeaponSwapped } from '../events/combat.events.ts';
6
+ import { hurt } from '../rules/damage.ts';
7
7
 
8
- const NEXT_WEAPON = { pistol: 'rifle', rifle: 'bazooka', bazooka: 'pistol' } as const;
8
+ const NEXT_WEAPON = { pistol: 'rifle', rifle: 'pistol' } as const;
9
9
  const KNIFE = { radius: 20, angle: 1.1, damage: 2, cooldown: 24 };
10
10
  /** Só lutadores vivos são alvo (morto fica escondido fora do mapa). */
11
11
  const alive = (e: EntityRef) => e.has(Fighter) && e.read(Fighter).respawn === 0;
@@ -46,8 +46,8 @@ export const GunControl = defineSystem('gun.control', {
46
46
  t.x = p.x + dir.x * (4 - gun.kick);
47
47
  t.y = p.y + 5 + dir.y * (4 - gun.kick);
48
48
  t.rotation = Math.atan2(dir.y, dir.x);
49
- t.scaleX = gun.weapon === 'rifle' ? 1.6 : gun.weapon === 'bazooka' ? 1.3 : 1; // shortcut: rifle e bazuca são a pistola esticada até terem arte própria
50
- t.scaleY = (dir.x < 0 ? -1 : 1) * (gun.weapon === 'bazooka' ? 1.6 : 1);
49
+ t.scaleX = gun.weapon === 'rifle' ? 1.6 : 1; // shortcut: o rifle é a pistola esticada até ter arte própria
50
+ t.scaleY = dir.x < 0 ? -1 : 1;
51
51
  if (gun.cooldown > 0) gun.cooldown--;
52
52
  if (gun.knifeCooldown > 0) gun.knifeCooldown--;
53
53
  if (f.respawn > 0 || !playing) continue;
@@ -86,22 +86,6 @@ export const GunControl = defineSystem('gun.control', {
86
86
  continue;
87
87
  }
88
88
 
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
89
  gun.cooldown = gun.rate;
106
90
  gun.kick = 3;
107
91
  body.velocity.x -= dir.x * gun.recoil;
@@ -126,14 +110,6 @@ export const BulletLifetime = defineSystem('gun.bullet-lifetime', {
126
110
  },
127
111
  });
128
112
 
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
113
  /** O traço do rifle esmaece e some. */
138
114
  export const TracerFade = defineSystem('gun.tracer-fade', {
139
115
  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', bazooka: 'bazuca' };
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, Tilemap, Transform2D, RigidBody2D } from '@vibe-engine/2d';
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();