@vibe-engine/cli 0.0.0-stage → 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/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +22 -0
- package/README.md +10 -2
- package/dist/assets.d.ts +9 -0
- package/dist/assets.js +76 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +7 -0
- package/dist/boundary.d.ts +12 -0
- package/dist/boundary.js +63 -0
- package/dist/create.d.ts +7 -0
- package/dist/create.js +56 -0
- package/dist/game-test.d.ts +60 -0
- package/dist/game-test.js +129 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/info.d.ts +41 -0
- package/dist/info.js +57 -0
- package/dist/main.d.ts +9 -0
- package/dist/main.js +106 -0
- package/dist/map.d.ts +21 -0
- package/dist/map.js +29 -0
- package/dist/project.d.ts +74 -0
- package/dist/project.js +273 -0
- package/dist/registry.d.ts +62 -0
- package/dist/registry.js +27 -0
- package/dist/run.d.ts +18 -0
- package/dist/run.js +132 -0
- package/dist/save-store.d.ts +2 -0
- package/dist/save-store.js +19 -0
- package/dist/serve.d.ts +6 -0
- package/dist/serve.js +63 -0
- package/dist/source.d.ts +7 -0
- package/dist/source.js +20 -0
- package/dist/test-run.d.ts +17 -0
- package/dist/test-run.js +94 -0
- package/dist/vite-plugin.d.ts +17 -0
- package/dist/vite-plugin.js +211 -0
- package/dist/web.d.ts +32 -0
- package/dist/web.js +195 -0
- package/package.json +52 -3
- package/templates/arena-3d/AGENTS.md +169 -0
- package/templates/arena-3d/CLAUDE.md +3 -0
- package/templates/arena-3d/README.md +13 -0
- package/templates/arena-3d/assets/audio/coin.wav +0 -0
- package/templates/arena-3d/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
- package/templates/arena-3d/assets/fonts/kenney-future.ttf +0 -0
- package/templates/arena-3d/assets/models/LICENSE-kenney-blocky-characters.txt +28 -0
- package/templates/arena-3d/assets/models/character.glb +0 -0
- package/templates/arena-3d/assets/ui/LICENSE-kenney-ui-pack.txt +23 -0
- package/templates/arena-3d/assets/ui/panel.meta.json +1 -0
- package/templates/arena-3d/assets/ui/panel.png +0 -0
- package/templates/arena-3d/package.json +22 -0
- package/templates/arena-3d/src/components/game.component.ts +11 -0
- package/templates/arena-3d/src/components/player.component.ts +16 -0
- package/templates/arena-3d/src/controls.input.ts +7 -0
- package/templates/arena-3d/src/level/build.ts +40 -0
- package/templates/arena-3d/src/maps/arena.map.ts +50 -0
- package/templates/arena-3d/src/scenes/arena.scene.ts +10 -0
- package/templates/arena-3d/src/systems/player-controller.system.ts +46 -0
- package/templates/arena-3d/src/systems/rules.system.ts +58 -0
- package/templates/arena-3d/src/ui/hud.ui.ts +11 -0
- package/templates/arena-3d/tests/arena.test.ts +111 -0
- package/templates/arena-3d/vibe.config.ts +21 -0
- package/templates/platformer-2d/AGENTS.md +172 -0
- package/templates/platformer-2d/CLAUDE.md +3 -0
- package/templates/platformer-2d/README.md +17 -0
- package/templates/platformer-2d/assets/KENNEY-LICENSE.txt +30 -0
- package/templates/platformer-2d/assets/audio/coin.wav +0 -0
- package/templates/platformer-2d/assets/audio/enemy-defeat.wav +0 -0
- package/templates/platformer-2d/assets/audio/enemy-hit.wav +0 -0
- package/templates/platformer-2d/assets/audio/game-over.wav +0 -0
- package/templates/platformer-2d/assets/audio/hurt.wav +0 -0
- package/templates/platformer-2d/assets/audio/jump.wav +0 -0
- package/templates/platformer-2d/assets/audio/level-complete.wav +0 -0
- package/templates/platformer-2d/assets/audio/music-theme.wav +0 -0
- package/templates/platformer-2d/assets/audio/shoot.wav +0 -0
- package/templates/platformer-2d/assets/audio/stomp.wav +0 -0
- package/templates/platformer-2d/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
- package/templates/platformer-2d/assets/fonts/kenney-pixel.ttf +0 -0
- package/templates/platformer-2d/assets/sprites/bullet.png +0 -0
- package/templates/platformer-2d/assets/sprites/characters.meta.json +9 -0
- package/templates/platformer-2d/assets/sprites/characters.png +0 -0
- package/templates/platformer-2d/assets/sprites/heart-empty.png +0 -0
- package/templates/platformer-2d/assets/sprites/heart.png +0 -0
- package/templates/platformer-2d/assets/sprites/pistol.png +0 -0
- package/templates/platformer-2d/assets/sprites/tiles.meta.json +7 -0
- package/templates/platformer-2d/assets/sprites/tiles.png +0 -0
- package/templates/platformer-2d/assets/ui/button-focus.meta.json +1 -0
- package/templates/platformer-2d/assets/ui/button-focus.png +0 -0
- package/templates/platformer-2d/assets/ui/button-hover.meta.json +1 -0
- package/templates/platformer-2d/assets/ui/button-hover.png +0 -0
- package/templates/platformer-2d/assets/ui/button-pressed.meta.json +1 -0
- package/templates/platformer-2d/assets/ui/button-pressed.png +0 -0
- package/templates/platformer-2d/assets/ui/button.meta.json +1 -0
- package/templates/platformer-2d/assets/ui/button.png +0 -0
- package/templates/platformer-2d/assets/ui/panel.meta.json +1 -0
- package/templates/platformer-2d/assets/ui/panel.png +0 -0
- package/templates/platformer-2d/package.json +22 -0
- package/templates/platformer-2d/src/components/enemy.component.ts +12 -0
- package/templates/platformer-2d/src/components/gun.component.ts +18 -0
- package/templates/platformer-2d/src/components/level.component.ts +10 -0
- package/templates/platformer-2d/src/components/pickup.component.ts +7 -0
- package/templates/platformer-2d/src/components/player.component.ts +25 -0
- package/templates/platformer-2d/src/components/shockwave.component.ts +7 -0
- package/templates/platformer-2d/src/controls.input.ts +10 -0
- package/templates/platformer-2d/src/events/gameplay.events.ts +11 -0
- package/templates/platformer-2d/src/level/build.ts +89 -0
- package/templates/platformer-2d/src/listeners/feedback.listener.ts +22 -0
- package/templates/platformer-2d/src/listeners/particles.listener.ts +21 -0
- package/templates/platformer-2d/src/listeners/progress.listener.ts +18 -0
- package/templates/platformer-2d/src/listeners/sound-effects.listener.ts +16 -0
- package/templates/platformer-2d/src/maps/legend.ts +9 -0
- package/templates/platformer-2d/src/maps/level-1.map.ts +22 -0
- package/templates/platformer-2d/src/maps/level-2.map.ts +22 -0
- package/templates/platformer-2d/src/saves/progress.save.ts +11 -0
- package/templates/platformer-2d/src/scenes/level-1.scene.ts +17 -0
- package/templates/platformer-2d/src/scenes/level-2.scene.ts +16 -0
- package/templates/platformer-2d/src/scenes/main-menu.scene.ts +36 -0
- package/templates/platformer-2d/src/systems/contacts.system.ts +74 -0
- package/templates/platformer-2d/src/systems/enemy-patrol.system.ts +28 -0
- package/templates/platformer-2d/src/systems/gameplay.ts +17 -0
- package/templates/platformer-2d/src/systems/gun.system.ts +65 -0
- package/templates/platformer-2d/src/systems/hud.system.ts +23 -0
- package/templates/platformer-2d/src/systems/pause.system.ts +22 -0
- package/templates/platformer-2d/src/systems/player-controller.system.ts +46 -0
- package/templates/platformer-2d/src/systems/player-damage.system.ts +61 -0
- package/templates/platformer-2d/src/systems/player-juice.system.ts +40 -0
- package/templates/platformer-2d/src/systems/shockwave.system.ts +15 -0
- package/templates/platformer-2d/src/ui/hud.ui.ts +16 -0
- package/templates/platformer-2d/src/ui/main-menu.ui.ts +7 -0
- package/templates/platformer-2d/src/ui/pause-menu.ui.ts +12 -0
- package/templates/platformer-2d/tests/gameplay.test.ts +492 -0
- package/templates/platformer-2d/tests/jump.test.ts +41 -0
- package/templates/platformer-2d/vibe.config.ts +32 -0
- package/templates/shooter-2d-pvp/AGENTS.md +181 -0
- package/templates/shooter-2d-pvp/CLAUDE.md +3 -0
- package/templates/shooter-2d-pvp/README.md +14 -0
- package/templates/shooter-2d-pvp/assets/KENNEY-LICENSE.txt +30 -0
- package/templates/shooter-2d-pvp/assets/audio/enemy-defeat.wav +0 -0
- package/templates/shooter-2d-pvp/assets/audio/enemy-hit.wav +0 -0
- package/templates/shooter-2d-pvp/assets/audio/game-over.wav +0 -0
- package/templates/shooter-2d-pvp/assets/audio/hurt.wav +0 -0
- package/templates/shooter-2d-pvp/assets/audio/jump.wav +0 -0
- package/templates/shooter-2d-pvp/assets/audio/shoot.wav +0 -0
- package/templates/shooter-2d-pvp/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
- package/templates/shooter-2d-pvp/assets/fonts/kenney-pixel.ttf +0 -0
- package/templates/shooter-2d-pvp/assets/sprites/bullet.png +0 -0
- package/templates/shooter-2d-pvp/assets/sprites/characters.meta.json +84 -0
- package/templates/shooter-2d-pvp/assets/sprites/characters.png +0 -0
- package/templates/shooter-2d-pvp/assets/sprites/heart.png +0 -0
- package/templates/shooter-2d-pvp/assets/sprites/pistol.png +0 -0
- package/templates/shooter-2d-pvp/assets/sprites/tiles.meta.json +7 -0
- package/templates/shooter-2d-pvp/assets/sprites/tiles.png +0 -0
- package/templates/shooter-2d-pvp/assets/ui/button-focus.meta.json +1 -0
- package/templates/shooter-2d-pvp/assets/ui/button-focus.png +0 -0
- package/templates/shooter-2d-pvp/assets/ui/button-hover.meta.json +1 -0
- package/templates/shooter-2d-pvp/assets/ui/button-hover.png +0 -0
- package/templates/shooter-2d-pvp/assets/ui/button-pressed.meta.json +1 -0
- package/templates/shooter-2d-pvp/assets/ui/button-pressed.png +0 -0
- package/templates/shooter-2d-pvp/assets/ui/button.meta.json +1 -0
- package/templates/shooter-2d-pvp/assets/ui/button.png +0 -0
- package/templates/shooter-2d-pvp/assets/ui/panel.meta.json +1 -0
- package/templates/shooter-2d-pvp/assets/ui/panel.png +0 -0
- package/templates/shooter-2d-pvp/package.json +23 -0
- package/templates/shooter-2d-pvp/src/components/fighter.component.ts +33 -0
- package/templates/shooter-2d-pvp/src/components/gun.component.ts +49 -0
- package/templates/shooter-2d-pvp/src/controls.input.ts +14 -0
- package/templates/shooter-2d-pvp/src/events/combat.events.ts +13 -0
- package/templates/shooter-2d-pvp/src/level/build.ts +46 -0
- package/templates/shooter-2d-pvp/src/listeners/effects.listener.ts +51 -0
- package/templates/shooter-2d-pvp/src/listeners/players.listener.ts +32 -0
- package/templates/shooter-2d-pvp/src/maps/arena.map.ts +26 -0
- package/templates/shooter-2d-pvp/src/rooms/arena.room.ts +22 -0
- package/templates/shooter-2d-pvp/src/rules/damage.ts +41 -0
- package/templates/shooter-2d-pvp/src/saves/player.save.ts +9 -0
- package/templates/shooter-2d-pvp/src/scenes/arena.scene.ts +15 -0
- package/templates/shooter-2d-pvp/src/scenes/lobby.scene.ts +11 -0
- package/templates/shooter-2d-pvp/src/systems/combat.system.ts +85 -0
- package/templates/shooter-2d-pvp/src/systems/fighter-controller.system.ts +54 -0
- package/templates/shooter-2d-pvp/src/systems/gun.system.ts +123 -0
- package/templates/shooter-2d-pvp/src/systems/lobby.system.ts +52 -0
- package/templates/shooter-2d-pvp/src/systems/view.system.ts +35 -0
- package/templates/shooter-2d-pvp/src/ui/hud.ui.ts +10 -0
- package/templates/shooter-2d-pvp/src/ui/lobby.ui.ts +18 -0
- package/templates/shooter-2d-pvp/tests/pvp.test.ts +221 -0
- package/templates/shooter-2d-pvp/vibe.config.ts +39 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { RigidBody2D, Sprite, SpriteShader, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { Player } from '../components/player.component.ts';
|
|
4
|
+
import { Level } from '../components/level.component.ts';
|
|
5
|
+
import { PlayerHurt } from '../events/gameplay.events.ts';
|
|
6
|
+
|
|
7
|
+
const INVULNERABLE_TICKS = 90;
|
|
8
|
+
const FLASH_TICKS = 10;
|
|
9
|
+
|
|
10
|
+
/** Dano, clarão branco no hit, piscar enquanto invulnerável, cair do mapa e game over. */
|
|
11
|
+
export const PlayerDamage = defineSystem('player.damage', {
|
|
12
|
+
stage: 'postPhysics',
|
|
13
|
+
after: ['gameplay.contacts'],
|
|
14
|
+
query: [Player, Transform2D, RigidBody2D, Sprite],
|
|
15
|
+
optional: [SpriteShader],
|
|
16
|
+
reads: [PlayerHurt],
|
|
17
|
+
update({ entities, events, world, scene }) {
|
|
18
|
+
const level = world.entity('level').write(Level);
|
|
19
|
+
for (const e of entities) {
|
|
20
|
+
const p = e.write(Player);
|
|
21
|
+
const tr = e.read(Transform2D);
|
|
22
|
+
const hits = events.read(PlayerHurt);
|
|
23
|
+
let hurt = hits.length > 0 && p.invulnerable === 0;
|
|
24
|
+
const source = hits[0] && world.exists(hits[0].by) ? world.entity(hits[0].by).read(Transform2D) : null;
|
|
25
|
+
|
|
26
|
+
// Caiu do mapa: perde vida e volta para o início.
|
|
27
|
+
if (tr.y > level.height + 48) {
|
|
28
|
+
hurt = true;
|
|
29
|
+
p.invulnerable = 0;
|
|
30
|
+
const t = e.write(Transform2D);
|
|
31
|
+
t.x = p.spawn.x;
|
|
32
|
+
t.y = p.spawn.y;
|
|
33
|
+
e.write(RigidBody2D).velocity = { x: 0, y: 0 };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (hurt && level.status === 'playing') {
|
|
37
|
+
p.lives = Math.max(0, p.lives - 1);
|
|
38
|
+
p.invulnerable = INVULNERABLE_TICKS;
|
|
39
|
+
// Knockback: para longe de quem machucou (cair do mapa não empurra).
|
|
40
|
+
const body = e.write(RigidBody2D);
|
|
41
|
+
if (source) {
|
|
42
|
+
const away = Math.sign(tr.x - source.x) || (e.read(Sprite).flipX ? 1 : -1);
|
|
43
|
+
body.velocity = { x: away * p.knockback.x, y: -p.knockback.y };
|
|
44
|
+
p.stun = 14;
|
|
45
|
+
} else {
|
|
46
|
+
body.velocity.y = -200;
|
|
47
|
+
}
|
|
48
|
+
if (p.lives === 0) {
|
|
49
|
+
p.frozen = true;
|
|
50
|
+
level.status = 'game-over';
|
|
51
|
+
scene.go('level-1', { params: { lives: 3, coins: 0 }, delay: { seconds: 2 } });
|
|
52
|
+
}
|
|
53
|
+
} else if (p.invulnerable > 0) {
|
|
54
|
+
p.invulnerable--;
|
|
55
|
+
}
|
|
56
|
+
e.write(Sprite).alpha = p.invulnerable > 0 && Math.floor(p.invulnerable / 5) % 2 === 0 ? 0.35 : 1;
|
|
57
|
+
// Clarão (shader `flash`): 1 no hit, some em FLASH_TICKS. É estado: o teste lê, o renderer só desenha.
|
|
58
|
+
if (e.has(SpriteShader)) e.write(SpriteShader).uniforms.amount = Math.max(0, p.invulnerable - (INVULNERABLE_TICKS - FLASH_TICKS)) / FLASH_TICKS;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Grounded, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { Player } from '../components/player.component.ts';
|
|
4
|
+
import { PlayerJumped, PlayerLanded } from '../events/gameplay.events.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Squash & stretch: estica no pulo, achata no pouso e volta ao normal em
|
|
8
|
+
* poucos ticks. É escala no Transform2D (a física ignora escala).
|
|
9
|
+
*/
|
|
10
|
+
export const PlayerJuice = defineSystem('player.juice', {
|
|
11
|
+
after: ['player.controller'],
|
|
12
|
+
query: [Player, Transform2D],
|
|
13
|
+
optional: [Grounded],
|
|
14
|
+
reads: [PlayerJumped],
|
|
15
|
+
update({ entities, events, emit }) {
|
|
16
|
+
const jumped = events.read(PlayerJumped).length > 0;
|
|
17
|
+
for (const e of entities) {
|
|
18
|
+
const p = e.write(Player);
|
|
19
|
+
const t = e.write(Transform2D);
|
|
20
|
+
if (e.has(Grounded)) {
|
|
21
|
+
if (p.airTicks > 8) {
|
|
22
|
+
t.scaleX = 1.25;
|
|
23
|
+
t.scaleY = 0.78;
|
|
24
|
+
emit(PlayerLanded, { airTicks: p.airTicks });
|
|
25
|
+
}
|
|
26
|
+
p.airTicks = 0;
|
|
27
|
+
} else {
|
|
28
|
+
p.airTicks++;
|
|
29
|
+
}
|
|
30
|
+
if (jumped) {
|
|
31
|
+
t.scaleX = 0.78;
|
|
32
|
+
t.scaleY = 1.25;
|
|
33
|
+
}
|
|
34
|
+
t.scaleX += (1 - t.scaleX) * 0.22;
|
|
35
|
+
t.scaleY += (1 - t.scaleY) * 0.22;
|
|
36
|
+
if (Math.abs(t.scaleX - 1) < 0.01) t.scaleX = 1;
|
|
37
|
+
if (Math.abs(t.scaleY - 1) < 0.01) t.scaleY = 1;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PostEffect, defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Shockwave } from '../components/shockwave.component.ts';
|
|
3
|
+
|
|
4
|
+
/** Expande a onda de choque (uniform `progress` de 0 a 1) e tira a entidade no fim. Roda também no hit-stop (stage update). */
|
|
5
|
+
export const ShockwaveFade = defineSystem('effects.shockwave', {
|
|
6
|
+
query: [Shockwave, PostEffect],
|
|
7
|
+
update({ entities, world }) {
|
|
8
|
+
for (const e of entities) {
|
|
9
|
+
const s = e.write(Shockwave);
|
|
10
|
+
s.tick++;
|
|
11
|
+
e.write(PostEffect).uniforms.progress = Math.min(1, s.tick / s.duration);
|
|
12
|
+
if (s.tick >= s.duration) world.despawn(e.id);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UiAnchor, UiImage, UiStack, UiStyle, UiText, definePrefab } from '@vibe-engine/core';
|
|
2
|
+
|
|
3
|
+
/** HUD: corações, moedas e fase. O system `ui.hud` mantém o conteúdo em dia com o estado. */
|
|
4
|
+
export const hud = definePrefab('hud', () => ({
|
|
5
|
+
components: [UiAnchor({ corner: 'top-left', margin: 12 }), UiStack({ direction: 'row', gap: 10 }), UiStyle({ use: 'panel' })],
|
|
6
|
+
children: {
|
|
7
|
+
'heart-1': [UiImage({ asset: 'sprites/heart', width: 27, height: 27 })],
|
|
8
|
+
'heart-2': [UiImage({ asset: 'sprites/heart', width: 27, height: 27 })],
|
|
9
|
+
'heart-3': [UiImage({ asset: 'sprites/heart', width: 27, height: 27 })],
|
|
10
|
+
coins: [UiText(), UiStyle({ use: 'hud' })],
|
|
11
|
+
level: [UiText(), UiStyle({ use: 'hud' })],
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
/** Mensagem grande no meio da tela (fase concluída, vitória, game over). */
|
|
16
|
+
export const banner = definePrefab('banner', () => [UiAnchor({ corner: 'center' }), UiText(), UiStyle({ use: 'banner' })]);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UiAnchor, UiButton, UiFocus, UiStack, definePrefab } from '@vibe-engine/core';
|
|
2
|
+
|
|
3
|
+
/** Botões do menu principal, com foco preso (setas + Enter, ou mouse). */
|
|
4
|
+
export const mainMenu = definePrefab('main-menu', () => ({
|
|
5
|
+
components: [UiAnchor({ corner: 'center', offset: { x: 0, y: 30 } }), UiStack({ gap: 10 }), UiFocus()],
|
|
6
|
+
children: { play: [UiButton({ label: 'jogar' })], controls: [UiButton({ label: 'controles' })] },
|
|
7
|
+
}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UiAnchor, UiButton, UiFocus, UiStack, UiStyle, UiText, definePrefab } from '@vibe-engine/core';
|
|
2
|
+
|
|
3
|
+
/** Menu de pausa: foco preso nos botões (setas + Enter, ou mouse). Nasce escondido. */
|
|
4
|
+
export const pauseMenu = definePrefab('pause-menu', () => ({
|
|
5
|
+
components: [UiAnchor({ corner: 'center' }), UiStack({ gap: 8, align: 'stretch' }), UiStyle({ use: 'panel' }), UiFocus()],
|
|
6
|
+
children: {
|
|
7
|
+
title: [UiText({ text: 'pausado' }), UiStyle({ use: 'title' })],
|
|
8
|
+
resume: [UiButton({ label: 'continuar' })],
|
|
9
|
+
restart: [UiButton({ label: 'reiniciar fase' })],
|
|
10
|
+
menu: [UiButton({ label: 'menu principal' })],
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testes headless do template (#20): só estado e eventos, sem tela.
|
|
3
|
+
* `pnpm test` roda; o mesmo jogo abre no browser com `pnpm dev`.
|
|
4
|
+
* Para isolar uma regra, o teste põe o player perto do que quer testar
|
|
5
|
+
* (escrever Transform2D teletransporta o corpo).
|
|
6
|
+
*/
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { execFileSync } from 'node:child_process';
|
|
11
|
+
import { openScene } from '@vibe-engine/cli';
|
|
12
|
+
import { memorySaveStore } from '@vibe-engine/core';
|
|
13
|
+
import { Progress } from '../src/saves/progress.save.ts';
|
|
14
|
+
import { UiImage, UiText, type World } from '@vibe-engine/core';
|
|
15
|
+
import { Grounded, RigidBody2D, Sprite, SpriteShader, Transform2D } from '@vibe-engine/2d';
|
|
16
|
+
import { PostEffect } from '@vibe-engine/core';
|
|
17
|
+
import { Player } from '../src/components/player.component.ts';
|
|
18
|
+
import { Level } from '../src/components/level.component.ts';
|
|
19
|
+
import { Enemy } from '../src/components/enemy.component.ts';
|
|
20
|
+
import { Gun } from '../src/components/gun.component.ts';
|
|
21
|
+
|
|
22
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
23
|
+
const GROUND_Y = 168; // centro do player em pé no chão da linha 10 (topo em y=180; caixa vai até y+12)
|
|
24
|
+
const PIT_X = 20 * 18 + 9; // primeiro buraco da fase 1
|
|
25
|
+
const open = (scene = 'level-1', seed = 1) => openScene(root, { scene, seed });
|
|
26
|
+
const player = (w: World) => w.entity('player');
|
|
27
|
+
const pos = (w: World, id: string) => w.entity(id).read(Transform2D);
|
|
28
|
+
const events = (w: World, name: string) => w.observe({ entityIds: [] }).events.filter((e) => e.name === name);
|
|
29
|
+
function teleport(w: World, x: number, y: number) {
|
|
30
|
+
const t = player(w).write(Transform2D);
|
|
31
|
+
t.x = x;
|
|
32
|
+
t.y = y;
|
|
33
|
+
player(w).write(RigidBody2D).velocity = { x: 0, y: 0 };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test('the player lands on the ground and is Grounded; observe shows Transform2D and Grounded', async () => {
|
|
37
|
+
const w = await open();
|
|
38
|
+
w.step(30);
|
|
39
|
+
const p = w.observe({ entityIds: ['player'] }).entities.player!;
|
|
40
|
+
assert.ok('Grounded' in p && 'Transform2D' in p);
|
|
41
|
+
const y = (p.Transform2D as { y: number }).y;
|
|
42
|
+
assert.ok(Math.abs(y - GROUND_Y) < 1, `stands on the ground, got y=${y}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('move walks; jump only from the ground, no double jump', async () => {
|
|
46
|
+
const w = await open();
|
|
47
|
+
w.step(30);
|
|
48
|
+
const x0 = pos(w, 'player').x;
|
|
49
|
+
w.input.set('move', 1);
|
|
50
|
+
w.step(20);
|
|
51
|
+
assert.ok(pos(w, 'player').x > x0 + 30, 'walked right');
|
|
52
|
+
w.input.set('move', 0);
|
|
53
|
+
w.input.set('jump', true); // segurando: pulo inteiro
|
|
54
|
+
w.step(2);
|
|
55
|
+
assert.ok(player(w).read(RigidBody2D).velocity.y < -250, 'jumped');
|
|
56
|
+
assert.equal(events(w, 'player.jumped').length, 1);
|
|
57
|
+
w.step(12);
|
|
58
|
+
w.input.set('jump', false);
|
|
59
|
+
w.step(1);
|
|
60
|
+
w.input.set('jump', true); // de novo no ar, depois da janela de coyote
|
|
61
|
+
w.step(2);
|
|
62
|
+
assert.equal(events(w, 'player.jumped').length, 1, 'no double jump');
|
|
63
|
+
w.input.set('jump', false);
|
|
64
|
+
w.step(60);
|
|
65
|
+
assert.ok(player(w).has(Grounded), 'lands again');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('game feel: acceleration instead of instant speed', async () => {
|
|
69
|
+
const w = await open();
|
|
70
|
+
w.step(30);
|
|
71
|
+
w.input.set('move', 1);
|
|
72
|
+
w.step(2);
|
|
73
|
+
const early = player(w).read(RigidBody2D).velocity.x;
|
|
74
|
+
w.step(10);
|
|
75
|
+
assert.ok(early > 0 && early < 120, `still accelerating after 2 ticks, got ${early}`);
|
|
76
|
+
assert.equal(player(w).read(RigidBody2D).velocity.x, 120, 'top speed after a few ticks');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('game feel: variable jump height (tap = short hop, hold = full jump)', async () => {
|
|
80
|
+
const peak = async (holdTicks: number) => {
|
|
81
|
+
const w = await open();
|
|
82
|
+
w.step(30);
|
|
83
|
+
const y0 = pos(w, 'player').y;
|
|
84
|
+
w.input.set('jump', true);
|
|
85
|
+
let top = y0;
|
|
86
|
+
for (let i = 0; i < 70; i++) {
|
|
87
|
+
if (i === holdTicks) w.input.set('jump', false);
|
|
88
|
+
w.step(1);
|
|
89
|
+
top = Math.min(top, pos(w, 'player').y);
|
|
90
|
+
}
|
|
91
|
+
return y0 - top;
|
|
92
|
+
};
|
|
93
|
+
const tap = await peak(1);
|
|
94
|
+
const hold = await peak(30);
|
|
95
|
+
assert.ok(hold > tap * 2, `full jump ${hold.toFixed(1)} px vs hop ${tap.toFixed(1)} px`);
|
|
96
|
+
assert.ok(hold > 54, `a full jump clears a 3-tile platform, got ${hold.toFixed(1)} px`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('game feel: coyote time (jump right after walking off an edge)', async () => {
|
|
100
|
+
const leaveEdge = async (lateTicks: number) => {
|
|
101
|
+
const w = await open();
|
|
102
|
+
w.step(30);
|
|
103
|
+
teleport(w, PIT_X - 2 * 18, GROUND_Y); // dois tiles antes do buraco
|
|
104
|
+
w.input.set('move', 1);
|
|
105
|
+
let t = 0;
|
|
106
|
+
while (player(w).has(Grounded) && t++ < 60) w.step(1);
|
|
107
|
+
w.step(lateTicks);
|
|
108
|
+
w.input.set('jump', true);
|
|
109
|
+
w.step(2);
|
|
110
|
+
return events(w, 'player.jumped').length;
|
|
111
|
+
};
|
|
112
|
+
assert.equal(await leaveEdge(3), 1, 'jumps 3 ticks after leaving the ground');
|
|
113
|
+
assert.equal(await leaveEdge(12), 0, 'too late: falls');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('game feel: jump buffer (press a little before landing)', async () => {
|
|
117
|
+
const w = await open();
|
|
118
|
+
w.step(30);
|
|
119
|
+
teleport(w, pos(w, 'player').x, GROUND_Y - 40);
|
|
120
|
+
let t = 0;
|
|
121
|
+
while (pos(w, 'player').y < GROUND_Y - 8 && t++ < 60) w.step(1); // quase no chão
|
|
122
|
+
assert.equal(player(w).has(Grounded), false);
|
|
123
|
+
w.input.press('jump');
|
|
124
|
+
w.step(8);
|
|
125
|
+
assert.equal(events(w, 'player.jumped').length, 1, 'the early press still jumps on landing');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('coins: touching one collects it and emits coin.collected', async () => {
|
|
129
|
+
const w = await open();
|
|
130
|
+
w.step(30);
|
|
131
|
+
const coin = pos(w, 'coin-1');
|
|
132
|
+
teleport(w, coin.x - 20, coin.y);
|
|
133
|
+
w.input.set('move', 1);
|
|
134
|
+
w.step(12); // a próxima moeda está 36 px adiante
|
|
135
|
+
assert.equal(player(w).read(Player).coins, 1);
|
|
136
|
+
assert.equal(w.exists('coin-1'), false);
|
|
137
|
+
assert.deepEqual(events(w, 'coin.collected').map((e) => e.payload), [{ coin: 'coin-1', total: 1 }]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('enemies patrol inside their stretch of ground', async () => {
|
|
141
|
+
const w = await open();
|
|
142
|
+
const { left, right } = w.entity('enemy-1').read(Enemy);
|
|
143
|
+
const xs: number[] = [];
|
|
144
|
+
for (let i = 0; i < 600; i++) { w.step(1); xs.push(pos(w, 'enemy-1').x); }
|
|
145
|
+
assert.ok(Math.min(...xs) >= left - 2 && Math.max(...xs) <= right + 2, 'stays in range');
|
|
146
|
+
assert.ok(Math.max(...xs) - Math.min(...xs) > (right - left) * 0.9, 'walks the whole range');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('landing on an enemy defeats it and bounces; walking into it hurts', async () => {
|
|
150
|
+
const w = await open();
|
|
151
|
+
w.step(30);
|
|
152
|
+
const e = pos(w, 'enemy-1');
|
|
153
|
+
teleport(w, e.x, e.y - 40);
|
|
154
|
+
w.step(30);
|
|
155
|
+
assert.equal(w.exists('enemy-1'), false, 'stomped');
|
|
156
|
+
assert.equal(events(w, 'enemy.defeated').length, 1);
|
|
157
|
+
assert.equal(player(w).read(Player).lives, 3, 'no damage when stomping');
|
|
158
|
+
|
|
159
|
+
const w2 = await open();
|
|
160
|
+
w2.step(30);
|
|
161
|
+
const e2 = pos(w2, 'enemy-1');
|
|
162
|
+
teleport(w2, e2.x - 30, GROUND_Y);
|
|
163
|
+
w2.input.set('move', 1);
|
|
164
|
+
w2.step(30);
|
|
165
|
+
assert.equal(player(w2).read(Player).lives, 2, 'hurt from the side');
|
|
166
|
+
assert.ok(player(w2).read(Player).invulnerable > 0, 'invulnerable for a while');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('gun: aims where the input points, the player faces it, holding fire shoots at a fixed rate', async () => {
|
|
170
|
+
const w = await open();
|
|
171
|
+
w.step(30);
|
|
172
|
+
w.input.set('aim', [-1, 0]);
|
|
173
|
+
w.input.set('fire', true);
|
|
174
|
+
w.step(30); // rate 14: tiros nos ticks 1, 15 e 29
|
|
175
|
+
const shots = events(w, 'gun.fired');
|
|
176
|
+
assert.equal(shots.length, 3);
|
|
177
|
+
assert.deepEqual((shots[0]!.payload as { dir: unknown }).dir, { x: -1, y: 0 });
|
|
178
|
+
assert.equal(player(w).read(Sprite).flipX, true, 'faces left');
|
|
179
|
+
assert.equal(w.entity('gun').read(Transform2D).scaleY, -1, 'gun not upside down');
|
|
180
|
+
const bullet = (shots[2]!.payload as { bullet: string }).bullet;
|
|
181
|
+
assert.ok(pos(w, bullet).x < pos(w, 'player').x, 'bullet flies left');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('gun: two shots defeat an enemy; bullets vanish on walls and after their lifetime', async () => {
|
|
185
|
+
const w = await open();
|
|
186
|
+
w.step(30);
|
|
187
|
+
const e = pos(w, 'enemy-1');
|
|
188
|
+
teleport(w, e.x - 70, GROUND_Y);
|
|
189
|
+
w.input.set('aim', [1, 0.05]);
|
|
190
|
+
w.input.set('fire', true);
|
|
191
|
+
let t = 0;
|
|
192
|
+
while (w.exists('enemy-1') && t++ < 120) w.step(1);
|
|
193
|
+
assert.equal(w.exists('enemy-1'), false, 'defeated');
|
|
194
|
+
assert.deepEqual(events(w, 'enemy.defeated').map((x) => x.payload), [{ enemy: 'enemy-1', how: 'shot' }]);
|
|
195
|
+
assert.ok(w.entity('gun').read(Gun).shots >= 2);
|
|
196
|
+
|
|
197
|
+
w.input.set('aim', [0, 1]); // no chão
|
|
198
|
+
w.step(20);
|
|
199
|
+
w.input.set('fire', false);
|
|
200
|
+
w.step(70);
|
|
201
|
+
assert.equal(Object.keys(w.observe().entities).filter((id) => id.startsWith('bullet-')).length, 0, 'no bullets left');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('spikes hurt; falling off the map costs a life and respawns at the start', async () => {
|
|
205
|
+
const w = await open();
|
|
206
|
+
w.step(30);
|
|
207
|
+
const id = Object.keys(w.observe().entities).find((k) => k.startsWith('spikes-'))!;
|
|
208
|
+
teleport(w, pos(w, id).x, 150);
|
|
209
|
+
w.step(30);
|
|
210
|
+
assert.equal(player(w).read(Player).lives, 2);
|
|
211
|
+
assert.equal((events(w, 'player.hurt')[0]!.payload as { by: string }).by, id);
|
|
212
|
+
|
|
213
|
+
const w2 = await open();
|
|
214
|
+
w2.step(30);
|
|
215
|
+
teleport(w2, PIT_X, 150);
|
|
216
|
+
w2.step(90);
|
|
217
|
+
const p = player(w2).read(Player);
|
|
218
|
+
assert.equal(p.lives, 2);
|
|
219
|
+
assert.ok(Math.abs(pos(w2, 'player').x - p.spawn.x) < 1, 'back at the spawn point');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('losing every life is game over and restarts level 1 with 3 lives', async () => {
|
|
223
|
+
const w = await open();
|
|
224
|
+
w.step(30);
|
|
225
|
+
player(w).write(Player).lives = 1;
|
|
226
|
+
teleport(w, PIT_X, 150);
|
|
227
|
+
w.step(60);
|
|
228
|
+
assert.equal(w.entity('level').read(Level).status, 'game-over');
|
|
229
|
+
assert.equal(player(w).read(Player).frozen, true);
|
|
230
|
+
w.step(150);
|
|
231
|
+
assert.equal(w.observe().scene, 'level-1');
|
|
232
|
+
assert.equal(player(w).read(Player).lives, 3);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('the flag completes level 1 and carries lives and coins into level 2; level 2 flag wins', async () => {
|
|
236
|
+
const w = await open();
|
|
237
|
+
w.step(30);
|
|
238
|
+
player(w).write(Player).coins = 4;
|
|
239
|
+
const flag = pos(w, 'goal');
|
|
240
|
+
teleport(w, flag.x - 20, GROUND_Y);
|
|
241
|
+
w.input.set('move', 1);
|
|
242
|
+
w.step(20);
|
|
243
|
+
assert.equal(w.entity('level').read(Level).status, 'completed');
|
|
244
|
+
assert.deepEqual(events(w, 'level.completed').map((e) => e.payload), [{ level: 1, coins: 4 }]);
|
|
245
|
+
w.step(100);
|
|
246
|
+
assert.equal(w.observe().scene, 'level-2');
|
|
247
|
+
assert.equal(player(w).read(Player).coins, 4);
|
|
248
|
+
assert.equal(w.entity('level').read(Level).number, 2);
|
|
249
|
+
|
|
250
|
+
const w2 = await open('level-2');
|
|
251
|
+
w2.step(30);
|
|
252
|
+
const flag2 = pos(w2, 'goal');
|
|
253
|
+
teleport(w2, flag2.x - 20, flag2.y);
|
|
254
|
+
w2.input.set('move', 1);
|
|
255
|
+
w2.step(30);
|
|
256
|
+
assert.equal(w2.entity('level').read(Level).status, 'won');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('audio: scene music starts; game events play their sounds (checked headless, no speakers)', async () => {
|
|
260
|
+
const w = await open();
|
|
261
|
+
w.step(30);
|
|
262
|
+
w.input.set('jump', true);
|
|
263
|
+
w.step(2);
|
|
264
|
+
w.input.set('jump', false);
|
|
265
|
+
w.input.set('aim', [1, 0]);
|
|
266
|
+
w.input.press('fire');
|
|
267
|
+
w.step(2);
|
|
268
|
+
const sounds = w.observe({ entityIds: [] }).events.filter((e) => e.name.startsWith('audio.')).map((e) => (e.payload as { sound?: string; track?: string }).sound ?? `music:${(e.payload as { track: string }).track}`);
|
|
269
|
+
assert.deepEqual(sounds, ['music:audio/music-theme', 'audio/jump', 'audio/shoot']);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('juice: jump stretches, landing squashes, both settle back to scale 1', async () => {
|
|
273
|
+
const w = await open();
|
|
274
|
+
w.step(30);
|
|
275
|
+
w.input.set('jump', true);
|
|
276
|
+
w.step(2);
|
|
277
|
+
assert.ok(pos(w, 'player').scaleY > 1.1, 'stretched on jump');
|
|
278
|
+
w.input.set('jump', false);
|
|
279
|
+
let landed = false;
|
|
280
|
+
for (let i = 0; i < 90 && !landed; i++) { w.step(1); landed = events(w, 'player.landed').length > 0; }
|
|
281
|
+
assert.ok(landed, 'landed');
|
|
282
|
+
assert.ok(pos(w, 'player').scaleY < 0.95, 'squashed on landing');
|
|
283
|
+
w.step(30);
|
|
284
|
+
assert.deepEqual([pos(w, 'player').scaleX, pos(w, 'player').scaleY], [1, 1]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('juice: stomping shakes the camera and freezes the action for a few ticks (hit-stop)', async () => {
|
|
288
|
+
const w = await open();
|
|
289
|
+
w.step(30);
|
|
290
|
+
const e = pos(w, 'enemy-1');
|
|
291
|
+
teleport(w, e.x, e.y - 40);
|
|
292
|
+
let t = 0;
|
|
293
|
+
while (w.exists('enemy-1') && t++ < 40) w.step(1);
|
|
294
|
+
assert.ok(w.hitStopLeft > 0, 'hit-stop active right after the stomp');
|
|
295
|
+
assert.ok(events(w, 'camera.shake').some((x) => (x.payload as { amount: number }).amount >= 2), 'shake');
|
|
296
|
+
const enemyX = Object.keys(w.observe().entities).includes('enemy-2') ? pos(w, 'enemy-2').x : null;
|
|
297
|
+
w.step(1);
|
|
298
|
+
if (enemyX !== null) assert.equal(pos(w, 'enemy-2').x, enemyX, 'the world is frozen during hit-stop');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test('feel: recoil kicks the gun back and pushes the player against the shot', async () => {
|
|
302
|
+
const w = await open();
|
|
303
|
+
w.step(30);
|
|
304
|
+
w.input.set('aim', [1, 0]);
|
|
305
|
+
w.step(1);
|
|
306
|
+
const restX = pos(w, 'gun').x - pos(w, 'player').x;
|
|
307
|
+
w.input.press('fire');
|
|
308
|
+
w.step(1);
|
|
309
|
+
assert.ok(player(w).read(RigidBody2D).velocity.x < -30, 'pushed left when shooting right');
|
|
310
|
+
assert.ok(w.entity('gun').read(Gun).kick > 1, 'gun kicked back');
|
|
311
|
+
w.step(1); // a arma é posicionada antes do tiro: o coice aparece no tick seguinte
|
|
312
|
+
assert.ok(pos(w, 'gun').x - pos(w, 'player').x < restX, 'gun drawn closer to the body');
|
|
313
|
+
w.step(20);
|
|
314
|
+
assert.equal(w.entity('gun').read(Gun).kick, 0, 'kick settles');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('feel: getting hurt knocks the player away from the source and takes control for a moment', async () => {
|
|
318
|
+
const w = await open();
|
|
319
|
+
w.step(30);
|
|
320
|
+
const e = pos(w, 'enemy-1');
|
|
321
|
+
teleport(w, e.x - 30, GROUND_Y);
|
|
322
|
+
w.input.set('move', 1); // andando para o inimigo
|
|
323
|
+
let t = 0;
|
|
324
|
+
while (player(w).read(Player).lives === 3 && t++ < 60) w.step(1);
|
|
325
|
+
w.step(1);
|
|
326
|
+
assert.ok(player(w).read(RigidBody2D).velocity.x < -100, 'thrown back, away from the enemy, even holding right');
|
|
327
|
+
assert.ok(player(w).read(Player).stun > 0, 'no control while stunned');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('shaders: getting hurt flashes the player white (flash uniform from state), fading in a few ticks', async () => {
|
|
331
|
+
const w = await open();
|
|
332
|
+
w.step(30);
|
|
333
|
+
const flash = () => player(w).read(SpriteShader).uniforms.amount as number;
|
|
334
|
+
assert.equal(flash(), 0);
|
|
335
|
+
const e = pos(w, 'enemy-1');
|
|
336
|
+
teleport(w, e.x - 30, GROUND_Y);
|
|
337
|
+
w.input.set('move', 1);
|
|
338
|
+
let t = 0;
|
|
339
|
+
while (player(w).read(Player).lives === 3 && t++ < 60) w.step(1);
|
|
340
|
+
assert.equal(flash(), 1, 'full flash on the hit tick');
|
|
341
|
+
assert.deepEqual(w.observe({ entityIds: ['player'] }).entities.player!.SpriteShader, { shader: 'flash', uniforms: { amount: 1 } });
|
|
342
|
+
w.step(5 + 3); // o hit-stop do dano segura 5 ticks; depois apaga
|
|
343
|
+
assert.ok(flash() > 0 && flash() < 1, 'fading');
|
|
344
|
+
w.step(10);
|
|
345
|
+
assert.equal(flash(), 0, 'gone after the flash ticks');
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('shaders: defeating an enemy spawns a shockwave post effect at it, which expands and goes away', async () => {
|
|
349
|
+
const w = await open();
|
|
350
|
+
w.step(30);
|
|
351
|
+
const e = pos(w, 'enemy-1');
|
|
352
|
+
teleport(w, e.x, e.y - 40);
|
|
353
|
+
let t = 0;
|
|
354
|
+
while (w.exists('enemy-1') && t++ < 40) w.step(1);
|
|
355
|
+
w.step(1);
|
|
356
|
+
const wave = w.entity('shockwave-enemy-1').read(PostEffect);
|
|
357
|
+
assert.equal(wave.shader, 'shockwave');
|
|
358
|
+
const center = wave.uniforms.center as { x: number; y: number };
|
|
359
|
+
assert.ok(Math.abs(center.x - e.x) < 40, 'centered near the enemy');
|
|
360
|
+
const p0 = wave.uniforms.progress as number;
|
|
361
|
+
w.step(5);
|
|
362
|
+
assert.ok((w.entity('shockwave-enemy-1').read(PostEffect).uniforms.progress as number) > p0, 'expands');
|
|
363
|
+
w.step(40);
|
|
364
|
+
assert.equal(w.exists('shockwave-enemy-1'), false, 'removed at the end');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test('feel: a shot pushes the enemy in the bullet direction, within its patrol range', async () => {
|
|
368
|
+
const w = await open();
|
|
369
|
+
w.step(30);
|
|
370
|
+
const e = pos(w, 'enemy-1');
|
|
371
|
+
teleport(w, e.x - 70, GROUND_Y);
|
|
372
|
+
w.input.set('aim', [1, 0.05]);
|
|
373
|
+
w.input.press('fire');
|
|
374
|
+
let t = 0;
|
|
375
|
+
while (events(w, 'enemy.hit').length === 0 && t++ < 60) w.step(1);
|
|
376
|
+
assert.ok(w.entity('enemy-1').read(Enemy).knock > 50, 'knocked right');
|
|
377
|
+
const { left, right } = w.entity('enemy-1').read(Enemy);
|
|
378
|
+
w.step(30);
|
|
379
|
+
const x = pos(w, 'enemy-1').x;
|
|
380
|
+
assert.ok(x >= left - 3 && x <= right + 3, 'stays on its ground');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('ui: the main menu starts the game by button id (keyboard focus lands on "jogar")', async () => {
|
|
384
|
+
const w = await open('main-menu');
|
|
385
|
+
w.step(1);
|
|
386
|
+
assert.equal(w.ui.focused(), 'menu/play');
|
|
387
|
+
w.ui.click('menu/controls');
|
|
388
|
+
w.step(1);
|
|
389
|
+
assert.equal(w.entity('controls').visible, true);
|
|
390
|
+
w.ui.confirm(); // foco foi para "controles" com o clique; navegar de volta e confirmar
|
|
391
|
+
w.ui.navigate('prev');
|
|
392
|
+
w.ui.confirm();
|
|
393
|
+
w.step(2);
|
|
394
|
+
assert.equal(w.observe().scene, 'level-1');
|
|
395
|
+
assert.equal(player(w).read(Player).lives, 3);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('ui: the HUD shows lives, coins and level as state; the banner follows the level status', async () => {
|
|
399
|
+
const w = await open();
|
|
400
|
+
w.step(2);
|
|
401
|
+
assert.equal(w.entity('hud/coins').read(UiText).text, 'moedas 0');
|
|
402
|
+
assert.equal(w.entity('hud/level').read(UiText).text, 'fase 1');
|
|
403
|
+
player(w).write(Player).coins = 5;
|
|
404
|
+
player(w).write(Player).lives = 2;
|
|
405
|
+
w.step(1);
|
|
406
|
+
assert.equal(w.entity('hud/coins').read(UiText).text, 'moedas 5');
|
|
407
|
+
assert.equal(w.entity('hud/heart-3').read(UiImage).asset, 'sprites/heart-empty');
|
|
408
|
+
assert.equal(w.entity('banner').read(UiText).text, '');
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('ui: Esc pauses (world frozen, menu with focus), "continuar" resumes, "reiniciar" restarts', async () => {
|
|
412
|
+
const w = await open();
|
|
413
|
+
w.step(30);
|
|
414
|
+
w.input.press('pause');
|
|
415
|
+
w.step(1);
|
|
416
|
+
assert.equal(w.paused, true);
|
|
417
|
+
assert.equal(w.entity('pause-menu').visible, true);
|
|
418
|
+
w.step(1); // o foco entra no passo de UI do começo do tick seguinte
|
|
419
|
+
assert.equal(w.ui.focused(), 'pause-menu/resume');
|
|
420
|
+
const x = pos(w, 'enemy-1').x;
|
|
421
|
+
w.step(30);
|
|
422
|
+
assert.equal(pos(w, 'enemy-1').x, x, 'nothing moves while paused');
|
|
423
|
+
w.ui.click('pause-menu/resume');
|
|
424
|
+
w.step(1);
|
|
425
|
+
assert.equal(w.paused, false);
|
|
426
|
+
assert.equal(w.entity('pause-menu').visible, false);
|
|
427
|
+
player(w).write(Player).coins = 3;
|
|
428
|
+
w.input.press('pause');
|
|
429
|
+
w.step(1);
|
|
430
|
+
w.ui.click('pause-menu/restart');
|
|
431
|
+
w.step(2);
|
|
432
|
+
assert.equal(player(w).read(Player).coins, 0, 'restarted');
|
|
433
|
+
assert.equal(w.paused, false);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test('saves: finishing a level records progress; the main menu shows the record', async () => {
|
|
437
|
+
const saves = memorySaveStore();
|
|
438
|
+
const w = await openScene(root, { scene: 'level-1', saves });
|
|
439
|
+
w.step(30);
|
|
440
|
+
player(w).write(Player).coins = 6;
|
|
441
|
+
const flag = pos(w, 'goal');
|
|
442
|
+
teleport(w, flag.x - 20, GROUND_Y);
|
|
443
|
+
w.input.set('move', 1);
|
|
444
|
+
w.step(20);
|
|
445
|
+
assert.deepEqual(w.saves.load(Progress), { bestCoins: 6, levelReached: 2, wins: 0 });
|
|
446
|
+
assert.ok(saves.read('progress/default'), 'written to the store after the tick');
|
|
447
|
+
|
|
448
|
+
const menu = await openScene(root, { scene: 'main-menu', saves });
|
|
449
|
+
menu.step(1);
|
|
450
|
+
assert.equal(menu.entity('records').read(UiText).text, 'recorde: 6 moedas · fase 2');
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test('particles: jumping, shooting and stomping request bursts (visual, but checked headless by event)', async () => {
|
|
454
|
+
const w = await open();
|
|
455
|
+
w.step(30);
|
|
456
|
+
w.input.set('jump', true);
|
|
457
|
+
w.step(2);
|
|
458
|
+
w.input.set('jump', false);
|
|
459
|
+
w.input.set('aim', [1, 0]);
|
|
460
|
+
w.input.press('fire');
|
|
461
|
+
w.step(1);
|
|
462
|
+
const presets = () => events(w, 'particles.burst').map((e) => (e.payload as { preset: string }).preset);
|
|
463
|
+
assert.deepEqual(presets(), ['dust', 'sparks']);
|
|
464
|
+
const e = pos(w, 'enemy-1');
|
|
465
|
+
teleport(w, e.x, e.y - 40);
|
|
466
|
+
let t = 0;
|
|
467
|
+
while (w.exists('enemy-1') && t++ < 40) w.step(1);
|
|
468
|
+
assert.ok(presets().includes('explosion'));
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
test('same seed and inputs give equal snapshots (replay of a recording)', async () => {
|
|
472
|
+
const play = async (w: World) => {
|
|
473
|
+
w.input.set('move', 1);
|
|
474
|
+
w.step(40);
|
|
475
|
+
w.input.press('jump');
|
|
476
|
+
w.step(200);
|
|
477
|
+
return w;
|
|
478
|
+
};
|
|
479
|
+
const live = await play(await open('level-1', 7));
|
|
480
|
+
const replay = await open('level-1', 7);
|
|
481
|
+
replay.input.schedule(live.input.recorded());
|
|
482
|
+
replay.step(240);
|
|
483
|
+
assert.equal(replay.hash(), live.hash());
|
|
484
|
+
assert.deepEqual(replay.observe(), live.observe());
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test('vibe run --headless --json works on the template', () => {
|
|
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
|
+
const out = JSON.parse(execFileSync(process.execPath, [bin, 'run', '--headless', '--scene', 'level-1', '--frames', '60', '--entities', 'player', '--json'], { cwd: root, encoding: 'utf8' }));
|
|
490
|
+
assert.equal(out.scene, 'level-1');
|
|
491
|
+
assert.ok('Grounded' in out.entities.player && 'Transform2D' in out.entities.player);
|
|
492
|
+
});
|