@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,407 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Controle por toque: joystick virtual + botões de ação + zona de olhar.
|
|
3
|
+
//
|
|
4
|
+
// Decisões que fazem diferença no celular:
|
|
5
|
+
//
|
|
6
|
+
// 1. Desenhado em CANVAS próprio, não em DOM. Botão HTML no meio do jogo gera
|
|
7
|
+
// layout/paint a cada toque e o jogo engasga; canvas sobreposto não.
|
|
8
|
+
//
|
|
9
|
+
// 2. Multi-toque de verdade, rastreado por pointerId. Sem isso o jogador não
|
|
10
|
+
// consegue andar e atirar ao mesmo tempo — o segundo dedo rouba o primeiro.
|
|
11
|
+
//
|
|
12
|
+
// 3. Joystick FLUTUANTE por padrão: ele nasce onde o polegar encostou, em vez
|
|
13
|
+
// de ficar num canto fixo. É o padrão dos bons jogos mobile — o dedo não
|
|
14
|
+
// precisa procurar o controle.
|
|
15
|
+
//
|
|
16
|
+
// 4. Escreve no Input do engine. O gameplay continua chamando input.eixo() e
|
|
17
|
+
// não sabe que veio de toque.
|
|
18
|
+
//
|
|
19
|
+
// 5. RESERVA o dedo que está num controle (`input.reservarPonteiro`) e declara
|
|
20
|
+
// sua área (`input.definirZonaDeControle`). Sem isso, arrastar o joystick
|
|
21
|
+
// também girava a câmera — os dois liam o mesmo pointermove. Com a reserva,
|
|
22
|
+
// a divisão fica clara: metade do joystick anda, a outra metade olha.
|
|
23
|
+
//
|
|
24
|
+
// 6. REGISTRA as zonas que ocupa no layout do engine, para o HUD não desenhar o
|
|
25
|
+
// minimapa em cima dos botões (era exatamente o que acontecia: os dois
|
|
26
|
+
// ficavam no canto inferior direito, e o HUD por estar num z-index maior
|
|
27
|
+
// ganhava).
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
import type { Input, Acao, Zona } from '../engine';
|
|
31
|
+
import { safeArea, registrarZonas, removerZonas } from '../engine';
|
|
32
|
+
import { getPalette, alpha } from '../design/tokens';
|
|
33
|
+
|
|
34
|
+
const NOME_ZONA = 'controle-toque';
|
|
35
|
+
|
|
36
|
+
export const tuning = {
|
|
37
|
+
/** Raio do joystick em px (na densidade CSS). */
|
|
38
|
+
raioBase: 62,
|
|
39
|
+
raioManete: 28,
|
|
40
|
+
/** Fração do raio ignorada no centro. Evita drift com o polegar parado. */
|
|
41
|
+
zonaMorta: 0.16,
|
|
42
|
+
/** Joystick nasce onde o dedo tocou (true) ou fica fixo no canto (false). */
|
|
43
|
+
flutuante: true,
|
|
44
|
+
/** Metade esquerda da tela move; direita age. Inverta para canhoto. */
|
|
45
|
+
ladoDoJoystick: 'esquerda' as 'esquerda' | 'direita',
|
|
46
|
+
raioBotao: 38,
|
|
47
|
+
espacamentoBotao: 14,
|
|
48
|
+
opacidade: 0.32,
|
|
49
|
+
opacidadeAtiva: 0.6,
|
|
50
|
+
/** Margem extra além do safe-area (notch / barra de gestos). */
|
|
51
|
+
margem: 24,
|
|
52
|
+
/**
|
|
53
|
+
* Fração da altura da tela, a partir do topo, que NÃO aceita joystick.
|
|
54
|
+
* Deixa a faixa superior livre para arrastar a câmera com o polegar esquerdo.
|
|
55
|
+
*/
|
|
56
|
+
fracaoSuperiorLivre: 0.25,
|
|
57
|
+
vibrar: true
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export interface BotaoToque {
|
|
61
|
+
acao: Acao;
|
|
62
|
+
rotulo: string;
|
|
63
|
+
/** Ordem a partir do canto: 0 é o mais próximo do polegar. */
|
|
64
|
+
ordem: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Layout padrão. Troque a `acao` para reaproveitar em outro gênero. */
|
|
68
|
+
export const BOTOES_PADRAO: BotaoToque[] = [
|
|
69
|
+
{ acao: 'pular', rotulo: 'A', ordem: 0 },
|
|
70
|
+
{ acao: 'atacar', rotulo: 'B', ordem: 1 },
|
|
71
|
+
{ acao: 'usar', rotulo: 'E', ordem: 2 }
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
interface Toque {
|
|
75
|
+
id: number;
|
|
76
|
+
origemX: number;
|
|
77
|
+
origemY: number;
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
/** Qual controle este dedo está usando. */
|
|
81
|
+
alvo: 'joystick' | Acao;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ControleToque {
|
|
85
|
+
/** Chame no desenhar() da cena, DEPOIS do jogo. */
|
|
86
|
+
desenhar(): void;
|
|
87
|
+
/** Some com os controles (cutscene, menu). */
|
|
88
|
+
visivel: boolean;
|
|
89
|
+
dispose(): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function criarControleToque(
|
|
93
|
+
input: Input,
|
|
94
|
+
canvasJogo: HTMLCanvasElement,
|
|
95
|
+
botoes: BotaoToque[] = BOTOES_PADRAO
|
|
96
|
+
): ControleToque {
|
|
97
|
+
// Canvas próprio, por cima, sem capturar eventos (pointer-events: none) —
|
|
98
|
+
// quem escuta é o canvas do jogo, que já tem os listeners.
|
|
99
|
+
const canvas = document.createElement('canvas');
|
|
100
|
+
canvas.style.cssText =
|
|
101
|
+
'position:fixed;inset:0;pointer-events:none;z-index:10;touch-action:none;';
|
|
102
|
+
document.body.appendChild(canvas);
|
|
103
|
+
const ctx = canvas.getContext('2d')!;
|
|
104
|
+
|
|
105
|
+
const toques = new Map<number, Toque>();
|
|
106
|
+
/**
|
|
107
|
+
* Quantos dedos seguram cada ação. Sem a contagem, soltar o segundo dedo de
|
|
108
|
+
* um mesmo botão liberava a ação enquanto o primeiro ainda estava apertado.
|
|
109
|
+
*/
|
|
110
|
+
const dedosPorAcao = new Map<Acao, number>();
|
|
111
|
+
let visivel = true;
|
|
112
|
+
|
|
113
|
+
const redimensionar = () => {
|
|
114
|
+
const dpr = Math.min(devicePixelRatio || 1, 2);
|
|
115
|
+
canvas.width = Math.round(innerWidth * dpr);
|
|
116
|
+
canvas.height = Math.round(innerHeight * dpr);
|
|
117
|
+
canvas.style.width = `${innerWidth}px`;
|
|
118
|
+
canvas.style.height = `${innerHeight}px`;
|
|
119
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
120
|
+
};
|
|
121
|
+
redimensionar();
|
|
122
|
+
addEventListener('resize', redimensionar);
|
|
123
|
+
|
|
124
|
+
const noLadoDoJoystick = () => tuning.ladoDoJoystick === 'esquerda';
|
|
125
|
+
|
|
126
|
+
/** Posição de repouso do joystick (usada quando flutuante = false). */
|
|
127
|
+
const ancoraJoystick = () => {
|
|
128
|
+
const sa = safeArea();
|
|
129
|
+
const y = innerHeight - tuning.raioBase - tuning.margem - sa.base;
|
|
130
|
+
const x = noLadoDoJoystick()
|
|
131
|
+
? tuning.raioBase + tuning.margem + sa.esq
|
|
132
|
+
: innerWidth - tuning.raioBase - tuning.margem - sa.dir;
|
|
133
|
+
return { x, y };
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Centro de cada botão: o 0 no canto, os outros em ANÉIS em volta dele, ao
|
|
138
|
+
* alcance do polegar. Os ângulos são em graus a partir do "para cima" e
|
|
139
|
+
* crescem para dentro da tela.
|
|
140
|
+
*
|
|
141
|
+
* A versão anterior girava 0,62 rad por botão num raio só: a 90 px isso põe
|
|
142
|
+
* centros a 55 px um do outro, com botões de 76 px de diâmetro — do 3º botão
|
|
143
|
+
* em diante eles se sobrepunham (e o toque na sobra caía no botão errado), e
|
|
144
|
+
* o 4º saía pela borda de baixo da tela. Dois anéis cabem 6 botões sem
|
|
145
|
+
* encostar: no anel de dentro 60° de passo, no de fora (raio dobrado) 30°.
|
|
146
|
+
*/
|
|
147
|
+
const ANEIS: ReadonlyArray<{ raio: number; graus: number }> = [
|
|
148
|
+
{ raio: 0, graus: 0 },
|
|
149
|
+
{ raio: 1, graus: 15 }, { raio: 1, graus: 75 },
|
|
150
|
+
{ raio: 2, graus: 10 }, { raio: 2, graus: 40 }, { raio: 2, graus: 70 }
|
|
151
|
+
];
|
|
152
|
+
const posicaoBotao = (ordem: number) => {
|
|
153
|
+
const sa = safeArea();
|
|
154
|
+
const passo = tuning.raioBotao * 2 + tuning.espacamentoBotao;
|
|
155
|
+
const baseY = innerHeight - tuning.raioBotao - tuning.margem - sa.base;
|
|
156
|
+
const baseX = noLadoDoJoystick()
|
|
157
|
+
? innerWidth - tuning.raioBotao - tuning.margem - sa.dir
|
|
158
|
+
: tuning.raioBotao + tuning.margem + sa.esq;
|
|
159
|
+
const slot = ANEIS[Math.min(Math.max(0, ordem), ANEIS.length - 1)]!;
|
|
160
|
+
const rad = (slot.graus * Math.PI) / 180;
|
|
161
|
+
// "Para dentro" é para a esquerda quando os botões estão à direita.
|
|
162
|
+
const dentro = noLadoDoJoystick() ? -1 : 1;
|
|
163
|
+
const r = slot.raio * passo;
|
|
164
|
+
return { x: baseX + dentro * Math.sin(rad) * r, y: baseY - Math.cos(rad) * r };
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const dentroDoBotao = (x: number, y: number): Acao | null => {
|
|
168
|
+
for (const b of botoes) {
|
|
169
|
+
const p = posicaoBotao(b.ordem);
|
|
170
|
+
if (Math.hypot(x - p.x, y - p.y) <= tuning.raioBotao * 1.15) return b.acao;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Região onde o joystick pode nascer: metade escolhida da tela, exceto a
|
|
177
|
+
* faixa de cima. A faixa livre é o que permite girar a câmera com QUALQUER
|
|
178
|
+
* polegar em vez de só com o direito.
|
|
179
|
+
*/
|
|
180
|
+
const podeNascerJoystick = (x: number, y: number): boolean => {
|
|
181
|
+
if (y < innerHeight * tuning.fracaoSuperiorLivre) return false;
|
|
182
|
+
return noLadoDoJoystick() ? x < innerWidth / 2 : x >= innerWidth / 2;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/** Área que pertence a este controle — o Input consulta para não girar a câmera. */
|
|
186
|
+
const ehZonaDeControle = (x: number, y: number): boolean => {
|
|
187
|
+
if (!visivel) return false;
|
|
188
|
+
if (dentroDoBotao(x, y)) return true;
|
|
189
|
+
if (tuning.flutuante) return podeNascerJoystick(x, y);
|
|
190
|
+
const a = ancoraJoystick();
|
|
191
|
+
return Math.hypot(x - a.x, y - a.y) <= tuning.raioBase * 1.25;
|
|
192
|
+
};
|
|
193
|
+
input.definirZonaDeControle(ehZonaDeControle);
|
|
194
|
+
|
|
195
|
+
// Retângulos ocupados, para o HUD escolher outro canto.
|
|
196
|
+
const calcularZonas = (): Zona[] => {
|
|
197
|
+
if (!visivel) return [];
|
|
198
|
+
const zonas: Zona[] = [];
|
|
199
|
+
|
|
200
|
+
const a = ancoraJoystick();
|
|
201
|
+
const rj = tuning.raioBase;
|
|
202
|
+
zonas.push({ x: a.x - rj, y: a.y - rj, largura: rj * 2, altura: rj * 2 });
|
|
203
|
+
|
|
204
|
+
if (botoes.length) {
|
|
205
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
206
|
+
for (const b of botoes) {
|
|
207
|
+
const p = posicaoBotao(b.ordem);
|
|
208
|
+
x0 = Math.min(x0, p.x - tuning.raioBotao);
|
|
209
|
+
y0 = Math.min(y0, p.y - tuning.raioBotao);
|
|
210
|
+
x1 = Math.max(x1, p.x + tuning.raioBotao);
|
|
211
|
+
y1 = Math.max(y1, p.y + tuning.raioBotao);
|
|
212
|
+
}
|
|
213
|
+
zonas.push({ x: x0, y: y0, largura: x1 - x0, altura: y1 - y0 });
|
|
214
|
+
}
|
|
215
|
+
return zonas;
|
|
216
|
+
};
|
|
217
|
+
registrarZonas(NOME_ZONA, calcularZonas);
|
|
218
|
+
|
|
219
|
+
const segurar = (acao: Acao) => {
|
|
220
|
+
const n = (dedosPorAcao.get(acao) ?? 0) + 1;
|
|
221
|
+
dedosPorAcao.set(acao, n);
|
|
222
|
+
if (n === 1) input.definirExterno(acao, true);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const soltar = (acao: Acao) => {
|
|
226
|
+
const n = (dedosPorAcao.get(acao) ?? 1) - 1;
|
|
227
|
+
if (n <= 0) {
|
|
228
|
+
dedosPorAcao.delete(acao);
|
|
229
|
+
input.definirExterno(acao, false);
|
|
230
|
+
} else {
|
|
231
|
+
dedosPorAcao.set(acao, n);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// ------------------------------------------------------------- eventos
|
|
236
|
+
const aoDescer = (e: PointerEvent) => {
|
|
237
|
+
if (!visivel) return;
|
|
238
|
+
// Mouse no desktop não deve acionar joystick virtual: quem tem mouse quer
|
|
239
|
+
// que o arraste gire a câmera.
|
|
240
|
+
if (e.pointerType === 'mouse') return;
|
|
241
|
+
|
|
242
|
+
const acao = dentroDoBotao(e.clientX, e.clientY);
|
|
243
|
+
if (acao) {
|
|
244
|
+
input.reservarPonteiro(e.pointerId);
|
|
245
|
+
toques.set(e.pointerId, {
|
|
246
|
+
id: e.pointerId, origemX: e.clientX, origemY: e.clientY,
|
|
247
|
+
x: e.clientX, y: e.clientY, alvo: acao
|
|
248
|
+
});
|
|
249
|
+
segurar(acao);
|
|
250
|
+
vibrar(8);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!podeNascerJoystick(e.clientX, e.clientY)) return;
|
|
254
|
+
|
|
255
|
+
input.reservarPonteiro(e.pointerId);
|
|
256
|
+
const origem = tuning.flutuante ? { x: e.clientX, y: e.clientY } : ancoraJoystick();
|
|
257
|
+
toques.set(e.pointerId, {
|
|
258
|
+
id: e.pointerId, origemX: origem.x, origemY: origem.y,
|
|
259
|
+
x: e.clientX, y: e.clientY, alvo: 'joystick'
|
|
260
|
+
});
|
|
261
|
+
// Joystick fixo já responde ao primeiro contato, sem esperar o arraste.
|
|
262
|
+
if (!tuning.flutuante) atualizarEixo(toques.get(e.pointerId)!);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const aoMover = (e: PointerEvent) => {
|
|
266
|
+
const t = toques.get(e.pointerId);
|
|
267
|
+
if (!t || t.alvo !== 'joystick') return;
|
|
268
|
+
t.x = e.clientX;
|
|
269
|
+
t.y = e.clientY;
|
|
270
|
+
atualizarEixo(t);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const aoSubir = (e: PointerEvent) => {
|
|
274
|
+
const t = toques.get(e.pointerId);
|
|
275
|
+
if (!t) return;
|
|
276
|
+
if (t.alvo === 'joystick') {
|
|
277
|
+
input.eixoVirtual.x = 0;
|
|
278
|
+
input.eixoVirtual.y = 0;
|
|
279
|
+
} else {
|
|
280
|
+
soltar(t.alvo);
|
|
281
|
+
}
|
|
282
|
+
toques.delete(e.pointerId);
|
|
283
|
+
input.liberarPonteiro(e.pointerId);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const atualizarEixo = (t: Toque) => {
|
|
287
|
+
const dx = t.x - t.origemX;
|
|
288
|
+
const dy = t.y - t.origemY;
|
|
289
|
+
const dist = Math.hypot(dx, dy);
|
|
290
|
+
if (dist < tuning.raioBase * tuning.zonaMorta) {
|
|
291
|
+
input.eixoVirtual.x = 0;
|
|
292
|
+
input.eixoVirtual.y = 0;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
// Normaliza pelo raio e satura em 1 — puxar além da base não anda mais rápido.
|
|
296
|
+
const forca = Math.min(1, dist / tuning.raioBase);
|
|
297
|
+
input.eixoVirtual.x = (dx / dist) * forca;
|
|
298
|
+
input.eixoVirtual.y = (dy / dist) * forca;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const vibrar = (ms: number) => {
|
|
302
|
+
if (!tuning.vibrar) return;
|
|
303
|
+
if (typeof navigator !== 'undefined' && navigator.vibrate) navigator.vibrate(ms);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
canvasJogo.addEventListener('pointerdown', aoDescer);
|
|
307
|
+
canvasJogo.addEventListener('pointermove', aoMover);
|
|
308
|
+
canvasJogo.addEventListener('pointerup', aoSubir);
|
|
309
|
+
canvasJogo.addEventListener('pointercancel', aoSubir);
|
|
310
|
+
// O dedo pode subir fora do canvas (arrastou para a barra de status).
|
|
311
|
+
addEventListener('pointerup', aoSubir);
|
|
312
|
+
addEventListener('pointercancel', aoSubir);
|
|
313
|
+
|
|
314
|
+
// ------------------------------------------------------------- desenho
|
|
315
|
+
const desenhar = (): void => {
|
|
316
|
+
ctx.clearRect(0, 0, innerWidth, innerHeight);
|
|
317
|
+
if (!visivel) return;
|
|
318
|
+
const p = getPalette();
|
|
319
|
+
|
|
320
|
+
// Joystick: só aparece quando o dedo está nele, se for flutuante.
|
|
321
|
+
const tJoy = [...toques.values()].find((t) => t.alvo === 'joystick');
|
|
322
|
+
if (tJoy || !tuning.flutuante) {
|
|
323
|
+
const ancora = ancoraJoystick();
|
|
324
|
+
const cx = tJoy ? tJoy.origemX : ancora.x;
|
|
325
|
+
const cy = tJoy ? tJoy.origemY : ancora.y;
|
|
326
|
+
|
|
327
|
+
anel(cx, cy, tuning.raioBase, p.contorno, tuning.opacidade);
|
|
328
|
+
|
|
329
|
+
let mx = cx, my = cy;
|
|
330
|
+
if (tJoy) {
|
|
331
|
+
const dx = tJoy.x - cx, dy = tJoy.y - cy;
|
|
332
|
+
const d = Math.hypot(dx, dy);
|
|
333
|
+
const lim = Math.min(d, tuning.raioBase);
|
|
334
|
+
if (d > 0) { mx = cx + (dx / d) * lim; my = cy + (dy / d) * lim; }
|
|
335
|
+
}
|
|
336
|
+
disco(mx, my, tuning.raioManete, p.primaria, tJoy ? tuning.opacidadeAtiva : tuning.opacidade);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Botões
|
|
340
|
+
for (const b of botoes) {
|
|
341
|
+
const pos = posicaoBotao(b.ordem);
|
|
342
|
+
const ativo = (dedosPorAcao.get(b.acao) ?? 0) > 0;
|
|
343
|
+
disco(pos.x, pos.y, tuning.raioBotao, ativo ? p.acento : p.superficie,
|
|
344
|
+
ativo ? tuning.opacidadeAtiva : tuning.opacidade);
|
|
345
|
+
anel(pos.x, pos.y, tuning.raioBotao, p.contorno, tuning.opacidade + 0.15);
|
|
346
|
+
|
|
347
|
+
ctx.fillStyle = alpha(p.texto, 0.85);
|
|
348
|
+
// Rótulo de palavra ("FOGO", "MIRA") encolhe para caber no círculo.
|
|
349
|
+
const escala = b.rotulo.length > 2 ? 0.4 : 0.62;
|
|
350
|
+
ctx.font = `bold ${tuning.raioBotao * escala}px system-ui, sans-serif`;
|
|
351
|
+
ctx.textAlign = 'center';
|
|
352
|
+
ctx.textBaseline = 'middle';
|
|
353
|
+
ctx.fillText(b.rotulo, pos.x, pos.y + 1);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
const disco = (x: number, y: number, r: number, cor: string, a: number) => {
|
|
358
|
+
ctx.beginPath();
|
|
359
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
360
|
+
ctx.fillStyle = alpha(cor, a);
|
|
361
|
+
ctx.fill();
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const anel = (x: number, y: number, r: number, cor: string, a: number) => {
|
|
365
|
+
ctx.beginPath();
|
|
366
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
367
|
+
ctx.strokeStyle = alpha(cor, a);
|
|
368
|
+
ctx.lineWidth = 2.5;
|
|
369
|
+
ctx.stroke();
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const largarTudo = () => {
|
|
373
|
+
input.eixoVirtual.x = 0;
|
|
374
|
+
input.eixoVirtual.y = 0;
|
|
375
|
+
for (const t of toques.values()) {
|
|
376
|
+
if (t.alvo !== 'joystick') soltar(t.alvo);
|
|
377
|
+
input.liberarPonteiro(t.id);
|
|
378
|
+
}
|
|
379
|
+
toques.clear();
|
|
380
|
+
dedosPorAcao.clear();
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
desenhar,
|
|
385
|
+
get visivel() { return visivel; },
|
|
386
|
+
set visivel(v: boolean) {
|
|
387
|
+
visivel = v;
|
|
388
|
+
if (!v) {
|
|
389
|
+
largarTudo();
|
|
390
|
+
ctx.clearRect(0, 0, innerWidth, innerHeight);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
dispose() {
|
|
394
|
+
largarTudo();
|
|
395
|
+
canvasJogo.removeEventListener('pointerdown', aoDescer);
|
|
396
|
+
canvasJogo.removeEventListener('pointermove', aoMover);
|
|
397
|
+
canvasJogo.removeEventListener('pointerup', aoSubir);
|
|
398
|
+
canvasJogo.removeEventListener('pointercancel', aoSubir);
|
|
399
|
+
removeEventListener('pointerup', aoSubir);
|
|
400
|
+
removeEventListener('pointercancel', aoSubir);
|
|
401
|
+
removeEventListener('resize', redimensionar);
|
|
402
|
+
removerZonas(NOME_ZONA);
|
|
403
|
+
input.definirZonaDeControle(null);
|
|
404
|
+
canvas.remove();
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"categoria": "game",
|
|
3
|
+
"framework": "three",
|
|
4
|
+
"linguagem": "typescript",
|
|
5
|
+
"compatibilidade": {
|
|
6
|
+
"banco": [],
|
|
7
|
+
"auth": []
|
|
8
|
+
},
|
|
9
|
+
"versao": "2.1.0",
|
|
10
|
+
"id": "adapt-controle-toque-01",
|
|
11
|
+
"nome": "Adaptação: Controle por Toque (mobile)",
|
|
12
|
+
"dependencias": [],
|
|
13
|
+
"tags": [
|
|
14
|
+
"game",
|
|
15
|
+
"jogo",
|
|
16
|
+
"controle",
|
|
17
|
+
"toque",
|
|
18
|
+
"touch",
|
|
19
|
+
"mobile",
|
|
20
|
+
"celular",
|
|
21
|
+
"joystick",
|
|
22
|
+
"analogico",
|
|
23
|
+
"botao",
|
|
24
|
+
"virtual",
|
|
25
|
+
"adaptacao"
|
|
26
|
+
],
|
|
27
|
+
"recursos_suportados": [
|
|
28
|
+
"joystick-virtual",
|
|
29
|
+
"botoes-de-acao",
|
|
30
|
+
"multi-toque",
|
|
31
|
+
"zona-morta",
|
|
32
|
+
"safe-area",
|
|
33
|
+
"joystick-flutuante",
|
|
34
|
+
"reserva-de-dedo",
|
|
35
|
+
"zona-de-olhar-separada",
|
|
36
|
+
"registro-de-zonas-para-o-hud",
|
|
37
|
+
"contagem-de-dedos-por-botao",
|
|
38
|
+
"canhoto",
|
|
39
|
+
"ate-6-botoes-sem-sobreposicao",
|
|
40
|
+
"rotulo-que-cabe-no-botao"
|
|
41
|
+
],
|
|
42
|
+
"descricao": "OBRIGATÓRIA em jogo mobile. Joystick virtual analógico + botões de ação desenhados em canvas próprio (não DOM, não trava o jogo). Multi-toque real: mover e atirar ao mesmo tempo. Modo flutuante (o joystick nasce onde o dedo encostou), zona morta configurável, layout para canhoto e safe-area medido de verdade. Divide a tela com a câmera do jeito certo: RESERVA no engine o dedo que está num controle e DECLARA a área que ocupa, então metade da tela anda e a outra metade olha — sem isso, arrastar o joystick girava a câmera junto. Também REGISTRA seus retângulos no layout do engine, que é como o HUD descobre que não pode pôr o minimapa em cima dos botões. Escreve direto no Input do engine, então o gameplay não sabe que é toque. Até 6 botões em dois anéis em volta do principal, sem sobreposição (antes, do 3º em diante os botões se encavalavam e o 4º saía pela borda) — o FPS usa 4: FOGO, MIRA, R e trocar arma."
|
|
43
|
+
}
|