@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,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monta uma fase a partir do mapa (`src/maps/*.map.ts`, `defineMap` da engine).
|
|
3
|
+
* Chão, plataformas e decoração viram um `Tilemap` (autotile pelos vizinhos);
|
|
4
|
+
* moedas, espinhos, inimigos, bandeira e player viram entidades.
|
|
5
|
+
*/
|
|
6
|
+
import type { GridMap, SceneSetupContext } from '@vibe-engine/core';
|
|
7
|
+
import { Camera2D, Collider2D, RigidBody2D, Sprite, SpriteShader, Tilemap, Transform2D, autotile, cellCenter, edges, standingY, tilemapFromGrid } from '@vibe-engine/2d';
|
|
8
|
+
import { Player } from '../components/player.component.ts';
|
|
9
|
+
import { Enemy } from '../components/enemy.component.ts';
|
|
10
|
+
import { Coin, Goal, Hazard } from '../components/pickup.component.ts';
|
|
11
|
+
import { Level } from '../components/level.component.ts';
|
|
12
|
+
import { Gun } from '../components/gun.component.ts';
|
|
13
|
+
import { banner, hud } from '../ui/hud.ui.ts';
|
|
14
|
+
import { pauseMenu } from '../ui/pause-menu.ui.ts';
|
|
15
|
+
|
|
16
|
+
export const TILE = 18;
|
|
17
|
+
/** Quanto o inimigo anda para cada lado a partir de onde nasceu, no máximo (em tiles). */
|
|
18
|
+
const PATROL_RANGE = 4;
|
|
19
|
+
const SOLID = ['ground', 'plank'];
|
|
20
|
+
|
|
21
|
+
export interface LevelParams {
|
|
22
|
+
lives: number;
|
|
23
|
+
coins: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function buildLevel({ spawn }: SceneSetupContext, map: GridMap, level: number, params: Partial<LevelParams> = {}): void {
|
|
27
|
+
// Frames da folha `sprites/tiles` (Kenney Pixel Platformer, 18 px).
|
|
28
|
+
spawn('level-map', [Transform2D({ x: 0, y: 0 }), Tilemap(tilemapFromGrid(map, {
|
|
29
|
+
tileset: 'sprites/tiles',
|
|
30
|
+
tileWidth: TILE,
|
|
31
|
+
layers: {
|
|
32
|
+
ground: {
|
|
33
|
+
match: 'ground', collides: true,
|
|
34
|
+
tiles: autotile({
|
|
35
|
+
alone: { single: 0, left: 1, mid: 2, right: 3 }, // chão de uma linha só
|
|
36
|
+
top: { single: 20, left: 21, mid: 22, right: 23 }, // grama com terra embaixo
|
|
37
|
+
middle: { single: 120, left: 121, mid: 122, right: 123 },
|
|
38
|
+
bottom: { single: 140, left: 141, mid: 142, right: 143 },
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
planks: { match: 'plank', collides: true, tiles: edges({ single: 47, left: 48, mid: 49, right: 50 }) },
|
|
42
|
+
decor: { match: ['grass', 'bush', 'tree', 'mushroom'], tiles: { grass: 124, bush: 125, tree: 126, mushroom: 128 } },
|
|
43
|
+
},
|
|
44
|
+
}))]);
|
|
45
|
+
|
|
46
|
+
map.cells('coin').forEach((cell, i) => {
|
|
47
|
+
spawn(`coin-${i + 1}`, [Transform2D(cellCenter(cell, TILE)), Sprite({ asset: 'sprites/tiles', animation: 'coin', layer: 1 }), Collider2D.circle({ radius: 6, trigger: true }), Coin()]);
|
|
48
|
+
});
|
|
49
|
+
for (const cell of map.cells('spikes')) {
|
|
50
|
+
spawn(`spikes-${cell.y}-${cell.x}`, [Transform2D(cellCenter(cell, TILE)), Sprite({ asset: 'sprites/tiles', frame: 68, layer: 1 }), Collider2D.box({ width: 14, height: 6, offset: { x: 0, y: 5 }, trigger: true }), Hazard()]);
|
|
51
|
+
}
|
|
52
|
+
for (const cell of map.cells('flag')) {
|
|
53
|
+
spawn('goal', [Transform2D(cellCenter(cell, TILE)), Sprite({ asset: 'sprites/tiles', animation: 'flag', layer: 1 }), Collider2D.box({ width: 8, height: 18, trigger: true }), Goal()]);
|
|
54
|
+
}
|
|
55
|
+
map.cells('enemy').forEach((cell, i) => {
|
|
56
|
+
// Patrulha o trecho de chão embaixo, sem atravessar parede nem sair da borda.
|
|
57
|
+
let lo = cell.x;
|
|
58
|
+
let hi = cell.x;
|
|
59
|
+
while (lo > cell.x - PATROL_RANGE && map.is(lo - 1, cell.y + 1, SOLID) && !map.is(lo - 1, cell.y, SOLID)) lo--;
|
|
60
|
+
while (hi < cell.x + PATROL_RANGE && map.is(hi + 1, cell.y + 1, SOLID) && !map.is(hi + 1, cell.y, SOLID)) hi++;
|
|
61
|
+
spawn(`enemy-${i + 1}`, [
|
|
62
|
+
Transform2D({ x: cellCenter(cell, TILE).x, y: standingY(cell, TILE, 24) }),
|
|
63
|
+
Sprite({ asset: 'sprites/characters', animation: 'enemy-walk', layer: 2 }),
|
|
64
|
+
SpriteShader({ shader: 'flash' }), // clarão ao levar tiro: enemy.patrol escreve uniforms.amount
|
|
65
|
+
RigidBody2D({ type: 'kinematic' }),
|
|
66
|
+
Collider2D.box({ width: 16, height: 12, offset: { x: 0, y: 6 }, trigger: true }),
|
|
67
|
+
Enemy({ left: lo * TILE + 8, right: (hi + 1) * TILE - 8 }),
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const start = map.cells('player')[0]!; // `exactly: { P: 1 }` garante um
|
|
72
|
+
const spawnAt = { x: cellCenter(start, TILE).x, y: standingY(start, TILE, 24) };
|
|
73
|
+
spawn('player', [
|
|
74
|
+
Transform2D(spawnAt),
|
|
75
|
+
Sprite({ asset: 'sprites/characters', animation: 'player-idle', layer: 3 }),
|
|
76
|
+
SpriteShader({ shader: 'flash' }), // clarão de dano: player.damage escreve uniforms.amount
|
|
77
|
+
RigidBody2D({ ccd: true }),
|
|
78
|
+
// A bolha do capacete fica fora da caixa: colide o corpo, não o vidro.
|
|
79
|
+
Collider2D.box({ width: 14, height: 18, offset: { x: 0, y: 3 }, friction: 0 }),
|
|
80
|
+
Player({ spawn: spawnAt, lives: params.lives ?? 3, coins: params.coins ?? 0 }),
|
|
81
|
+
]);
|
|
82
|
+
spawn('gun', [Transform2D(spawnAt), Sprite({ asset: 'sprites/pistol', layer: 4, anchor: { x: 0.25, y: 0.5 } }), Gun({ owner: 'player' })]);
|
|
83
|
+
const size = { width: map.width * TILE, height: map.height * TILE };
|
|
84
|
+
spawn('level', [Level({ number: level, ...size, coinsTotal: map.cells('coin').length })]);
|
|
85
|
+
spawn('camera', [Camera2D({ follow: 'player', zoom: 3, deadzone: { x: 12, y: 24 }, smoothing: 0.12, lookahead: { x: 28, y: 0 }, bounds: { x: 0, y: 0, ...size } })]);
|
|
86
|
+
spawn('hud', hud());
|
|
87
|
+
spawn('banner', banner());
|
|
88
|
+
spawn('pause-menu', pauseMenu(), { hidden: true });
|
|
89
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PostEffect, defineListener } from '@vibe-engine/core';
|
|
2
|
+
import { CameraShake, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { Shockwave } from '../components/shockwave.component.ts';
|
|
4
|
+
import { EnemyDefeated, EnemyHit, PlayerHurt, PlayerLanded, ShotFired } from '../events/gameplay.events.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Game feel dos impactos: tremor de tela (visual), hit-stop (a simulação para
|
|
8
|
+
* alguns ticks, igual no replay) e onda de choque ao derrotar inimigo (uma entidade
|
|
9
|
+
* com PostEffect `shockwave`, que `effects.shockwave` expande e apaga). Ajuste os números aqui.
|
|
10
|
+
*/
|
|
11
|
+
export const Feedback = defineListener('juice.feedback', (on) => {
|
|
12
|
+
on(ShotFired, (_e, { emit }) => emit(CameraShake, { amount: 0.6, seconds: 0.06 }));
|
|
13
|
+
on(EnemyHit, (_e, { emit, hitStop }) => { emit(CameraShake, { amount: 1, seconds: 0.08 }); hitStop(1); });
|
|
14
|
+
on(EnemyDefeated, (e, { emit, hitStop, world }) => {
|
|
15
|
+
emit(CameraShake, { amount: 2.5, seconds: 0.18 });
|
|
16
|
+
hitStop(4);
|
|
17
|
+
const at = world.exists(e.enemy) ? world.entity(e.enemy).read(Transform2D) : null;
|
|
18
|
+
if (at) world.spawn(`shockwave-${e.enemy}`, [Shockwave(), PostEffect({ shader: 'shockwave', uniforms: { center: { x: at.x, y: at.y }, progress: 0, radius: 40, width: 8, strength: 3 } })]);
|
|
19
|
+
});
|
|
20
|
+
on(PlayerHurt, (_e, { emit, hitStop }) => { emit(CameraShake, { amount: 3.5, seconds: 0.3 }); hitStop(5); });
|
|
21
|
+
on(PlayerLanded, (e, { emit }) => { if (e.airTicks > 40) emit(CameraShake, { amount: 1.2, seconds: 0.1 }); });
|
|
22
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineListener, type World } from '@vibe-engine/core';
|
|
2
|
+
import { ParticleBurst, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { BulletImpact, CoinCollected, EnemyDefeated, EnemyHit, PlayerJumped, PlayerLanded, ShotFired } from '../events/gameplay.events.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Partículas dos acontecimentos (visuais; o pedido fica no log de eventos).
|
|
7
|
+
* Listeners rodam antes do despawn do fim do stage: moeda e inimigo ainda existem aqui.
|
|
8
|
+
*/
|
|
9
|
+
export const ParticleEffects = defineListener('effects.particles', (on) => {
|
|
10
|
+
const pos = (world: World, id: string) => (world.exists(id) ? world.entity(id).read(Transform2D) : null);
|
|
11
|
+
on(PlayerJumped, (_e, { world, emit }) => { const p = pos(world, 'player'); if (p) emit(ParticleBurst, { x: p.x, y: p.y + 12, preset: 'dust' }); });
|
|
12
|
+
on(PlayerLanded, (e, { world, emit }) => { const p = pos(world, 'player'); if (p) emit(ParticleBurst, { x: p.x, y: p.y + 12, preset: 'dust', config: { count: e.airTicks > 40 ? 12 : 6 } }); });
|
|
13
|
+
on(CoinCollected, (e, { world, emit }) => { const c = pos(world, e.coin); if (c) emit(ParticleBurst, { x: c.x, y: c.y, preset: 'coin' }); });
|
|
14
|
+
on(EnemyHit, (e, { world, emit }) => { const p = pos(world, e.enemy); if (p) emit(ParticleBurst, { x: p.x, y: p.y + 4, preset: 'sparks' }); });
|
|
15
|
+
on(EnemyDefeated, (e, { world, emit }) => { const p = pos(world, e.enemy); if (p) emit(ParticleBurst, { x: p.x, y: p.y + 4, preset: 'explosion' }); });
|
|
16
|
+
on(BulletImpact, (e, { emit }) => emit(ParticleBurst, { x: e.x, y: e.y, preset: 'sparks', config: { count: 6 } }));
|
|
17
|
+
on(ShotFired, (e, { world, emit }) => {
|
|
18
|
+
const g = pos(world, 'gun');
|
|
19
|
+
if (g) emit(ParticleBurst, { x: g.x + e.dir.x * 10, y: g.y + e.dir.y * 10, preset: 'sparks', config: { count: 4, angle: [-25, 25], speed: [60, 120], gravity: 0 }, angle: (Math.atan2(e.dir.y, e.dir.x) * 180) / Math.PI });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineListener } from '@vibe-engine/core';
|
|
2
|
+
import { LevelCompleted, PlayerHurt } from '../events/gameplay.events.ts';
|
|
3
|
+
import { Progress } from '../saves/progress.save.ts';
|
|
4
|
+
import { Player } from '../components/player.component.ts';
|
|
5
|
+
|
|
6
|
+
/** Grava recordes quando algo marcante acontece (fim de fase, game over). */
|
|
7
|
+
export const ProgressRecords = defineListener('progress.records', (on) => {
|
|
8
|
+
on(LevelCompleted, (e, { saves, scene }) => saves.update(Progress, 'default', (p) => {
|
|
9
|
+
p.bestCoins = Math.max(p.bestCoins, e.coins);
|
|
10
|
+
p.levelReached = Math.max(p.levelReached, scene.next ? e.level + 1 : e.level);
|
|
11
|
+
if (!scene.next) p.wins++;
|
|
12
|
+
}));
|
|
13
|
+
on(PlayerHurt, (e, { saves, world }) => {
|
|
14
|
+
if (e.livesLeft > 0) return;
|
|
15
|
+
const coins = world.entity('player').read(Player).coins;
|
|
16
|
+
saves.update(Progress, 'default', (p) => { p.bestCoins = Math.max(p.bestCoins, coins); });
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineListener } from '@vibe-engine/core';
|
|
2
|
+
import { CoinCollected, EnemyDefeated, EnemyHit, LevelCompleted, PlayerHurt, PlayerJumped, ShotFired } from '../events/gameplay.events.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Som de cada acontecimento do jogo. As regras só emitem eventos; quem decide
|
|
6
|
+
* o som é este listener. Variação de pitch vem do `random` (determinístico).
|
|
7
|
+
*/
|
|
8
|
+
export const SoundEffects = defineListener('audio.sfx', (on) => {
|
|
9
|
+
on(PlayerJumped, (_e, { audio, random }) => audio.play('audio/jump', { volume: 0.6, pitch: 0.95 + random.float() * 0.1 }));
|
|
10
|
+
on(CoinCollected, (_e, { audio }) => audio.play('audio/coin', { volume: 0.7 }));
|
|
11
|
+
on(ShotFired, (_e, { audio, random }) => audio.play('audio/shoot', { volume: 0.4, pitch: 0.9 + random.float() * 0.2 }));
|
|
12
|
+
on(EnemyHit, (_e, { audio }) => audio.play('audio/enemy-hit', { volume: 0.6 }));
|
|
13
|
+
on(EnemyDefeated, (e, { audio }) => audio.play(e.how === 'stomp' ? 'audio/stomp' : 'audio/enemy-defeat', { volume: 0.7 }));
|
|
14
|
+
on(PlayerHurt, (e, { audio }) => audio.play(e.livesLeft <= 0 ? 'audio/game-over' : 'audio/hurt', { volume: 0.8 }));
|
|
15
|
+
on(LevelCompleted, (_e, { audio }) => audio.play('audio/level-complete', { volume: 0.8 }));
|
|
16
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Legenda e regras comuns às fases (lista compartilhada, sem sufixo). */
|
|
2
|
+
export const platformerLegend = {
|
|
3
|
+
legend: {
|
|
4
|
+
'#': 'ground', '=': 'plank', P: 'player', o: 'coin', e: 'enemy', '^': 'spikes', F: 'flag',
|
|
5
|
+
g: 'grass', b: 'bush', t: 'tree', m: 'mushroom',
|
|
6
|
+
},
|
|
7
|
+
needsBelow: { P: ['ground', 'plank'], e: ['ground', 'plank'], '^': ['ground', 'plank'], F: ['ground', 'plank'] },
|
|
8
|
+
exactly: { P: 1, F: 1 },
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineMap } from '@vibe-engine/core';
|
|
2
|
+
import { platformerLegend } from './legend.ts';
|
|
3
|
+
|
|
4
|
+
/** Fase 1. Edite o desenho; `vibe map show level-1` mostra com coordenadas e `vibe check` valida. */
|
|
5
|
+
export default defineMap('level-1', {
|
|
6
|
+
...platformerLegend,
|
|
7
|
+
// prettier-ignore
|
|
8
|
+
rows: [
|
|
9
|
+
'............................................................',
|
|
10
|
+
'............................................................',
|
|
11
|
+
'............................................................',
|
|
12
|
+
'............................................................',
|
|
13
|
+
'...........................ooo..............................',
|
|
14
|
+
'..........................=====.............................',
|
|
15
|
+
'...........ooo..............................o.o.o...........',
|
|
16
|
+
'..........=====.......====.................=======..........',
|
|
17
|
+
'............................................................',
|
|
18
|
+
'..P...g.o.o........o.o.........e......^^.....b.....t.....F..',
|
|
19
|
+
'###################...###################...################',
|
|
20
|
+
'###################...###################...################',
|
|
21
|
+
],
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineMap } from '@vibe-engine/core';
|
|
2
|
+
import { platformerLegend } from './legend.ts';
|
|
3
|
+
|
|
4
|
+
/** Fase 2. Edite o desenho; `vibe map show level-2` mostra com coordenadas e `vibe check` valida. */
|
|
5
|
+
export default defineMap('level-2', {
|
|
6
|
+
...platformerLegend,
|
|
7
|
+
// prettier-ignore
|
|
8
|
+
rows: [
|
|
9
|
+
'............................................................',
|
|
10
|
+
'............................................................',
|
|
11
|
+
'............................................................',
|
|
12
|
+
'.......................................ooo..................',
|
|
13
|
+
'......................................=====.................',
|
|
14
|
+
'............................................................',
|
|
15
|
+
'...........o.o.........ooo........................o.o.......',
|
|
16
|
+
'..........=====.......=====.......===............=====......',
|
|
17
|
+
'......................................................##....',
|
|
18
|
+
'..P..m......e.......^....e...........o.......^....e...##.F..',
|
|
19
|
+
'##############...###########...##########...################',
|
|
20
|
+
'##############...###########...##########...################',
|
|
21
|
+
],
|
|
22
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineSave, t } from '@vibe-engine/core';
|
|
2
|
+
|
|
3
|
+
/** Recordes do jogador. Mudou o formato? Suba `version` e escreva a migração. */
|
|
4
|
+
export const Progress = defineSave('progress', {
|
|
5
|
+
version: 1,
|
|
6
|
+
schema: {
|
|
7
|
+
bestCoins: t.int({ min: 0, doc: 'mais moedas numa partida' }),
|
|
8
|
+
levelReached: t.int({ default: 1, min: 1, doc: 'fase mais alta alcançada' }),
|
|
9
|
+
wins: t.int({ min: 0 }),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineScene } from '@vibe-engine/core';
|
|
2
|
+
import { buildLevel, type LevelParams } from '../level/build.ts';
|
|
3
|
+
import map from '../maps/level-1.map.ts';
|
|
4
|
+
import { gameplay } from '../systems/gameplay.ts';
|
|
5
|
+
import { SoundEffects } from '../listeners/sound-effects.listener.ts';
|
|
6
|
+
import { Feedback } from '../listeners/feedback.listener.ts';
|
|
7
|
+
import { ProgressRecords } from '../listeners/progress.listener.ts';
|
|
8
|
+
import { ParticleEffects } from '../listeners/particles.listener.ts';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export default defineScene({
|
|
12
|
+
systems: gameplay,
|
|
13
|
+
listeners: [SoundEffects, Feedback, ProgressRecords, ParticleEffects],
|
|
14
|
+
music: 'audio/music-theme',
|
|
15
|
+
next: 'level-2',
|
|
16
|
+
setup: (ctx) => buildLevel(ctx, map, 1, ctx.params as Partial<LevelParams> | undefined),
|
|
17
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineScene } from '@vibe-engine/core';
|
|
2
|
+
import { buildLevel, type LevelParams } from '../level/build.ts';
|
|
3
|
+
import map from '../maps/level-2.map.ts';
|
|
4
|
+
import { gameplay } from '../systems/gameplay.ts';
|
|
5
|
+
import { SoundEffects } from '../listeners/sound-effects.listener.ts';
|
|
6
|
+
import { Feedback } from '../listeners/feedback.listener.ts';
|
|
7
|
+
import { ProgressRecords } from '../listeners/progress.listener.ts';
|
|
8
|
+
import { ParticleEffects } from '../listeners/particles.listener.ts';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export default defineScene({
|
|
12
|
+
systems: gameplay,
|
|
13
|
+
listeners: [SoundEffects, Feedback, ProgressRecords, ParticleEffects],
|
|
14
|
+
music: 'audio/music-theme',
|
|
15
|
+
setup: (ctx) => buildLevel(ctx, map, 2, ctx.params as Partial<LevelParams> | undefined),
|
|
16
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { UiAnchor, UiClicked, UiStyle, UiText, defineScene, defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { mainMenu } from '../ui/main-menu.ui.ts';
|
|
3
|
+
import { Progress } from '../saves/progress.save.ts';
|
|
4
|
+
|
|
5
|
+
const MenuActions = defineSystem('menu.actions', {
|
|
6
|
+
stage: 'update',
|
|
7
|
+
reads: [UiClicked],
|
|
8
|
+
update({ events, world, scene }) {
|
|
9
|
+
for (const { entity } of events.read(UiClicked)) {
|
|
10
|
+
if (entity === 'menu/play') scene.go('level-1', { params: { lives: 3, coins: 0 } });
|
|
11
|
+
if (entity === 'menu/controls') {
|
|
12
|
+
const help = world.entity('controls');
|
|
13
|
+
if (help.visible) help.hide(); else help.show();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default defineScene({
|
|
20
|
+
systems: [MenuActions],
|
|
21
|
+
music: 'audio/music-theme',
|
|
22
|
+
setup({ spawn, saves }) {
|
|
23
|
+
const progress = saves.load(Progress);
|
|
24
|
+
spawn('title', [UiAnchor({ corner: 'top', margin: 90 }), UiText({ text: 'platformer 2d', size: 72 }), UiStyle({ use: 'title' })]);
|
|
25
|
+
spawn('subtitle', [UiAnchor({ corner: 'top', margin: 150 }), UiText({ text: 'feito com vibe-engine' }), UiStyle({ use: 'muted' })]);
|
|
26
|
+
spawn('menu', mainMenu());
|
|
27
|
+
if (saves.exists(Progress)) {
|
|
28
|
+
spawn('records', [UiAnchor({ corner: 'top', margin: 180 }), UiStyle({ use: 'muted' }), UiText({ text: `recorde: ${progress.bestCoins} moedas · fase ${progress.levelReached}${progress.wins ? ` · ${progress.wins} vitória${progress.wins > 1 ? 's' : ''}` : ''}` })]);
|
|
29
|
+
}
|
|
30
|
+
spawn('controls', [
|
|
31
|
+
UiAnchor({ corner: 'bottom', margin: 40 }),
|
|
32
|
+
UiStyle({ use: 'panel muted' }),
|
|
33
|
+
UiText({ text: 'A D ou ← → andar · espaço pular (segure para ir mais alto)\nmouse mira e atira · pise ou atire nos inimigos · Esc pausa' }),
|
|
34
|
+
], { hidden: true });
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { RigidBody2D, Tilemap, Transform2D, TriggerEnter, pairWith } from '@vibe-engine/2d';
|
|
3
|
+
import { Player } from '../components/player.component.ts';
|
|
4
|
+
import { Enemy } from '../components/enemy.component.ts';
|
|
5
|
+
import { Coin, Goal, Hazard } from '../components/pickup.component.ts';
|
|
6
|
+
import { Level } from '../components/level.component.ts';
|
|
7
|
+
import { Bullet } from '../components/gun.component.ts';
|
|
8
|
+
import { BulletImpact, CoinCollected, EnemyDefeated, EnemyHit, LevelCompleted, PlayerHurt } from '../events/gameplay.events.ts';
|
|
9
|
+
|
|
10
|
+
/** O que acontece quando algo encosta: player × moeda/inimigo/espinho/bandeira, bala × inimigo/parede. */
|
|
11
|
+
export const Contacts = defineSystem('gameplay.contacts', {
|
|
12
|
+
stage: 'postPhysics',
|
|
13
|
+
reads: [TriggerEnter],
|
|
14
|
+
update({ world, events, emit, scene }) {
|
|
15
|
+
for (const hit of events.read(TriggerEnter)) {
|
|
16
|
+
const shot = pairWith(world, hit, Bullet);
|
|
17
|
+
if (shot) {
|
|
18
|
+
const [bullet, target] = shot;
|
|
19
|
+
if (!world.exists(bullet.id) || !world.exists(target.id)) continue;
|
|
20
|
+
if (target.has(Enemy)) {
|
|
21
|
+
const en = target.write(Enemy);
|
|
22
|
+
en.hp = Math.max(0, en.hp - bullet.read(Bullet).damage);
|
|
23
|
+
en.flash = 12;
|
|
24
|
+
en.knock = Math.sign(bullet.read(RigidBody2D).velocity.x) * 150;
|
|
25
|
+
world.despawn(bullet.id);
|
|
26
|
+
if (en.hp === 0) {
|
|
27
|
+
world.despawn(target.id);
|
|
28
|
+
emit(EnemyDefeated, { enemy: target.id, how: 'shot' });
|
|
29
|
+
} else {
|
|
30
|
+
emit(EnemyHit, { enemy: target.id, hpLeft: en.hp });
|
|
31
|
+
}
|
|
32
|
+
} else if (target.has(Tilemap)) {
|
|
33
|
+
const at = bullet.read(Transform2D);
|
|
34
|
+
emit(BulletImpact, { x: at.x, y: at.y });
|
|
35
|
+
world.despawn(bullet.id); // bateu no chão ou numa plataforma
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const pair = pairWith(world, hit, Player);
|
|
40
|
+
if (!pair) continue;
|
|
41
|
+
const [player, other] = pair;
|
|
42
|
+
if (!world.exists(other.id)) continue; // já tratado neste tick
|
|
43
|
+
|
|
44
|
+
if (other.has(Coin)) {
|
|
45
|
+
const p = player.write(Player);
|
|
46
|
+
p.coins++;
|
|
47
|
+
world.despawn(other.id);
|
|
48
|
+
emit(CoinCollected, { coin: other.id, total: p.coins });
|
|
49
|
+
} else if (other.has(Enemy)) {
|
|
50
|
+
// Caindo e acima do inimigo: pisou. Senão, o inimigo machuca.
|
|
51
|
+
const body = player.write(RigidBody2D);
|
|
52
|
+
if (body.velocity.y > 0 && player.read(Transform2D).y < other.read(Transform2D).y) {
|
|
53
|
+
body.velocity.y = -player.read(Player).jump * 0.6;
|
|
54
|
+
world.despawn(other.id);
|
|
55
|
+
emit(EnemyDefeated, { enemy: other.id, how: 'stomp' });
|
|
56
|
+
} else {
|
|
57
|
+
emit(PlayerHurt, { by: other.id, livesLeft: player.read(Player).lives - 1 });
|
|
58
|
+
}
|
|
59
|
+
} else if (other.has(Hazard)) {
|
|
60
|
+
emit(PlayerHurt, { by: other.id, livesLeft: player.read(Player).lives - 1 });
|
|
61
|
+
} else if (other.has(Goal)) {
|
|
62
|
+
const level = world.entity('level').write(Level);
|
|
63
|
+
if (level.status !== 'playing') continue;
|
|
64
|
+
const p = player.write(Player);
|
|
65
|
+
p.frozen = true;
|
|
66
|
+
level.status = scene.next ? 'completed' : 'won';
|
|
67
|
+
emit(LevelCompleted, { level: level.number, coins: p.coins });
|
|
68
|
+
// Vidas e moedas seguem para a próxima fase pelos params da cena (resources chegam com a #55).
|
|
69
|
+
if (scene.next) scene.go(scene.next, { params: { lives: p.lives, coins: p.coins }, delay: { seconds: 1.5 } });
|
|
70
|
+
else scene.go('main-menu', { delay: { seconds: 3 } });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { RigidBody2D, Sprite, SpriteShader, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { Enemy } from '../components/enemy.component.ts';
|
|
4
|
+
|
|
5
|
+
/** Anda até a borda do trecho e volta. */
|
|
6
|
+
export const EnemyPatrol = defineSystem('enemy.patrol', {
|
|
7
|
+
query: [Enemy, Transform2D, RigidBody2D, Sprite],
|
|
8
|
+
optional: [SpriteShader],
|
|
9
|
+
update({ entities }) {
|
|
10
|
+
for (const e of entities) {
|
|
11
|
+
const en = e.write(Enemy);
|
|
12
|
+
const x = e.read(Transform2D).x;
|
|
13
|
+
if (x <= en.left) en.dir = 1;
|
|
14
|
+
if (x >= en.right) en.dir = -1;
|
|
15
|
+
// Empurrão do tiro, sem sair do trecho de patrulha (inimigo cinemático não cai da borda).
|
|
16
|
+
if ((x <= en.left && en.knock < 0) || (x >= en.right && en.knock > 0)) en.knock = 0;
|
|
17
|
+
en.knock *= 0.82;
|
|
18
|
+
if (Math.abs(en.knock) < 1) en.knock = 0;
|
|
19
|
+
e.write(RigidBody2D).velocity.x = en.dir * en.speed + en.knock;
|
|
20
|
+
const sprite = e.write(Sprite);
|
|
21
|
+
sprite.flipX = en.dir > 0;
|
|
22
|
+
if (en.flash > 0) en.flash--;
|
|
23
|
+
// Clarão branco ao levar tiro (shader `flash`), apagando em 12 ticks.
|
|
24
|
+
if (e.has(SpriteShader)) e.write(SpriteShader).uniforms.amount = en.flash / 12;
|
|
25
|
+
else sprite.alpha = en.flash > 0 && en.flash % 4 < 2 ? 0.3 : 1;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lista compartilhada: as duas fases rodam as mesmas regras. Não define nada
|
|
3
|
+
* (por isso não tem sufixo); cada cena faz `systems: gameplay`. A ordem da
|
|
4
|
+
* lista é a ordem de execução dentro de cada stage. Uma fase com regra a mais
|
|
5
|
+
* faz `systems: [...gameplay, BossFight]`.
|
|
6
|
+
*/
|
|
7
|
+
import { PlayerController } from './player-controller.system.ts';
|
|
8
|
+
import { EnemyPatrol } from './enemy-patrol.system.ts';
|
|
9
|
+
import { Contacts } from './contacts.system.ts';
|
|
10
|
+
import { PlayerDamage } from './player-damage.system.ts';
|
|
11
|
+
import { BulletLifetime, GunControl } from './gun.system.ts';
|
|
12
|
+
import { PlayerJuice } from './player-juice.system.ts';
|
|
13
|
+
import { Hud } from './hud.system.ts';
|
|
14
|
+
import { Pause } from './pause.system.ts';
|
|
15
|
+
import { ShockwaveFade } from './shockwave.system.ts';
|
|
16
|
+
|
|
17
|
+
export const gameplay = [PlayerController, PlayerJuice, GunControl, BulletLifetime, EnemyPatrol, Contacts, PlayerDamage, ShockwaveFade, Hud, Pause];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Collider2D, Grounded, RigidBody2D, Sprite, Transform2D } from '@vibe-engine/2d';
|
|
3
|
+
import { Player } from '../components/player.component.ts';
|
|
4
|
+
import { Bullet, Gun } from '../components/gun.component.ts';
|
|
5
|
+
import { ShotFired } from '../events/gameplay.events.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mira e tiro. A arma acompanha o player e aponta para `aim`; o player olha
|
|
9
|
+
* para onde mira. Segurar `fire` dispara a cada `rate` ticks.
|
|
10
|
+
*/
|
|
11
|
+
export const GunControl = defineSystem('gun.control', {
|
|
12
|
+
after: ['player.controller'],
|
|
13
|
+
query: [Gun, Transform2D],
|
|
14
|
+
update({ entities, world, input, emit }) {
|
|
15
|
+
for (const g of entities) {
|
|
16
|
+
const gun = g.write(Gun);
|
|
17
|
+
if (!gun.owner || !world.exists(gun.owner)) continue;
|
|
18
|
+
const owner = world.entity(gun.owner);
|
|
19
|
+
const [ax, ay] = input.vector('aim');
|
|
20
|
+
const len = Math.hypot(ax, ay);
|
|
21
|
+
if (len > 0) gun.aim = { x: ax / len, y: ay / len };
|
|
22
|
+
const dir = gun.aim;
|
|
23
|
+
const p = owner.read(Transform2D);
|
|
24
|
+
owner.write(Sprite).flipX = dir.x < 0;
|
|
25
|
+
|
|
26
|
+
const t = g.write(Transform2D);
|
|
27
|
+
gun.kick *= 0.6;
|
|
28
|
+
if (gun.kick < 0.1) gun.kick = 0;
|
|
29
|
+
t.x = p.x + dir.x * (4 - gun.kick);
|
|
30
|
+
t.y = p.y + 5 + dir.y * (4 - gun.kick);
|
|
31
|
+
t.rotation = Math.atan2(dir.y, dir.x);
|
|
32
|
+
t.scaleY = dir.x < 0 ? -1 : 1; // mirando para a esquerda, a arma não fica de cabeça para baixo
|
|
33
|
+
|
|
34
|
+
if (gun.cooldown > 0) gun.cooldown--;
|
|
35
|
+
if (!input.down('fire') || gun.cooldown > 0 || owner.read(Player).frozen) continue;
|
|
36
|
+
gun.cooldown = gun.rate;
|
|
37
|
+
gun.shots++;
|
|
38
|
+
// Recoil: coice visual + empurrão no player (no ar, atirar para baixo dá um impulso para cima).
|
|
39
|
+
gun.kick = 3;
|
|
40
|
+
const body = owner.write(RigidBody2D);
|
|
41
|
+
body.velocity.x -= dir.x * gun.recoil;
|
|
42
|
+
if (!owner.has(Grounded)) body.velocity.y -= dir.y * gun.recoil * 0.6;
|
|
43
|
+
const id = `bullet-${gun.shots}`;
|
|
44
|
+
world.spawn(id, [
|
|
45
|
+
Transform2D({ x: t.x + dir.x * 10, y: t.y + dir.y * 10 }),
|
|
46
|
+
Sprite({ asset: 'sprites/bullet', layer: 4 }),
|
|
47
|
+
RigidBody2D({ type: 'kinematic', velocity: { x: dir.x * gun.bulletSpeed, y: dir.y * gun.bulletSpeed } }),
|
|
48
|
+
Collider2D.circle({ radius: 2, trigger: true }),
|
|
49
|
+
Bullet(),
|
|
50
|
+
]);
|
|
51
|
+
emit(ShotFired, { bullet: id, dir: { x: dir.x, y: dir.y } });
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Bala some depois de `ttl` ticks (as que acertam somem antes, em gameplay.contacts). */
|
|
57
|
+
export const BulletLifetime = defineSystem('gun.bullet-lifetime', {
|
|
58
|
+
query: [Bullet],
|
|
59
|
+
update({ entities, world }) {
|
|
60
|
+
for (const e of entities) {
|
|
61
|
+
const b = e.write(Bullet);
|
|
62
|
+
if (--b.ttl <= 0) world.despawn(e.id);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { UiImage, UiText, defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Player } from '../components/player.component.ts';
|
|
3
|
+
import { Level } from '../components/level.component.ts';
|
|
4
|
+
|
|
5
|
+
const BANNER = { playing: '', completed: 'fase concluída', won: 'você venceu!', 'game-over': 'game over' };
|
|
6
|
+
|
|
7
|
+
/** Escreve o estado do jogo na UI (o texto exibido é estado: testes conferem sem tela). */
|
|
8
|
+
export const Hud = defineSystem('ui.hud', {
|
|
9
|
+
stage: 'update',
|
|
10
|
+
update({ world }) {
|
|
11
|
+
if (!world.exists('player') || !world.exists('level') || !world.exists('hud')) return;
|
|
12
|
+
const p = world.entity('player').read(Player);
|
|
13
|
+
const level = world.entity('level').read(Level);
|
|
14
|
+
const set = (id: string, text: string) => { if (world.entity(id).read(UiText).text !== text) world.entity(id).write(UiText).text = text; };
|
|
15
|
+
for (let i = 1; i <= 3; i++) {
|
|
16
|
+
const asset = i <= p.lives ? 'sprites/heart' : 'sprites/heart-empty';
|
|
17
|
+
if (world.entity(`hud/heart-${i}`).read(UiImage).asset !== asset) world.entity(`hud/heart-${i}`).write(UiImage).asset = asset;
|
|
18
|
+
}
|
|
19
|
+
set('hud/coins', `moedas ${p.coins}`);
|
|
20
|
+
set('hud/level', `fase ${level.number}`);
|
|
21
|
+
set('banner', BANNER[level.status]);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UiClicked, defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Level } from '../components/level.component.ts';
|
|
3
|
+
|
|
4
|
+
/** Esc/P pausa e abre o menu; os botões do menu continuam, reiniciam ou voltam ao menu principal. */
|
|
5
|
+
export const Pause = defineSystem('game.pause', {
|
|
6
|
+
stage: 'update', // roda com o jogo pausado
|
|
7
|
+
reads: [UiClicked],
|
|
8
|
+
update({ world, input, events, scene }) {
|
|
9
|
+
const menu = world.entity('pause-menu');
|
|
10
|
+
const playing = world.entity('level').read(Level).status === 'playing';
|
|
11
|
+
const close = () => { world.resume(); menu.hide(); };
|
|
12
|
+
if (input.pressed('pause') && playing) {
|
|
13
|
+
if (world.paused) close();
|
|
14
|
+
else { world.pause(); menu.show(); }
|
|
15
|
+
}
|
|
16
|
+
for (const { entity } of events.read(UiClicked)) {
|
|
17
|
+
if (entity === 'pause-menu/resume') close();
|
|
18
|
+
if (entity === 'pause-menu/restart') scene.restart();
|
|
19
|
+
if (entity === 'pause-menu/menu') scene.go('main-menu');
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineSystem } from '@vibe-engine/core';
|
|
2
|
+
import { Grounded, RigidBody2D, Sprite } from '@vibe-engine/2d';
|
|
3
|
+
import { Player } from '../components/player.component.ts';
|
|
4
|
+
import { PlayerJumped } from '../events/gameplay.events.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Input → velocidade, com as técnicas de game feel de platformer:
|
|
8
|
+
* aceleração (chão e ar), coyote time, jump buffer, pulo variável e queda mais
|
|
9
|
+
* pesada. Também escolhe o frame do sprite (para onde olha vem da mira, em gun.control).
|
|
10
|
+
*/
|
|
11
|
+
export const PlayerController = defineSystem('player.controller', {
|
|
12
|
+
query: [Player, RigidBody2D, Sprite],
|
|
13
|
+
optional: [Grounded],
|
|
14
|
+
update({ entities, input, emit, time }) {
|
|
15
|
+
for (const e of entities) {
|
|
16
|
+
const p = e.write(Player);
|
|
17
|
+
const body = e.write(RigidBody2D);
|
|
18
|
+
const grounded = e.has(Grounded);
|
|
19
|
+
const move = p.frozen ? 0 : input.axis('move');
|
|
20
|
+
|
|
21
|
+
// Aceleração em vez de velocidade instantânea.
|
|
22
|
+
// Durante o knockback, o empurrão manda; o controle volta depois de `stun` ticks.
|
|
23
|
+
if (p.stun > 0) p.stun--;
|
|
24
|
+
const target = move * p.speed;
|
|
25
|
+
const step = (grounded ? p.accel : p.airAccel) * time.dt;
|
|
26
|
+
if (p.stun === 0) body.velocity.x += Math.max(-step, Math.min(step, target - body.velocity.x));
|
|
27
|
+
|
|
28
|
+
// Coyote time e jump buffer: janelas curtas que perdoam o timing do jogador.
|
|
29
|
+
p.coyote = grounded ? p.coyoteTicks : Math.max(0, p.coyote - 1);
|
|
30
|
+
p.buffer = !p.frozen && input.pressed('jump') ? p.bufferTicks : Math.max(0, p.buffer - 1);
|
|
31
|
+
if (p.buffer > 0 && p.coyote > 0) {
|
|
32
|
+
body.velocity.y = -p.jump;
|
|
33
|
+
p.buffer = 0;
|
|
34
|
+
p.coyote = 0;
|
|
35
|
+
emit(PlayerJumped, { x: body.velocity.x, y: body.velocity.y });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Pulo variável: soltar subindo corta o pulo. Caindo: gravidade extra e limite.
|
|
39
|
+
if (input.released('jump') && body.velocity.y < 0) body.velocity.y *= p.jumpCut;
|
|
40
|
+
if (body.velocity.y > 0) body.velocity.y = Math.min(p.maxFall, body.velocity.y + p.fallGravity * time.dt);
|
|
41
|
+
|
|
42
|
+
const walking = Math.abs(body.velocity.x) > 10 && grounded;
|
|
43
|
+
e.write(Sprite).animation = !grounded ? 'player-jump' : walking ? 'player-walk' : 'player-idle';
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|