@muvtacode/cli 0.1.8 → 0.1.10
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/agent/loop.js +10 -1
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/prompt.js +101 -0
- package/dist/agent/prompt.js.map +1 -1
- package/dist/cli.js +102 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.js +28 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/i18n/en.js +4 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/pt.js +4 -0
- package/dist/i18n/pt.js.map +1 -1
- package/dist/remote/claudeSessions.js +82 -0
- package/dist/remote/claudeSessions.js.map +1 -0
- package/dist/remote/host.js +530 -0
- package/dist/remote/host.js.map +1 -0
- package/dist/remote/passagem.js +545 -0
- package/dist/remote/passagem.js.map +1 -0
- package/dist/repl.js +94 -22
- package/dist/repl.js.map +1 -1
- package/dist/state/templates.js +43 -10
- package/dist/state/templates.js.map +1 -1
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.obj +1472 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.obj +890 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/LICENCA.txt +25 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.obj +1444 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.obj +1789 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.obj +1273 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.obj +485 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.obj +1589 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.obj +309 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.obj +1681 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.obj +1275 -0
- package/dist/templates/game/adapt-assets-3d-01/files/src/assets/modelos.ts +270 -0
- package/dist/templates/game/adapt-assets-3d-01/meta.json +30 -0
- package/dist/templates/game/adapt-audio-01/files/src/audio/audio.ts +309 -0
- package/dist/templates/game/adapt-audio-01/meta.json +47 -0
- package/dist/templates/game/adapt-camera-rig-01/files/src/camera/rig.ts +364 -0
- package/dist/templates/game/adapt-camera-rig-01/meta.json +53 -0
- package/dist/templates/game/adapt-controle-teclado-01/files/src/controles/teclado.ts +175 -0
- package/dist/templates/game/adapt-controle-teclado-01/meta.json +36 -0
- package/dist/templates/game/adapt-controle-toque-01/files/src/controles/toque.ts +407 -0
- package/dist/templates/game/adapt-controle-toque-01/meta.json +43 -0
- package/dist/templates/game/adapt-dia-noite-01/files/src/world/dianoite.ts +378 -0
- package/dist/templates/game/adapt-dia-noite-01/meta.json +50 -0
- package/dist/templates/game/adapt-hud-01/files/src/hud/hud.ts +859 -0
- package/dist/templates/game/adapt-hud-01/meta.json +69 -0
- package/dist/templates/game/adapt-menu-01/files/src/ui/menu.ts +427 -0
- package/dist/templates/game/adapt-menu-01/meta.json +41 -0
- package/dist/templates/game/adapt-particulas-01/files/src/vfx/particulas.ts +280 -0
- package/dist/templates/game/adapt-particulas-01/meta.json +50 -0
- package/dist/templates/game/adapt-perf-mobile-01/files/src/engine/performance.ts +220 -0
- package/dist/templates/game/adapt-perf-mobile-01/meta.json +49 -0
- package/dist/templates/game/adapt-primeira-pessoa-01/files/src/camera/primeirapessoa.ts +595 -0
- package/dist/templates/game/adapt-primeira-pessoa-01/meta.json +63 -0
- package/dist/templates/game/adapt-save-01/files/src/save/save.ts +188 -0
- package/dist/templates/game/adapt-save-01/meta.json +34 -0
- package/dist/templates/game/carro-2d-01/files/src/models/carro2d.ts +253 -0
- package/dist/templates/game/carro-2d-01/meta.json +38 -0
- package/dist/templates/game/carro-3d-01/files/src/models/carro3d.ts +266 -0
- package/dist/templates/game/carro-3d-01/meta.json +13 -0
- package/dist/templates/game/estruturas-3d-01/files/src/world/estruturas.ts +490 -0
- package/dist/templates/game/estruturas-3d-01/meta.json +13 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/arena.ts +324 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/armas.ts +398 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/cena.ts +801 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/coletaveis.ts +129 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/fisica.ts +257 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/inimigos.ts +608 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/jogador.ts +224 -0
- package/dist/templates/game/fps-3d-01/files/src/main.ts +21 -0
- package/dist/templates/game/fps-3d-01/meta.json +48 -0
- package/dist/templates/game/game-design-tokens-01/files/src/design/tokens.ts +274 -0
- package/dist/templates/game/game-design-tokens-01/meta.json +13 -0
- package/dist/templates/game/game-engine-base-01/files/index.html +37 -0
- package/dist/templates/game/game-engine-base-01/files/package.json +19 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/device.ts +57 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/engine.ts +221 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/index.ts +68 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/input.ts +578 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/layout.ts +192 -0
- package/dist/templates/game/game-engine-base-01/files/tsconfig.json +14 -0
- package/dist/templates/game/game-engine-base-01/files/vite.config.ts +10 -0
- package/dist/templates/game/game-engine-base-01/meta.json +70 -0
- package/dist/templates/game/mundo-25d-01/files/src/world/mundo25d.ts +252 -0
- package/dist/templates/game/mundo-25d-01/meta.json +39 -0
- package/dist/templates/game/mundo-2d-01/files/src/world/mundo2d.ts +273 -0
- package/dist/templates/game/mundo-2d-01/meta.json +38 -0
- package/dist/templates/game/mundo-3d-01/files/src/world/mundo3d.ts +3130 -0
- package/dist/templates/game/mundo-3d-01/meta.json +132 -0
- package/dist/templates/game/npc-3d-01/files/src/ai/npc3d.ts +658 -0
- package/dist/templates/game/npc-3d-01/meta.json +13 -0
- package/dist/templates/game/personagem-2d-01/files/src/models/personagem2d.ts +341 -0
- package/dist/templates/game/personagem-2d-01/meta.json +41 -0
- package/dist/templates/game/personagem-3d-01/files/src/models/personagem3d.ts +614 -0
- package/dist/templates/game/personagem-3d-01/meta.json +67 -0
- package/package.json +2 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Layout de tela: safe-area real + reserva de zonas.
|
|
3
|
+
//
|
|
4
|
+
// Existe por causa de dois bugs que aparecem SEMPRE que HUD e controle de toque
|
|
5
|
+
// são escritos separadamente:
|
|
6
|
+
//
|
|
7
|
+
// 1. SAFE-AREA FANTASMA. Cada módulo lia uma variável CSS (`--sab`) que ninguém
|
|
8
|
+
// nunca definia — o valor voltava 0 e o botão ia para debaixo da barra de
|
|
9
|
+
// gestos. `env(safe-area-inset-*)` não é legível por getComputedStyle de
|
|
10
|
+
// forma confiável quando guardado em custom property, então aqui medimos com
|
|
11
|
+
// um elemento-sonda: o padding resolvido SEMPRE volta em px de verdade.
|
|
12
|
+
//
|
|
13
|
+
// 2. HUD EM CIMA DO BOTÃO. O minimapa ficava no canto inferior direito e os
|
|
14
|
+
// botões de ação também. Ninguém estava "errado" — faltava alguém saber dos
|
|
15
|
+
// dois. Quem desenha controle REGISTRA a área que ocupa; quem desenha HUD
|
|
16
|
+
// pede uma âncora livre e recebe um canto que não colide.
|
|
17
|
+
//
|
|
18
|
+
// Tudo em pixels CSS (não físicos): é a unidade que o resto do jogo usa para
|
|
19
|
+
// layout, e a única que não muda quando o devicePixelRatio muda.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
export interface Insets {
|
|
23
|
+
topo: number;
|
|
24
|
+
base: number;
|
|
25
|
+
esq: number;
|
|
26
|
+
dir: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Zona {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
largura: number;
|
|
33
|
+
altura: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Cantos disponíveis para ancorar um widget de HUD. */
|
|
37
|
+
export type Canto =
|
|
38
|
+
| 'inferior-direita' | 'inferior-esquerda'
|
|
39
|
+
| 'superior-direita' | 'superior-esquerda';
|
|
40
|
+
|
|
41
|
+
export const tuning = {
|
|
42
|
+
/** Folga extra além do safe-area, em px CSS. */
|
|
43
|
+
margem: 20,
|
|
44
|
+
/** Distância mínima entre um widget de HUD e uma zona de controle. */
|
|
45
|
+
folgaEntreZonas: 8
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// --------------------------------------------------------------- safe-area
|
|
49
|
+
|
|
50
|
+
let sonda: HTMLElement | null = null;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Cria (uma vez) o elemento invisível que traduz `env(safe-area-inset-*)` em px.
|
|
54
|
+
* Precisa estar no fluxo do documento — `display:none` faz o padding não
|
|
55
|
+
* resolver e volta 0, que é justamente o bug que estamos consertando.
|
|
56
|
+
*/
|
|
57
|
+
function garantirSonda(): HTMLElement {
|
|
58
|
+
if (sonda?.isConnected) return sonda;
|
|
59
|
+
const el = document.createElement('div');
|
|
60
|
+
el.setAttribute('aria-hidden', 'true');
|
|
61
|
+
el.style.cssText = [
|
|
62
|
+
'position:fixed',
|
|
63
|
+
'top:0',
|
|
64
|
+
'left:0',
|
|
65
|
+
'width:0',
|
|
66
|
+
'height:0',
|
|
67
|
+
'pointer-events:none',
|
|
68
|
+
'visibility:hidden',
|
|
69
|
+
'padding-top:env(safe-area-inset-top, 0px)',
|
|
70
|
+
'padding-bottom:env(safe-area-inset-bottom, 0px)',
|
|
71
|
+
'padding-left:env(safe-area-inset-left, 0px)',
|
|
72
|
+
'padding-right:env(safe-area-inset-right, 0px)'
|
|
73
|
+
].join(';');
|
|
74
|
+
document.body.appendChild(el);
|
|
75
|
+
sonda = el;
|
|
76
|
+
return el;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let cache: Insets | null = null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Insets do notch / barra de gestos, em px CSS.
|
|
83
|
+
*
|
|
84
|
+
* O resultado é memorizado: `getComputedStyle` força layout, e chamar isso a
|
|
85
|
+
* cada botão desenhado a 60fps é um dos jeitos mais fáceis de fazer um jogo
|
|
86
|
+
* engasgar sem motivo aparente. `invalidarLayout()` limpa no resize.
|
|
87
|
+
*/
|
|
88
|
+
export function safeArea(): Insets {
|
|
89
|
+
if (cache) return cache;
|
|
90
|
+
if (typeof document === 'undefined') return { topo: 0, base: 0, esq: 0, dir: 0 };
|
|
91
|
+
|
|
92
|
+
const cs = getComputedStyle(garantirSonda());
|
|
93
|
+
const px = (v: string) => {
|
|
94
|
+
const n = parseFloat(v);
|
|
95
|
+
return Number.isFinite(n) ? n : 0;
|
|
96
|
+
};
|
|
97
|
+
cache = {
|
|
98
|
+
topo: px(cs.paddingTop),
|
|
99
|
+
base: px(cs.paddingBottom),
|
|
100
|
+
esq: px(cs.paddingLeft),
|
|
101
|
+
dir: px(cs.paddingRight)
|
|
102
|
+
};
|
|
103
|
+
return cache;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Margem total de um lado: safe-area + folga do jogo. */
|
|
107
|
+
export function margemDe(lado: keyof Insets, extra = 0): number {
|
|
108
|
+
return safeArea()[lado] + tuning.margem + extra;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ------------------------------------------------------------------ zonas
|
|
112
|
+
|
|
113
|
+
const registros = new Map<string, () => Zona[]>();
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Declara que um módulo ocupa certas áreas da tela.
|
|
117
|
+
*
|
|
118
|
+
* Passa-se uma FUNÇÃO, não um array: as posições dependem de innerWidth e do
|
|
119
|
+
* safe-area, que mudam quando o aparelho gira. Guardar valores congelados aqui
|
|
120
|
+
* traria de volta o bug de sobreposição só depois de rotacionar a tela.
|
|
121
|
+
*/
|
|
122
|
+
export function registrarZonas(nome: string, calcular: () => Zona[]): void {
|
|
123
|
+
registros.set(nome, calcular);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function removerZonas(nome: string): void {
|
|
127
|
+
registros.delete(nome);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Todas as zonas ocupadas agora, exceto as do próprio chamador. */
|
|
131
|
+
export function zonasOcupadas(exceto?: string): Zona[] {
|
|
132
|
+
const fora: Zona[] = [];
|
|
133
|
+
for (const [nome, calcular] of registros) {
|
|
134
|
+
if (nome === exceto) continue;
|
|
135
|
+
try {
|
|
136
|
+
fora.push(...calcular());
|
|
137
|
+
} catch {
|
|
138
|
+
// Um módulo com bug no cálculo não pode derrubar o desenho do HUD.
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return fora;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const colide = (a: Zona, b: Zona, folga: number): boolean =>
|
|
145
|
+
a.x < b.x + b.largura + folga &&
|
|
146
|
+
a.x + a.largura + folga > b.x &&
|
|
147
|
+
a.y < b.y + b.altura + folga &&
|
|
148
|
+
a.y + a.altura + folga > b.y;
|
|
149
|
+
|
|
150
|
+
/** Retângulo de um widget de tamanho fixo encostado num canto, já com margem. */
|
|
151
|
+
export function zonaNoCanto(canto: Canto, largura: number, altura: number): Zona {
|
|
152
|
+
const sa = safeArea();
|
|
153
|
+
const m = tuning.margem;
|
|
154
|
+
const direita = canto.endsWith('direita');
|
|
155
|
+
const inferior = canto.startsWith('inferior');
|
|
156
|
+
return {
|
|
157
|
+
x: direita ? innerWidth - sa.dir - m - largura : sa.esq + m,
|
|
158
|
+
y: inferior ? innerHeight - sa.base - m - altura : sa.topo + m,
|
|
159
|
+
largura,
|
|
160
|
+
altura
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Escolhe o primeiro canto da lista de preferência que não bate em nenhuma zona
|
|
166
|
+
* registrada por outro módulo. Se todos colidirem, devolve o último — melhor
|
|
167
|
+
* sobrepor num canto previsível do que empilhar tudo no mesmo lugar.
|
|
168
|
+
*/
|
|
169
|
+
export function cantoLivre(
|
|
170
|
+
preferencia: Canto[],
|
|
171
|
+
largura: number,
|
|
172
|
+
altura: number,
|
|
173
|
+
exceto?: string
|
|
174
|
+
): { canto: Canto; zona: Zona } {
|
|
175
|
+
const ocupadas = zonasOcupadas(exceto);
|
|
176
|
+
for (const canto of preferencia) {
|
|
177
|
+
const zona = zonaNoCanto(canto, largura, altura);
|
|
178
|
+
if (!ocupadas.some((o) => colide(zona, o, tuning.folgaEntreZonas))) return { canto, zona };
|
|
179
|
+
}
|
|
180
|
+
const ultimo = preferencia[preferencia.length - 1] ?? 'superior-esquerda';
|
|
181
|
+
return { canto: ultimo, zona: zonaNoCanto(ultimo, largura, altura) };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Chame no resize: o safe-area muda quando o aparelho gira. */
|
|
185
|
+
export function invalidarLayout(): void {
|
|
186
|
+
cache = null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (typeof window !== 'undefined') {
|
|
190
|
+
addEventListener('resize', invalidarLayout);
|
|
191
|
+
addEventListener('orientationchange', invalidarLayout);
|
|
192
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noUncheckedIndexedAccess": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
// host 0.0.0.0: o servidor precisa responder fora do localhost do Linux
|
|
4
|
+
// embutido (pré-visualização do app e túnel). chunkSizeWarningLimit: o Three
|
|
5
|
+
// sozinho passa dos 500 kB e o aviso padrão só assusta.
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
server: { host: '0.0.0.0', port: 5173 },
|
|
8
|
+
preview: { host: '0.0.0.0', port: 4173 },
|
|
9
|
+
build: { target: 'es2020', chunkSizeWarningLimit: 1500 }
|
|
10
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "game-engine-base-01",
|
|
3
|
+
"nome": "Engine Base de Jogo (desktop + mobile)",
|
|
4
|
+
"categoria": "game",
|
|
5
|
+
"framework": "vite",
|
|
6
|
+
"linguagem": "typescript",
|
|
7
|
+
"dependencias": [
|
|
8
|
+
"three",
|
|
9
|
+
"vite",
|
|
10
|
+
"typescript",
|
|
11
|
+
"@types/three"
|
|
12
|
+
],
|
|
13
|
+
"tags": [
|
|
14
|
+
"game",
|
|
15
|
+
"jogo",
|
|
16
|
+
"engine",
|
|
17
|
+
"loop",
|
|
18
|
+
"gameloop",
|
|
19
|
+
"input",
|
|
20
|
+
"canvas",
|
|
21
|
+
"three",
|
|
22
|
+
"2d",
|
|
23
|
+
"3d",
|
|
24
|
+
"desktop",
|
|
25
|
+
"mobile",
|
|
26
|
+
"base",
|
|
27
|
+
"bootstrap",
|
|
28
|
+
"teclado",
|
|
29
|
+
"gamepad",
|
|
30
|
+
"olhar",
|
|
31
|
+
"safe-area",
|
|
32
|
+
"layout",
|
|
33
|
+
"fps",
|
|
34
|
+
"mouse",
|
|
35
|
+
"mira",
|
|
36
|
+
"recarregar",
|
|
37
|
+
"agachar",
|
|
38
|
+
"scaffold",
|
|
39
|
+
"esqueleto",
|
|
40
|
+
"vite",
|
|
41
|
+
"index",
|
|
42
|
+
"package"
|
|
43
|
+
],
|
|
44
|
+
"compatibilidade": {
|
|
45
|
+
"banco": [],
|
|
46
|
+
"auth": []
|
|
47
|
+
},
|
|
48
|
+
"recursos_suportados": [
|
|
49
|
+
"passo-fixo",
|
|
50
|
+
"deteccao-dispositivo",
|
|
51
|
+
"input-unificado",
|
|
52
|
+
"bordas-por-passo",
|
|
53
|
+
"fontes-de-input-independentes",
|
|
54
|
+
"olhar-unificado",
|
|
55
|
+
"trava-de-ponteiro",
|
|
56
|
+
"safe-area-medida",
|
|
57
|
+
"reserva-de-zonas-de-tela",
|
|
58
|
+
"resize",
|
|
59
|
+
"cenas",
|
|
60
|
+
"pausa-automatica",
|
|
61
|
+
"estatisticas",
|
|
62
|
+
"esqueleto-vite-pronto",
|
|
63
|
+
"acoes-de-tiro",
|
|
64
|
+
"botoes-do-mouse-com-trava",
|
|
65
|
+
"roda-do-mouse",
|
|
66
|
+
"gatilhos-do-gamepad"
|
|
67
|
+
],
|
|
68
|
+
"versao": "2.1.0",
|
|
69
|
+
"descricao": "Fundação de qualquer jogo do projeto: laço com PASSO FIXO (física estável em 30 e em 144Hz), detecção desktop/mobile em runtime, camada de input unificada (teclado, mouse, gamepad e toque na MESMA API), resize com clamp de devicePixelRatio, gerenciador de cenas e pausa automática ao perder o foco. O input resolve três armadilhas clássicas: `pressionou()` é consumido POR PASSO de simulação (senão um toque no espaço vira vários pulos num quadro pesado, e num monitor de 144Hz a tecla é descartada antes de qualquer passo vê-la); teclado, toque e gamepad são fontes INDEPENDENTES unidas por OR (um gamepad plugado não zera mais a tecla segurada); e o delta de OLHAR é medido por posição num só lugar, então câmera e joystick nunca disputam o mesmo evento. Inclui layout.ts: safe-area medida de verdade (não a variável CSS que ninguém definia) e reserva de zonas de tela, que é como o HUD evita desenhar em cima dos botões de toque. Serve tanto Canvas 2D quanto Three.js. Aplique SEMPRE primeiro, antes dos templates de conteúdo. Traz o ESQUELETO do projeto: index.html (canvas #jogo + tela de carregamento #carregando), package.json (three, vite, typescript, @types/three; `npm run dev` já sobe em 0.0.0.0), vite.config.ts e tsconfig.json estrito. Falta só o src/main.ts, que é do jogo: chame bootstrap('#jogo'), troque a cena, engine.iniciar() e remova o #carregando. O input tem as ações de TIRO (`mirar`, `recarregar`, `agachar`, `trocarArma`), os botões do mouse como ação (`Mouse0` atira, `Mouse2` mira) só com o mouse travado — o clique que trava não dispara —, `input.rolagem` para trocar de arma na roda e RT/LB no gamepad."
|
|
70
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Mundo isométrico 2.5D com elevação.
|
|
3
|
+
//
|
|
4
|
+
// "2.5D" aqui é o de verdade: grid 2D com ALTURA, desenhado em projeção
|
|
5
|
+
// isométrica. Cada tile vira um bloco com topo e duas faces laterais.
|
|
6
|
+
//
|
|
7
|
+
// Os três problemas que definem se um iso engine funciona:
|
|
8
|
+
//
|
|
9
|
+
// 1. ORDENAÇÃO. Desenhar na ordem errada faz o bloco de trás cobrir o da
|
|
10
|
+
// frente. A ordem correta é por (linha + coluna) crescente — a diagonal da
|
|
11
|
+
// tela — e, dentro dela, por altura.
|
|
12
|
+
//
|
|
13
|
+
// 2. PICKING. Converter pixel do mouse em tile é a inversa da projeção. Com
|
|
14
|
+
// elevação fica pior: o pixel pode pertencer ao topo de um bloco alto que
|
|
15
|
+
// está "atrás". Resolvemos varrendo de frente para trás e parando no
|
|
16
|
+
// primeiro acerto.
|
|
17
|
+
//
|
|
18
|
+
// 3. SOMBREAMENTO DAS FACES. Topo claro, face esquerda média, face direita
|
|
19
|
+
// escura. Sem isso o bloco vira um hexágono chapado e a ilusão morre.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
import { getPalette, alpha } from '../design/tokens';
|
|
23
|
+
|
|
24
|
+
export const tuning = {
|
|
25
|
+
/** Largura do losango do tile. A altura é metade — proporção 2:1 clássica. */
|
|
26
|
+
larguraTile: 64,
|
|
27
|
+
/** Altura visual de uma unidade de elevação, em px. */
|
|
28
|
+
alturaNivel: 16,
|
|
29
|
+
/** Escurecimento das faces (0..1). */
|
|
30
|
+
faceEsquerda: 0.22,
|
|
31
|
+
faceDireita: 0.42,
|
|
32
|
+
/** Contorno dos blocos. Desligue para visual mais limpo. */
|
|
33
|
+
contorno: true,
|
|
34
|
+
suavizacaoCamera: 7
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface Tile {
|
|
38
|
+
/** Elevação em níveis inteiros. 0 = chão. */
|
|
39
|
+
altura: number;
|
|
40
|
+
/** Papel de cor na paleta. */
|
|
41
|
+
cor: string;
|
|
42
|
+
/** Livre para o gameplay: 'agua', 'parede', 'estrada'... */
|
|
43
|
+
tipo?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface Mundo25D {
|
|
47
|
+
colunas: number;
|
|
48
|
+
linhas: number;
|
|
49
|
+
camX: number;
|
|
50
|
+
camY: number;
|
|
51
|
+
tileEm(col: number, lin: number): Tile | null;
|
|
52
|
+
definirTile(col: number, lin: number, tile: Partial<Tile>): void;
|
|
53
|
+
/** Grid → pixel (canto do topo do bloco). */
|
|
54
|
+
paraTela(col: number, lin: number, altura?: number): { x: number; y: number };
|
|
55
|
+
/** Pixel → grid, respeitando elevação. null quando clicou fora. */
|
|
56
|
+
paraGrid(telaX: number, telaY: number): { col: number; lin: number } | null;
|
|
57
|
+
centralizarEm(col: number, lin: number, passo: number, larguraTela: number, alturaTela: number): void;
|
|
58
|
+
desenhar(ctx: CanvasRenderingContext2D, larguraTela: number, alturaTela: number): void;
|
|
59
|
+
/** Tile sob o cursor, destacado no desenho. */
|
|
60
|
+
destaque: { col: number; lin: number } | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Cria o mundo. `gerar` recebe (col, lin) e devolve o tile — por padrão faz um
|
|
65
|
+
* relevo suave com dois senos, só para não nascer plano.
|
|
66
|
+
*/
|
|
67
|
+
export function criarMundo25D(
|
|
68
|
+
colunas = 24,
|
|
69
|
+
linhas = 24,
|
|
70
|
+
gerar?: (col: number, lin: number) => Tile
|
|
71
|
+
): Mundo25D {
|
|
72
|
+
const geradorPadrao = (col: number, lin: number): Tile => {
|
|
73
|
+
const h = Math.round(
|
|
74
|
+
(Math.sin(col * 0.35) + Math.cos(lin * 0.3) + Math.sin((col + lin) * 0.18) * 0.8) * 1.6
|
|
75
|
+
);
|
|
76
|
+
const altura = Math.max(0, h + 2);
|
|
77
|
+
const cor = altura >= 5 ? 'texto' : altura >= 3 ? 'secundaria' : altura >= 1 ? 'sucesso' : 'primaria';
|
|
78
|
+
return { altura, cor, tipo: altura === 0 ? 'agua' : 'terra' };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const criar = gerar ?? geradorPadrao;
|
|
82
|
+
const grid: Tile[][] = Array.from({ length: linhas }, (_, lin) =>
|
|
83
|
+
Array.from({ length: colunas }, (_, col) => criar(col, lin))
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const W = tuning.larguraTile;
|
|
87
|
+
const H = W / 2; // proporção 2:1
|
|
88
|
+
const N = tuning.alturaNivel;
|
|
89
|
+
|
|
90
|
+
const mundo: Mundo25D = {
|
|
91
|
+
colunas,
|
|
92
|
+
linhas,
|
|
93
|
+
camX: 0,
|
|
94
|
+
camY: 0,
|
|
95
|
+
destaque: null,
|
|
96
|
+
|
|
97
|
+
tileEm(col, lin) {
|
|
98
|
+
if (col < 0 || col >= colunas || lin < 0 || lin >= linhas) return null;
|
|
99
|
+
return grid[lin]![col]!;
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
definirTile(col, lin, tile) {
|
|
103
|
+
const atual = mundo.tileEm(col, lin);
|
|
104
|
+
if (atual) Object.assign(atual, tile);
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/** Projeção isométrica padrão. A altura só desloca em Y. */
|
|
108
|
+
paraTela(col, lin, altura = 0) {
|
|
109
|
+
return {
|
|
110
|
+
x: (col - lin) * (W / 2),
|
|
111
|
+
y: (col + lin) * (H / 2) - altura * N
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
paraGrid(telaX, telaY) {
|
|
116
|
+
// Sem elevação, a inversa é direta. Com elevação, um pixel pode ser o
|
|
117
|
+
// topo de um bloco alto mais ao fundo — por isso varremos de FRENTE para
|
|
118
|
+
// trás (soma col+lin decrescente) e paramos no primeiro que contém o ponto.
|
|
119
|
+
const x = telaX + mundo.camX;
|
|
120
|
+
const y = telaY + mundo.camY;
|
|
121
|
+
|
|
122
|
+
for (let soma = colunas + linhas - 2; soma >= 0; soma--) {
|
|
123
|
+
for (let col = Math.min(soma, colunas - 1); col >= 0; col--) {
|
|
124
|
+
const lin = soma - col;
|
|
125
|
+
if (lin < 0 || lin >= linhas) continue;
|
|
126
|
+
const t = grid[lin]![col]!;
|
|
127
|
+
const p = mundo.paraTela(col, lin, t.altura);
|
|
128
|
+
|
|
129
|
+
// Ponto dentro do losango do topo: |dx|/(W/2) + |dy|/(H/2) <= 1
|
|
130
|
+
const dx = x - p.x;
|
|
131
|
+
const dy = y - (p.y + H / 2);
|
|
132
|
+
if (Math.abs(dx) / (W / 2) + Math.abs(dy) / (H / 2) <= 1) {
|
|
133
|
+
return { col, lin };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
centralizarEm(col, lin, passo, larguraTela, alturaTela) {
|
|
141
|
+
const t = mundo.tileEm(col, lin);
|
|
142
|
+
const p = mundo.paraTela(col, lin, t?.altura ?? 0);
|
|
143
|
+
const desejadaX = p.x - larguraTela / 2;
|
|
144
|
+
const desejadaY = p.y - alturaTela / 2;
|
|
145
|
+
const k = 1 - Math.exp(-passo * tuning.suavizacaoCamera);
|
|
146
|
+
mundo.camX += (desejadaX - mundo.camX) * k;
|
|
147
|
+
mundo.camY += (desejadaY - mundo.camY) * k;
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
desenhar(ctx, larguraTela, alturaTela) {
|
|
151
|
+
const p = getPalette();
|
|
152
|
+
ctx.save();
|
|
153
|
+
ctx.translate(-Math.round(mundo.camX), -Math.round(mundo.camY));
|
|
154
|
+
|
|
155
|
+
// Ordem de pintor: percorre pelas diagonais (col + lin crescente). O que
|
|
156
|
+
// está mais "ao fundo" é desenhado antes e acaba coberto pelo da frente.
|
|
157
|
+
for (let soma = 0; soma <= colunas + linhas - 2; soma++) {
|
|
158
|
+
for (let col = 0; col < colunas; col++) {
|
|
159
|
+
const lin = soma - col;
|
|
160
|
+
if (lin < 0 || lin >= linhas) continue;
|
|
161
|
+
|
|
162
|
+
const tile = grid[lin]![col]!;
|
|
163
|
+
const pos = mundo.paraTela(col, lin, tile.altura);
|
|
164
|
+
|
|
165
|
+
// Culling por caixa: pula o que está fora da tela.
|
|
166
|
+
const telaX = pos.x - mundo.camX;
|
|
167
|
+
const telaY = pos.y - mundo.camY;
|
|
168
|
+
if (telaX < -W || telaX > larguraTela + W) continue;
|
|
169
|
+
if (telaY < -H - tile.altura * N - 40 || telaY > alturaTela + H) continue;
|
|
170
|
+
|
|
171
|
+
const corBase = (p[tile.cor as keyof typeof p] as string) ?? p.primaria;
|
|
172
|
+
const profundidade = Math.max(1, tile.altura) * N;
|
|
173
|
+
|
|
174
|
+
desenharBloco(ctx, pos.x, pos.y, corBase, profundidade);
|
|
175
|
+
|
|
176
|
+
if (mundo.destaque?.col === col && mundo.destaque?.lin === lin) {
|
|
177
|
+
losango(ctx, pos.x, pos.y);
|
|
178
|
+
ctx.fillStyle = alpha(p.acento, 0.42);
|
|
179
|
+
ctx.fill();
|
|
180
|
+
ctx.strokeStyle = p.acento;
|
|
181
|
+
ctx.lineWidth = 2;
|
|
182
|
+
ctx.stroke();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
ctx.restore();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** Losango do topo, com o "canto de cima" em (x, y). */
|
|
191
|
+
function losango(ctx: CanvasRenderingContext2D, x: number, y: number): void {
|
|
192
|
+
ctx.beginPath();
|
|
193
|
+
ctx.moveTo(x, y);
|
|
194
|
+
ctx.lineTo(x + W / 2, y + H / 2);
|
|
195
|
+
ctx.lineTo(x, y + H);
|
|
196
|
+
ctx.lineTo(x - W / 2, y + H / 2);
|
|
197
|
+
ctx.closePath();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function desenharBloco(
|
|
201
|
+
ctx: CanvasRenderingContext2D,
|
|
202
|
+
x: number, y: number,
|
|
203
|
+
cor: string, profundidade: number
|
|
204
|
+
): void {
|
|
205
|
+
const p = getPalette();
|
|
206
|
+
|
|
207
|
+
// Face esquerda
|
|
208
|
+
ctx.beginPath();
|
|
209
|
+
ctx.moveTo(x - W / 2, y + H / 2);
|
|
210
|
+
ctx.lineTo(x, y + H);
|
|
211
|
+
ctx.lineTo(x, y + H + profundidade);
|
|
212
|
+
ctx.lineTo(x - W / 2, y + H / 2 + profundidade);
|
|
213
|
+
ctx.closePath();
|
|
214
|
+
ctx.fillStyle = misturar(cor, p.fundo, tuning.faceEsquerda);
|
|
215
|
+
ctx.fill();
|
|
216
|
+
|
|
217
|
+
// Face direita (mais escura: sugere a luz vindo da esquerda)
|
|
218
|
+
ctx.beginPath();
|
|
219
|
+
ctx.moveTo(x + W / 2, y + H / 2);
|
|
220
|
+
ctx.lineTo(x, y + H);
|
|
221
|
+
ctx.lineTo(x, y + H + profundidade);
|
|
222
|
+
ctx.lineTo(x + W / 2, y + H / 2 + profundidade);
|
|
223
|
+
ctx.closePath();
|
|
224
|
+
ctx.fillStyle = misturar(cor, p.fundo, tuning.faceDireita);
|
|
225
|
+
ctx.fill();
|
|
226
|
+
|
|
227
|
+
// Topo
|
|
228
|
+
losango(ctx, x, y);
|
|
229
|
+
ctx.fillStyle = cor;
|
|
230
|
+
ctx.fill();
|
|
231
|
+
|
|
232
|
+
if (tuning.contorno) {
|
|
233
|
+
ctx.strokeStyle = alpha(p.fundo, 0.35);
|
|
234
|
+
ctx.lineWidth = 1;
|
|
235
|
+
ctx.stroke();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return mundo;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Interpola duas cores hex. `t` 0 = a, 1 = b. */
|
|
243
|
+
function misturar(a: string, b: string, t: number): string {
|
|
244
|
+
const na = parseInt(a.replace('#', ''), 16);
|
|
245
|
+
const nb = parseInt(b.replace('#', ''), 16);
|
|
246
|
+
const canal = (deslocamento: number) => {
|
|
247
|
+
const ca = (na >> deslocamento) & 255;
|
|
248
|
+
const cb = (nb >> deslocamento) & 255;
|
|
249
|
+
return Math.round(ca + (cb - ca) * t);
|
|
250
|
+
};
|
|
251
|
+
return `rgb(${canal(16)}, ${canal(8)}, ${canal(0)})`;
|
|
252
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"categoria": "game",
|
|
3
|
+
"framework": "canvas",
|
|
4
|
+
"linguagem": "typescript",
|
|
5
|
+
"dependencias": [],
|
|
6
|
+
"compatibilidade": {
|
|
7
|
+
"banco": [],
|
|
8
|
+
"auth": []
|
|
9
|
+
},
|
|
10
|
+
"versao": "1.0.0",
|
|
11
|
+
"id": "mundo-25d-01",
|
|
12
|
+
"nome": "Mundo 2.5D Isométrico (com elevação)",
|
|
13
|
+
"tags": [
|
|
14
|
+
"game",
|
|
15
|
+
"jogo",
|
|
16
|
+
"mundo",
|
|
17
|
+
"isometrico",
|
|
18
|
+
"isometric",
|
|
19
|
+
"2.5d",
|
|
20
|
+
"25d",
|
|
21
|
+
"canvas",
|
|
22
|
+
"diablo",
|
|
23
|
+
"rts",
|
|
24
|
+
"city-builder",
|
|
25
|
+
"altura",
|
|
26
|
+
"profundidade",
|
|
27
|
+
"grid"
|
|
28
|
+
],
|
|
29
|
+
"recursos_suportados": [
|
|
30
|
+
"projecao-isometrica",
|
|
31
|
+
"elevacao",
|
|
32
|
+
"ordenacao-por-profundidade",
|
|
33
|
+
"picking-do-mouse",
|
|
34
|
+
"destaque-de-tile",
|
|
35
|
+
"sombra-por-altura",
|
|
36
|
+
"camera-isometrica"
|
|
37
|
+
],
|
|
38
|
+
"descricao": "Mundo isométrico 2.5D com elevação real: cada tile tem altura, é desenhado como bloco com topo e duas faces laterais sombreadas, e a ordenação por profundidade garante que o que está na frente cubra o que está atrás. Inclui picking inverso (converte pixel do mouse em coordenada do grid, contando a altura), destaque do tile sob o cursor e câmera isométrica com limites. Base para RTS, city builder ou RPG isométrico."
|
|
39
|
+
}
|