@muvtacode/cli 0.1.0
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/README.md +147 -0
- package/bin/muvta.js +25 -0
- package/dist/agent/bg.js +118 -0
- package/dist/agent/bg.js.map +1 -0
- package/dist/agent/changes.js +180 -0
- package/dist/agent/changes.js.map +1 -0
- package/dist/agent/compaction.js +83 -0
- package/dist/agent/compaction.js.map +1 -0
- package/dist/agent/loop.js +185 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/permissions.js +136 -0
- package/dist/agent/permissions.js.map +1 -0
- package/dist/agent/plan.js +34 -0
- package/dist/agent/plan.js.map +1 -0
- package/dist/agent/prompt.js +114 -0
- package/dist/agent/prompt.js.map +1 -0
- package/dist/agent/roles.js +10 -0
- package/dist/agent/roles.js.map +1 -0
- package/dist/agent/router.js +107 -0
- package/dist/agent/router.js.map +1 -0
- package/dist/agent/subagents.js +173 -0
- package/dist/agent/subagents.js.map +1 -0
- package/dist/agent/tools.js +656 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/verify.js +102 -0
- package/dist/agent/verify.js.map +1 -0
- package/dist/api/client.js +149 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/devices.js +17 -0
- package/dist/api/devices.js.map +1 -0
- package/dist/api/me.js +144 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/prefs.js +99 -0
- package/dist/api/prefs.js.map +1 -0
- package/dist/api/sessions.js +68 -0
- package/dist/api/sessions.js.map +1 -0
- package/dist/api/sse.js +122 -0
- package/dist/api/sse.js.map +1 -0
- package/dist/auth/device.js +116 -0
- package/dist/auth/device.js.map +1 -0
- package/dist/auth/store.js +86 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/cli.js +419 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/context.js +207 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/expose.js +98 -0
- package/dist/commands/expose.js.map +1 -0
- package/dist/commands/index.js +743 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/i18n/en.js +246 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.js +81 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/pt.js +245 -0
- package/dist/i18n/pt.js.map +1 -0
- package/dist/models/catalog.js +98 -0
- package/dist/models/catalog.js.map +1 -0
- package/dist/providers/direct.js +251 -0
- package/dist/providers/direct.js.map +1 -0
- package/dist/providers/index.js +112 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/kiro.js +31 -0
- package/dist/providers/kiro.js.map +1 -0
- package/dist/providers/muvta.js +27 -0
- package/dist/providers/muvta.js.map +1 -0
- package/dist/providers/types.js +4 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/repl.js +398 -0
- package/dist/repl.js.map +1 -0
- package/dist/state/config.js +66 -0
- package/dist/state/config.js.map +1 -0
- package/dist/state/keys.js +69 -0
- package/dist/state/keys.js.map +1 -0
- package/dist/state/project.js +41 -0
- package/dist/state/project.js.map +1 -0
- package/dist/state/session.js +87 -0
- package/dist/state/session.js.map +1 -0
- package/dist/state/skills.js +60 -0
- package/dist/state/skills.js.map +1 -0
- package/dist/state/stats.js +95 -0
- package/dist/state/stats.js.map +1 -0
- package/dist/state/templates.js +232 -0
- package/dist/state/templates.js.map +1 -0
- package/dist/templates/backend/auth-jwt-express-01/files/server/auth/authMiddleware.js +21 -0
- package/dist/templates/backend/auth-jwt-express-01/files/server/auth/authRoutes.js +59 -0
- package/dist/templates/backend/auth-jwt-express-01/files/server/db/database.js +46 -0
- package/dist/templates/backend/auth-jwt-express-01/meta.json +13 -0
- package/dist/templates/backend/crud-express-01/files/server/crud/createCrudRouter.js +130 -0
- package/dist/templates/backend/crud-express-01/files/server/db/database.js +46 -0
- package/dist/templates/backend/crud-express-01/meta.json +13 -0
- package/dist/templates/backend/crud-fastapi-01/files/api/main.py +146 -0
- package/dist/templates/backend/crud-fastapi-01/files/api/requirements.txt +3 -0
- package/dist/templates/backend/crud-fastapi-01/meta.json +13 -0
- package/dist/templates/backend/multiplayer-ws-01/files/server/index.js +97 -0
- package/dist/templates/backend/multiplayer-ws-01/files/server/package.json +13 -0
- package/dist/templates/backend/multiplayer-ws-01/files/server/public/index.html +130 -0
- package/dist/templates/backend/multiplayer-ws-01/meta.json +13 -0
- package/dist/templates/backend/server-express-base-01/files/server/.env.example +3 -0
- package/dist/templates/backend/server-express-base-01/files/server/index.js +28 -0
- package/dist/templates/backend/server-express-base-01/files/server/package.json +15 -0
- package/dist/templates/backend/server-express-base-01/meta.json +13 -0
- package/dist/templates/backend/upload-express-01/files/server/upload/uploadRoutes.js +72 -0
- package/dist/templates/backend/upload-express-01/meta.json +13 -0
- package/dist/templates/frontend/accordion-01/files/src/components/accordion/Accordion.css +57 -0
- package/dist/templates/frontend/accordion-01/files/src/components/accordion/Accordion.tsx +52 -0
- package/dist/templates/frontend/accordion-01/meta.json +13 -0
- package/dist/templates/frontend/agendamento-01/files/src/components/schedule/Scheduler.css +86 -0
- package/dist/templates/frontend/agendamento-01/files/src/components/schedule/Scheduler.tsx +100 -0
- package/dist/templates/frontend/agendamento-01/meta.json +13 -0
- package/dist/templates/frontend/app-react-base-01/files/index.html +15 -0
- package/dist/templates/frontend/app-react-base-01/files/package.json +23 -0
- package/dist/templates/frontend/app-react-base-01/files/src/App.tsx +17 -0
- package/dist/templates/frontend/app-react-base-01/files/src/main.tsx +14 -0
- package/dist/templates/frontend/app-react-base-01/files/tsconfig.json +19 -0
- package/dist/templates/frontend/app-react-base-01/files/vite.config.ts +10 -0
- package/dist/templates/frontend/app-react-base-01/meta.json +13 -0
- package/dist/templates/frontend/arvore-01/files/src/components/tree/TreeView.css +50 -0
- package/dist/templates/frontend/arvore-01/files/src/components/tree/TreeView.tsx +96 -0
- package/dist/templates/frontend/arvore-01/meta.json +13 -0
- package/dist/templates/frontend/bottomsheet-01/files/src/components/bottomsheet/BottomSheet.css +76 -0
- package/dist/templates/frontend/bottomsheet-01/files/src/components/bottomsheet/BottomSheet.tsx +94 -0
- package/dist/templates/frontend/bottomsheet-01/meta.json +13 -0
- package/dist/templates/frontend/cadastro-01/files/src/pages/auth/RegisterPage.css +166 -0
- package/dist/templates/frontend/cadastro-01/files/src/pages/auth/RegisterPage.tsx +132 -0
- package/dist/templates/frontend/cadastro-01/meta.json +13 -0
- package/dist/templates/frontend/caixa-01/files/src/components/box/Box.css +33 -0
- package/dist/templates/frontend/caixa-01/files/src/components/box/Box.tsx +35 -0
- package/dist/templates/frontend/caixa-01/meta.json +13 -0
- package/dist/templates/frontend/calendario-01/files/src/components/calendar/MonthCalendar.css +75 -0
- package/dist/templates/frontend/calendario-01/files/src/components/calendar/MonthCalendar.tsx +92 -0
- package/dist/templates/frontend/calendario-01/meta.json +13 -0
- package/dist/templates/frontend/cards-stats-01/files/src/components/dashboard/StatsCards.css +98 -0
- package/dist/templates/frontend/cards-stats-01/files/src/components/dashboard/StatsCards.tsx +63 -0
- package/dist/templates/frontend/cards-stats-01/meta.json +13 -0
- package/dist/templates/frontend/carrossel-01/files/src/components/carousel/Carousel.css +73 -0
- package/dist/templates/frontend/carrossel-01/files/src/components/carousel/Carousel.tsx +75 -0
- package/dist/templates/frontend/carrossel-01/meta.json +13 -0
- package/dist/templates/frontend/chat-ui-01/files/src/components/chat/ChatUI.css +159 -0
- package/dist/templates/frontend/chat-ui-01/files/src/components/chat/ChatUI.tsx +183 -0
- package/dist/templates/frontend/chat-ui-01/meta.json +13 -0
- package/dist/templates/frontend/checkout-01/files/src/components/checkout/Checkout.css +89 -0
- package/dist/templates/frontend/checkout-01/files/src/components/checkout/Checkout.tsx +264 -0
- package/dist/templates/frontend/checkout-01/meta.json +13 -0
- package/dist/templates/frontend/command-palette-01/files/src/components/command-palette/CommandPalette.css +104 -0
- package/dist/templates/frontend/command-palette-01/files/src/components/command-palette/CommandPalette.tsx +177 -0
- package/dist/templates/frontend/command-palette-01/meta.json +13 -0
- package/dist/templates/frontend/dashboard-admin-01/files/src/components/charts/BarChart.css +34 -0
- package/dist/templates/frontend/dashboard-admin-01/files/src/components/charts/BarChart.tsx +58 -0
- package/dist/templates/frontend/dashboard-admin-01/files/src/pages/dashboard/DashboardLayout.css +68 -0
- package/dist/templates/frontend/dashboard-admin-01/files/src/pages/dashboard/DashboardLayout.tsx +52 -0
- package/dist/templates/frontend/dashboard-admin-01/meta.json +13 -0
- package/dist/templates/frontend/design-system-01/files/src/styles/tokens.css +337 -0
- package/dist/templates/frontend/design-system-01/files/src/theme/ThemeProvider.tsx +42 -0
- package/dist/templates/frontend/design-system-01/files/src/theme/ThemeToggle.tsx +18 -0
- package/dist/templates/frontend/design-system-01/meta.json +13 -0
- package/dist/templates/frontend/drawer-01/files/src/components/drawer/Drawer.css +92 -0
- package/dist/templates/frontend/drawer-01/files/src/components/drawer/Drawer.tsx +48 -0
- package/dist/templates/frontend/drawer-01/meta.json +13 -0
- package/dist/templates/frontend/editor-richtext-01/files/src/components/editor/RichTextEditor.css +84 -0
- package/dist/templates/frontend/editor-richtext-01/files/src/components/editor/RichTextEditor.tsx +135 -0
- package/dist/templates/frontend/editor-richtext-01/meta.json +13 -0
- package/dist/templates/frontend/footer-01/files/src/components/layout/Footer.css +141 -0
- package/dist/templates/frontend/footer-01/files/src/components/layout/Footer.tsx +128 -0
- package/dist/templates/frontend/footer-01/meta.json +13 -0
- package/dist/templates/frontend/game-canvas-01/files/index.html +17 -0
- package/dist/templates/frontend/game-canvas-01/files/src/game.js +185 -0
- package/dist/templates/frontend/game-canvas-01/meta.json +13 -0
- package/dist/templates/frontend/game-phaser-01/files/index.html +42 -0
- package/dist/templates/frontend/game-phaser-01/files/src/game.js +158 -0
- package/dist/templates/frontend/game-phaser-01/meta.json +13 -0
- package/dist/templates/frontend/game-r3f-01/files/src/components/game3d/GameScene.css +67 -0
- package/dist/templates/frontend/game-r3f-01/files/src/components/game3d/GameScene.tsx +133 -0
- package/dist/templates/frontend/game-r3f-01/meta.json +13 -0
- package/dist/templates/frontend/game-threejs-01/files/index.html +71 -0
- package/dist/templates/frontend/game-threejs-01/files/src/game.js +214 -0
- package/dist/templates/frontend/game-threejs-01/meta.json +13 -0
- package/dist/templates/frontend/grafico-linha-01/files/src/components/charts/LineChart.css +46 -0
- package/dist/templates/frontend/grafico-linha-01/files/src/components/charts/LineChart.tsx +57 -0
- package/dist/templates/frontend/grafico-linha-01/meta.json +13 -0
- package/dist/templates/frontend/kanban-01/files/src/components/kanban/Kanban.css +107 -0
- package/dist/templates/frontend/kanban-01/files/src/components/kanban/Kanban.tsx +157 -0
- package/dist/templates/frontend/kanban-01/meta.json +13 -0
- package/dist/templates/frontend/landing-01/files/src/pages/landing/LandingPage.css +201 -0
- package/dist/templates/frontend/landing-01/files/src/pages/landing/LandingPage.tsx +117 -0
- package/dist/templates/frontend/landing-01/meta.json +13 -0
- package/dist/templates/frontend/landing-02/files/src/pages/landing/LandingPricing.css +147 -0
- package/dist/templates/frontend/landing-02/files/src/pages/landing/LandingPricing.tsx +71 -0
- package/dist/templates/frontend/landing-02/meta.json +13 -0
- package/dist/templates/frontend/landing-03/files/src/pages/landing/LandingProduct.css +178 -0
- package/dist/templates/frontend/landing-03/files/src/pages/landing/LandingProduct.tsx +113 -0
- package/dist/templates/frontend/landing-03/meta.json +13 -0
- package/dist/templates/frontend/landing-04/files/src/pages/landing/LandingConversion.css +179 -0
- package/dist/templates/frontend/landing-04/files/src/pages/landing/LandingConversion.tsx +120 -0
- package/dist/templates/frontend/landing-04/meta.json +13 -0
- package/dist/templates/frontend/login-01/files/src/pages/auth/LoginPage.css +155 -0
- package/dist/templates/frontend/login-01/files/src/pages/auth/LoginPage.tsx +125 -0
- package/dist/templates/frontend/login-01/meta.json +13 -0
- package/dist/templates/frontend/mapa-01/files/src/components/map/MapView.css +52 -0
- package/dist/templates/frontend/mapa-01/files/src/components/map/MapView.tsx +147 -0
- package/dist/templates/frontend/mapa-01/meta.json +13 -0
- package/dist/templates/frontend/modal-01/files/src/components/modal/Modal.css +82 -0
- package/dist/templates/frontend/modal-01/files/src/components/modal/Modal.tsx +95 -0
- package/dist/templates/frontend/modal-01/meta.json +13 -0
- package/dist/templates/frontend/navbar-01/files/src/components/nav/Navbar.css +159 -0
- package/dist/templates/frontend/navbar-01/files/src/components/nav/Navbar.tsx +127 -0
- package/dist/templates/frontend/navbar-01/meta.json +13 -0
- package/dist/templates/frontend/notificacoes-01/files/src/components/notifications/NotificationCenter.css +117 -0
- package/dist/templates/frontend/notificacoes-01/files/src/components/notifications/NotificationCenter.tsx +136 -0
- package/dist/templates/frontend/notificacoes-01/meta.json +13 -0
- package/dist/templates/frontend/onboarding-tour-01/files/src/components/tour/OnboardingTour.css +76 -0
- package/dist/templates/frontend/onboarding-tour-01/files/src/components/tour/OnboardingTour.tsx +130 -0
- package/dist/templates/frontend/onboarding-tour-01/meta.json +13 -0
- package/dist/templates/frontend/pagina-404-01/files/src/pages/errors/ErrorPage.css +56 -0
- package/dist/templates/frontend/pagina-404-01/files/src/pages/errors/ErrorPage.tsx +32 -0
- package/dist/templates/frontend/pagina-404-01/meta.json +13 -0
- package/dist/templates/frontend/perfil-01/files/src/components/profile/ProfilePage.css +81 -0
- package/dist/templates/frontend/perfil-01/files/src/components/profile/ProfilePage.tsx +206 -0
- package/dist/templates/frontend/perfil-01/meta.json +13 -0
- package/dist/templates/frontend/pwa-01/files/public/manifest.webmanifest +32 -0
- package/dist/templates/frontend/pwa-01/files/public/sw.js +86 -0
- package/dist/templates/frontend/pwa-01/files/src/pwa/registerSW.ts +69 -0
- package/dist/templates/frontend/pwa-01/meta.json +13 -0
- package/dist/templates/frontend/relatorio-01/files/src/components/report/ReportPage.css +119 -0
- package/dist/templates/frontend/relatorio-01/files/src/components/report/ReportPage.tsx +93 -0
- package/dist/templates/frontend/relatorio-01/meta.json +13 -0
- package/dist/templates/frontend/section-01/files/src/components/layout/Section.css +39 -0
- package/dist/templates/frontend/section-01/files/src/components/layout/Section.tsx +29 -0
- package/dist/templates/frontend/section-01/meta.json +13 -0
- package/dist/templates/frontend/sidebar-01/files/src/components/layout/Sidebar.css +120 -0
- package/dist/templates/frontend/sidebar-01/files/src/components/layout/Sidebar.tsx +58 -0
- package/dist/templates/frontend/sidebar-01/meta.json +13 -0
- package/dist/templates/frontend/skeleton-01/files/src/components/loading/Loading.css +48 -0
- package/dist/templates/frontend/skeleton-01/files/src/components/loading/Loading.tsx +39 -0
- package/dist/templates/frontend/skeleton-01/meta.json +13 -0
- package/dist/templates/frontend/streaming-01/files/src/components/streaming/MediaRow.css +233 -0
- package/dist/templates/frontend/streaming-01/files/src/components/streaming/MediaRow.tsx +159 -0
- package/dist/templates/frontend/streaming-01/files/src/components/streaming/VideoPlayer.css +156 -0
- package/dist/templates/frontend/streaming-01/files/src/components/streaming/VideoPlayer.tsx +199 -0
- package/dist/templates/frontend/streaming-01/files/src/pages/streaming/StreamingHome.css +257 -0
- package/dist/templates/frontend/streaming-01/files/src/pages/streaming/StreamingHome.tsx +173 -0
- package/dist/templates/frontend/streaming-01/files/src/pages/streaming/TitleDetails.css +138 -0
- package/dist/templates/frontend/streaming-01/files/src/pages/streaming/TitleDetails.tsx +122 -0
- package/dist/templates/frontend/streaming-01/meta.json +13 -0
- package/dist/templates/frontend/tabela-premium-01/files/src/components/table/DataTable.css +154 -0
- package/dist/templates/frontend/tabela-premium-01/files/src/components/table/DataTable.tsx +227 -0
- package/dist/templates/frontend/tabela-premium-01/meta.json +13 -0
- package/dist/templates/frontend/tabs-01/files/src/components/tabs/Tabs.css +52 -0
- package/dist/templates/frontend/tabs-01/files/src/components/tabs/Tabs.tsx +47 -0
- package/dist/templates/frontend/tabs-01/meta.json +13 -0
- package/dist/templates/frontend/timeline-01/files/src/components/timeline/Timeline.css +63 -0
- package/dist/templates/frontend/timeline-01/files/src/components/timeline/Timeline.tsx +37 -0
- package/dist/templates/frontend/timeline-01/meta.json +13 -0
- package/dist/templates/frontend/toast-01/files/src/components/toast/Toast.css +75 -0
- package/dist/templates/frontend/toast-01/files/src/components/toast/ToastProvider.tsx +74 -0
- package/dist/templates/frontend/toast-01/meta.json +13 -0
- package/dist/templates/frontend/topbar-01/files/src/components/layout/Topbar.css +118 -0
- package/dist/templates/frontend/topbar-01/files/src/components/layout/Topbar.tsx +57 -0
- package/dist/templates/frontend/topbar-01/meta.json +13 -0
- package/dist/templates/frontend/topbar-submenu-01/files/src/components/nav/TopbarSubmenu.css +133 -0
- package/dist/templates/frontend/topbar-submenu-01/files/src/components/nav/TopbarSubmenu.tsx +94 -0
- package/dist/templates/frontend/topbar-submenu-01/meta.json +13 -0
- package/dist/templates/frontend/upload-ui-01/files/src/components/upload/FileUpload.css +90 -0
- package/dist/templates/frontend/upload-ui-01/files/src/components/upload/FileUpload.tsx +178 -0
- package/dist/templates/frontend/upload-ui-01/meta.json +13 -0
- package/dist/templates/frontend/video-player-01/files/src/components/video/VideoPlayer.css +114 -0
- package/dist/templates/frontend/video-player-01/files/src/components/video/VideoPlayer.tsx +221 -0
- package/dist/templates/frontend/video-player-01/meta.json +13 -0
- package/dist/templates/frontend/wizard-01/files/src/components/wizard/Wizard.css +75 -0
- package/dist/templates/frontend/wizard-01/files/src/components/wizard/Wizard.tsx +70 -0
- package/dist/templates/frontend/wizard-01/meta.json +13 -0
- package/dist/ui/devicesView.js +115 -0
- package/dist/ui/devicesView.js.map +1 -0
- package/dist/ui/prompt.js +182 -0
- package/dist/ui/prompt.js.map +1 -0
- package/dist/ui/views.js +202 -0
- package/dist/ui/views.js.map +1 -0
- package/dist/update.js +96 -0
- package/dist/update.js.map +1 -0
- package/dist/util/ansi.js +75 -0
- package/dist/util/ansi.js.map +1 -0
- package/dist/util/fmt.js +53 -0
- package/dist/util/fmt.js.map +1 -0
- package/dist/util/log.js +58 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/paths.js +108 -0
- package/dist/util/paths.js.map +1 -0
- package/dist/util/redact.js +43 -0
- package/dist/util/redact.js.map +1 -0
- package/dist/util/shell.js +67 -0
- package/dist/util/shell.js.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/wizard.js +79 -0
- package/dist/wizard.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// "Desvie!" — jogo 2D arcade em Canvas puro (sem dependências, sem build).
|
|
2
|
+
// Desvie dos blocos que caem; a velocidade aumenta com o tempo. Teclado
|
|
3
|
+
// (←/→ ou A/D, Espaço pausa, Enter reinicia) e toque (arraste; toque reinicia).
|
|
4
|
+
//
|
|
5
|
+
// Arquitetura (reaproveite em qualquer jogo 2D):
|
|
6
|
+
// - Loop com PASSO FIXO (update a 60 Hz constantes + render por frame):
|
|
7
|
+
// física idêntica em celular fraco ou monitor de 144 Hz.
|
|
8
|
+
// - Canvas redimensionado com devicePixelRatio (nítido em qualquer tela).
|
|
9
|
+
// - Estados: "playing" | "paused" | "over".
|
|
10
|
+
(() => {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const canvas = document.getElementById('game');
|
|
14
|
+
const ctx = canvas.getContext('2d');
|
|
15
|
+
|
|
16
|
+
// ------------------------------------------------------------------
|
|
17
|
+
// Resize nítido (DPR) — coordenadas do jogo ficam em pixels CSS
|
|
18
|
+
// ------------------------------------------------------------------
|
|
19
|
+
let W = 0, H = 0;
|
|
20
|
+
function resize() {
|
|
21
|
+
const dpr = Math.min(devicePixelRatio || 1, 2);
|
|
22
|
+
W = canvas.clientWidth = innerWidth;
|
|
23
|
+
H = canvas.clientHeight = innerHeight;
|
|
24
|
+
canvas.width = Math.round(W * dpr);
|
|
25
|
+
canvas.height = Math.round(H * dpr);
|
|
26
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
27
|
+
}
|
|
28
|
+
addEventListener('resize', resize);
|
|
29
|
+
resize();
|
|
30
|
+
|
|
31
|
+
// ------------------------------------------------------------------
|
|
32
|
+
// Estado do jogo
|
|
33
|
+
// ------------------------------------------------------------------
|
|
34
|
+
const PLAYER = { w: 46, h: 46, speed: 420 }; // velocidade em px/s
|
|
35
|
+
let state, player, blocks, score, best, time, spawnTimer;
|
|
36
|
+
best = Number(localStorage.getItem('desvie_best') || 0);
|
|
37
|
+
|
|
38
|
+
function reset() {
|
|
39
|
+
state = 'playing';
|
|
40
|
+
player = { x: W / 2 - PLAYER.w / 2, y: H - PLAYER.h - Math.max(24, H * 0.06), vx: 0 };
|
|
41
|
+
blocks = [];
|
|
42
|
+
score = 0;
|
|
43
|
+
time = 0;
|
|
44
|
+
spawnTimer = 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ------------------------------------------------------------------
|
|
48
|
+
// Entrada: teclado + arrastar no toque
|
|
49
|
+
// ------------------------------------------------------------------
|
|
50
|
+
const keys = { left: false, right: false };
|
|
51
|
+
addEventListener('keydown', (e) => {
|
|
52
|
+
const k = e.key.toLowerCase();
|
|
53
|
+
if (k === 'arrowleft' || k === 'a') keys.left = true;
|
|
54
|
+
if (k === 'arrowright' || k === 'd') keys.right = true;
|
|
55
|
+
if (k === ' ' && state !== 'over') state = state === 'paused' ? 'playing' : 'paused';
|
|
56
|
+
if (k === 'enter' && state === 'over') reset();
|
|
57
|
+
});
|
|
58
|
+
addEventListener('keyup', (e) => {
|
|
59
|
+
const k = e.key.toLowerCase();
|
|
60
|
+
if (k === 'arrowleft' || k === 'a') keys.left = false;
|
|
61
|
+
if (k === 'arrowright' || k === 'd') keys.right = false;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
let touchX = null; // alvo horizontal do dedo (o player persegue)
|
|
65
|
+
canvas.addEventListener('pointerdown', (e) => {
|
|
66
|
+
if (state === 'over') { reset(); return; }
|
|
67
|
+
touchX = e.clientX;
|
|
68
|
+
});
|
|
69
|
+
canvas.addEventListener('pointermove', (e) => { if (touchX !== null) touchX = e.clientX; });
|
|
70
|
+
addEventListener('pointerup', () => { touchX = null; });
|
|
71
|
+
addEventListener('pointercancel', () => { touchX = null; });
|
|
72
|
+
|
|
73
|
+
// ------------------------------------------------------------------
|
|
74
|
+
// Update (passo fixo de 1/60 s)
|
|
75
|
+
// ------------------------------------------------------------------
|
|
76
|
+
const STEP = 1 / 60;
|
|
77
|
+
|
|
78
|
+
function update(dt) {
|
|
79
|
+
time += dt;
|
|
80
|
+
score = Math.floor(time * 10); // 10 pontos por segundo vivo
|
|
81
|
+
|
|
82
|
+
// Player: teclado tem prioridade; senão persegue o dedo
|
|
83
|
+
let dir = (keys.right ? 1 : 0) - (keys.left ? 1 : 0);
|
|
84
|
+
if (dir === 0 && touchX !== null) {
|
|
85
|
+
const center = player.x + PLAYER.w / 2;
|
|
86
|
+
if (Math.abs(touchX - center) > 6) dir = touchX > center ? 1 : -1;
|
|
87
|
+
}
|
|
88
|
+
player.x += dir * PLAYER.speed * dt;
|
|
89
|
+
player.x = Math.max(0, Math.min(W - PLAYER.w, player.x));
|
|
90
|
+
|
|
91
|
+
// Dificuldade progressiva: cai mais rápido e nasce mais bloco com o tempo
|
|
92
|
+
const fallSpeed = 180 + time * 14;
|
|
93
|
+
const spawnEvery = Math.max(0.18, 0.85 - time * 0.02);
|
|
94
|
+
|
|
95
|
+
spawnTimer -= dt;
|
|
96
|
+
if (spawnTimer <= 0) {
|
|
97
|
+
spawnTimer = spawnEvery;
|
|
98
|
+
const w = 30 + Math.random() * 70;
|
|
99
|
+
blocks.push({ x: Math.random() * (W - w), y: -60, w, h: 22 + Math.random() * 26, hue: 340 + Math.random() * 60 });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Blocos: caem; removem ao sair da tela; colisão AABB encerra o jogo
|
|
103
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
104
|
+
const b = blocks[i];
|
|
105
|
+
b.y += fallSpeed * dt;
|
|
106
|
+
if (b.y > H + 80) { blocks.splice(i, 1); continue; }
|
|
107
|
+
if (b.x < player.x + PLAYER.w && b.x + b.w > player.x &&
|
|
108
|
+
b.y < player.y + PLAYER.h && b.y + b.h > player.y) {
|
|
109
|
+
state = 'over';
|
|
110
|
+
best = Math.max(best, score);
|
|
111
|
+
localStorage.setItem('desvie_best', String(best));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ------------------------------------------------------------------
|
|
117
|
+
// Render
|
|
118
|
+
// ------------------------------------------------------------------
|
|
119
|
+
function draw() {
|
|
120
|
+
// Fundo com leve gradiente
|
|
121
|
+
const bg = ctx.createLinearGradient(0, 0, 0, H);
|
|
122
|
+
bg.addColorStop(0, '#0f172a');
|
|
123
|
+
bg.addColorStop(1, '#1e1b4b');
|
|
124
|
+
ctx.fillStyle = bg;
|
|
125
|
+
ctx.fillRect(0, 0, W, H);
|
|
126
|
+
|
|
127
|
+
// Blocos
|
|
128
|
+
for (const b of blocks) {
|
|
129
|
+
ctx.fillStyle = `hsl(${b.hue} 85% 60%)`;
|
|
130
|
+
ctx.beginPath();
|
|
131
|
+
ctx.roundRect(b.x, b.y, b.w, b.h, 6);
|
|
132
|
+
ctx.fill();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Player
|
|
136
|
+
ctx.fillStyle = '#818cf8';
|
|
137
|
+
ctx.beginPath();
|
|
138
|
+
ctx.roundRect(player.x, player.y, PLAYER.w, PLAYER.h, 10);
|
|
139
|
+
ctx.fill();
|
|
140
|
+
|
|
141
|
+
// HUD
|
|
142
|
+
ctx.fillStyle = '#fff';
|
|
143
|
+
ctx.font = '700 22px system-ui, sans-serif';
|
|
144
|
+
ctx.textAlign = 'left';
|
|
145
|
+
ctx.fillText(String(score), 16, 38);
|
|
146
|
+
ctx.font = '600 12px system-ui, sans-serif';
|
|
147
|
+
ctx.fillStyle = 'rgba(255,255,255,.55)';
|
|
148
|
+
ctx.fillText(`RECORDE ${best}`, 16, 56);
|
|
149
|
+
|
|
150
|
+
// Telas de pausa / game over
|
|
151
|
+
if (state !== 'playing') {
|
|
152
|
+
ctx.fillStyle = 'rgba(5,8,20,.7)';
|
|
153
|
+
ctx.fillRect(0, 0, W, H);
|
|
154
|
+
ctx.fillStyle = '#fff';
|
|
155
|
+
ctx.textAlign = 'center';
|
|
156
|
+
ctx.font = '800 34px system-ui, sans-serif';
|
|
157
|
+
ctx.fillText(state === 'over' ? '💥 Game Over' : '⏸ Pausado', W / 2, H / 2 - 18);
|
|
158
|
+
ctx.font = '600 15px system-ui, sans-serif';
|
|
159
|
+
ctx.fillStyle = 'rgba(255,255,255,.75)';
|
|
160
|
+
ctx.fillText(
|
|
161
|
+
state === 'over' ? `${score} pontos — toque ou Enter para jogar de novo` : 'Espaço para continuar',
|
|
162
|
+
W / 2, H / 2 + 16
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ------------------------------------------------------------------
|
|
168
|
+
// Loop principal: acumula tempo real e roda updates em passo fixo
|
|
169
|
+
// ------------------------------------------------------------------
|
|
170
|
+
let last = performance.now();
|
|
171
|
+
let acc = 0;
|
|
172
|
+
function frame(now) {
|
|
173
|
+
requestAnimationFrame(frame);
|
|
174
|
+
acc += Math.min((now - last) / 1000, 0.25); // trava saltos (aba oculta)
|
|
175
|
+
last = now;
|
|
176
|
+
while (acc >= STEP) {
|
|
177
|
+
if (state === 'playing') update(STEP);
|
|
178
|
+
acc -= STEP;
|
|
179
|
+
}
|
|
180
|
+
draw();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
reset();
|
|
184
|
+
requestAnimationFrame(frame);
|
|
185
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "game-canvas-01",
|
|
3
|
+
"nome": "Jogo 2D Canvas (Desvie!)",
|
|
4
|
+
"categoria": "game",
|
|
5
|
+
"framework": "vanilla",
|
|
6
|
+
"linguagem": "javascript",
|
|
7
|
+
"dependencias": [],
|
|
8
|
+
"tags": ["game", "jogo", "2d", "canvas", "arcade", "dodge", "desviar", "touch", "mobile", "sem-dependencias"],
|
|
9
|
+
"compatibilidade": { "banco": [], "auth": [] },
|
|
10
|
+
"recursos_suportados": ["mobile", "touch", "teclado", "offline"],
|
|
11
|
+
"versao": "1.0.0",
|
|
12
|
+
"descricao": "Jogo 2D arcade completo em Canvas puro, ZERO dependências (abre direto no navegador, sem build): player desvia de blocos que caem cada vez mais rápido, pontuação por sobrevivência, recorde em localStorage, controles por teclado e arrastar no celular, loop com passo fixo (física estável em qualquer FPS), pausa e reinício. Base ideal para qualquer jogo 2D: runner, nave, pong, snake."
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="pt-BR">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
|
|
6
|
+
<title>Plataforma Phaser</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
html, body { height: 100%; overflow: hidden; background: #0b1021; touch-action: none; }
|
|
10
|
+
#app { position: fixed; inset: 0; }
|
|
11
|
+
#app canvas { display: block; }
|
|
12
|
+
|
|
13
|
+
/* Botões de toque (aparecem só em telas de toque) */
|
|
14
|
+
.touch-btns {
|
|
15
|
+
position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 0; right: 0;
|
|
16
|
+
display: none; justify-content: space-between; padding: 0 max(14px, env(safe-area-inset-left));
|
|
17
|
+
pointer-events: none; z-index: 5;
|
|
18
|
+
}
|
|
19
|
+
@media (pointer: coarse) { .touch-btns { display: flex; } }
|
|
20
|
+
.touch-btns .group { display: flex; gap: 10px; pointer-events: auto; }
|
|
21
|
+
.touch-btns button {
|
|
22
|
+
width: 62px; height: 62px; border: none; border-radius: 16px;
|
|
23
|
+
background: rgba(255,255,255,.14); color: #fff; font-size: 24px;
|
|
24
|
+
touch-action: none; user-select: none; -webkit-user-select: none;
|
|
25
|
+
}
|
|
26
|
+
.touch-btns button:active { background: rgba(255,255,255,.32); }
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="app"></div>
|
|
31
|
+
<div class="touch-btns">
|
|
32
|
+
<div class="group">
|
|
33
|
+
<button id="btn-left" aria-label="Esquerda">◀</button>
|
|
34
|
+
<button id="btn-right" aria-label="Direita">▶</button>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="group">
|
|
37
|
+
<button id="btn-jump" aria-label="Pular">⤒</button>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<script type="module" src="/src/game.js"></script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Plataforma Phaser 3 — jogo base SEM assets externos (texturas geradas em
|
|
2
|
+
// código com Graphics). Setas/WASD movem, ⤒/W/↑ pula; no celular use os
|
|
3
|
+
// botões de toque. Colete todas as moedas para vencer; espinho reinicia.
|
|
4
|
+
//
|
|
5
|
+
// Para adaptar: mude o vetor LEVEL (plataformas/moedas/espinhos), troque as
|
|
6
|
+
// texturas geradas por sprites reais (this.load.image) e ajuste a gravidade.
|
|
7
|
+
import Phaser from 'phaser';
|
|
8
|
+
|
|
9
|
+
// Mundo fixo 960×540 escalado para caber na tela (coordenadas previsíveis).
|
|
10
|
+
const W = 960;
|
|
11
|
+
const H = 540;
|
|
12
|
+
|
|
13
|
+
// Nível: plataformas (x, y centrais), moedas e espinhos.
|
|
14
|
+
const LEVEL = {
|
|
15
|
+
platforms: [
|
|
16
|
+
{ x: 480, y: 530, w: 960 }, // chão
|
|
17
|
+
{ x: 180, y: 420, w: 200 },
|
|
18
|
+
{ x: 460, y: 330, w: 160 },
|
|
19
|
+
{ x: 740, y: 250, w: 200 },
|
|
20
|
+
{ x: 330, y: 180, w: 140 },
|
|
21
|
+
{ x: 80, y: 260, w: 120 },
|
|
22
|
+
],
|
|
23
|
+
coins: [
|
|
24
|
+
{ x: 180, y: 380 }, { x: 460, y: 290 }, { x: 740, y: 210 },
|
|
25
|
+
{ x: 330, y: 140 }, { x: 80, y: 220 }, { x: 620, y: 490 }, { x: 880, y: 490 },
|
|
26
|
+
],
|
|
27
|
+
spikes: [
|
|
28
|
+
{ x: 400, y: 508 }, { x: 424, y: 508 }, { x: 448, y: 508 },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Entrada dos botões de toque (compartilhada com a cena)
|
|
33
|
+
const touch = { left: false, right: false, jump: false };
|
|
34
|
+
function bindTouch(id, prop) {
|
|
35
|
+
const el = document.getElementById(id);
|
|
36
|
+
if (!el) return;
|
|
37
|
+
const set = (on) => (e) => { e.preventDefault(); touch[prop] = on; };
|
|
38
|
+
el.addEventListener('pointerdown', set(true));
|
|
39
|
+
el.addEventListener('pointerup', set(false));
|
|
40
|
+
el.addEventListener('pointerleave', set(false));
|
|
41
|
+
el.addEventListener('pointercancel', set(false));
|
|
42
|
+
}
|
|
43
|
+
bindTouch('btn-left', 'left');
|
|
44
|
+
bindTouch('btn-right', 'right');
|
|
45
|
+
bindTouch('btn-jump', 'jump');
|
|
46
|
+
|
|
47
|
+
class MainScene extends Phaser.Scene {
|
|
48
|
+
create() {
|
|
49
|
+
this.makeTextures();
|
|
50
|
+
|
|
51
|
+
// Plataformas (corpo estático)
|
|
52
|
+
const platforms = this.physics.add.staticGroup();
|
|
53
|
+
for (const p of LEVEL.platforms) {
|
|
54
|
+
// setScale ajusta a largura da textura base (100px); refreshBody aplica ao corpo físico
|
|
55
|
+
platforms.create(p.x, p.y, 'platform').setScale(p.w / 100, 1).refreshBody();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Player
|
|
59
|
+
this.player = this.physics.add.sprite(60, 470, 'player');
|
|
60
|
+
this.player.setCollideWorldBounds(true);
|
|
61
|
+
this.physics.add.collider(this.player, platforms);
|
|
62
|
+
|
|
63
|
+
// Moedas (estáticas; overlap coleta)
|
|
64
|
+
this.coins = this.physics.add.staticGroup();
|
|
65
|
+
for (const c of LEVEL.coins) this.coins.create(c.x, c.y, 'coin');
|
|
66
|
+
this.physics.add.overlap(this.player, this.coins, (_pl, coin) => this.collect(coin), undefined, this);
|
|
67
|
+
|
|
68
|
+
// Espinhos (tocar = reiniciar)
|
|
69
|
+
const spikes = this.physics.add.staticGroup();
|
|
70
|
+
for (const s of LEVEL.spikes) spikes.create(s.x, s.y, 'spike');
|
|
71
|
+
this.physics.add.overlap(this.player, spikes, () => this.die(), undefined, this);
|
|
72
|
+
|
|
73
|
+
// Controles
|
|
74
|
+
this.cursors = this.input.keyboard.createCursorKeys();
|
|
75
|
+
this.keys = this.input.keyboard.addKeys('W,A,D');
|
|
76
|
+
|
|
77
|
+
// HUD
|
|
78
|
+
this.score = 0;
|
|
79
|
+
this.total = LEVEL.coins.length;
|
|
80
|
+
this.hud = this.add.text(14, 10, `Moedas: 0/${this.total}`, {
|
|
81
|
+
fontFamily: 'system-ui, sans-serif', fontSize: '20px', color: '#ffffff', fontStyle: 'bold',
|
|
82
|
+
});
|
|
83
|
+
this.won = false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Gera todas as texturas em código — troque por this.load.image() para usar sprites. */
|
|
87
|
+
makeTextures() {
|
|
88
|
+
const g = this.add.graphics();
|
|
89
|
+
g.fillStyle(0x6366f1); g.fillRoundedRect(0, 0, 28, 36, 7); g.generateTexture('player', 28, 36); g.clear();
|
|
90
|
+
g.fillStyle(0x334155); g.fillRect(0, 0, 100, 22);
|
|
91
|
+
g.fillStyle(0x475569); g.fillRect(0, 0, 100, 5); g.generateTexture('platform', 100, 22); g.clear();
|
|
92
|
+
g.fillStyle(0xfbbf24); g.fillCircle(9, 9, 9);
|
|
93
|
+
g.fillStyle(0xfde68a); g.fillCircle(6, 6, 3); g.generateTexture('coin', 18, 18); g.clear();
|
|
94
|
+
g.fillStyle(0xef4444); g.fillTriangle(0, 24, 12, 0, 24, 24); g.generateTexture('spike', 24, 24);
|
|
95
|
+
g.destroy();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
collect(coin) {
|
|
99
|
+
coin.destroy();
|
|
100
|
+
this.score++;
|
|
101
|
+
this.hud.setText(`Moedas: ${this.score}/${this.total}`);
|
|
102
|
+
if (this.score >= this.total) this.win();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
win() {
|
|
106
|
+
if (this.won) return;
|
|
107
|
+
this.won = true;
|
|
108
|
+
this.physics.pause();
|
|
109
|
+
this.add.text(W / 2, H / 2 - 20, '🏆 Você venceu!', {
|
|
110
|
+
fontFamily: 'system-ui, sans-serif', fontSize: '42px', color: '#fbbf24', fontStyle: 'bold',
|
|
111
|
+
}).setOrigin(0.5);
|
|
112
|
+
this.add.text(W / 2, H / 2 + 26, 'Toque ou pressione qualquer tecla para jogar de novo', {
|
|
113
|
+
fontFamily: 'system-ui, sans-serif', fontSize: '16px', color: '#ffffff',
|
|
114
|
+
}).setOrigin(0.5);
|
|
115
|
+
this.input.once('pointerdown', () => this.scene.restart());
|
|
116
|
+
this.input.keyboard.once('keydown', () => this.scene.restart());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
die() {
|
|
120
|
+
// Piscada vermelha e reinício rápido
|
|
121
|
+
this.cameras.main.flash(220, 239, 68, 68);
|
|
122
|
+
this.time.delayedCall(230, () => this.scene.restart());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
update() {
|
|
126
|
+
if (this.won) return;
|
|
127
|
+
const left = this.cursors.left.isDown || this.keys.A.isDown || touch.left;
|
|
128
|
+
const right = this.cursors.right.isDown || this.keys.D.isDown || touch.right;
|
|
129
|
+
const jump = this.cursors.up.isDown || this.keys.W.isDown || touch.jump;
|
|
130
|
+
|
|
131
|
+
// Movimento horizontal
|
|
132
|
+
if (left) this.player.setVelocityX(-240);
|
|
133
|
+
else if (right) this.player.setVelocityX(240);
|
|
134
|
+
else this.player.setVelocityX(0);
|
|
135
|
+
|
|
136
|
+
// Pulo: só com os pés no chão/plataforma
|
|
137
|
+
if (jump && this.player.body.blocked.down) {
|
|
138
|
+
this.player.setVelocityY(-560);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
new Phaser.Game({
|
|
144
|
+
type: Phaser.AUTO,
|
|
145
|
+
parent: 'app',
|
|
146
|
+
backgroundColor: '#0b1021',
|
|
147
|
+
scale: {
|
|
148
|
+
mode: Phaser.Scale.FIT, // escala o mundo 960×540 para caber na tela
|
|
149
|
+
autoCenter: Phaser.Scale.CENTER_BOTH,
|
|
150
|
+
width: W,
|
|
151
|
+
height: H,
|
|
152
|
+
},
|
|
153
|
+
physics: {
|
|
154
|
+
default: 'arcade',
|
|
155
|
+
arcade: { gravity: { y: 1100 }, debug: false },
|
|
156
|
+
},
|
|
157
|
+
scene: MainScene,
|
|
158
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "game-phaser-01",
|
|
3
|
+
"nome": "Jogo Plataforma Phaser 3",
|
|
4
|
+
"categoria": "game",
|
|
5
|
+
"framework": "phaser",
|
|
6
|
+
"linguagem": "javascript",
|
|
7
|
+
"dependencias": ["phaser", "vite"],
|
|
8
|
+
"tags": ["game", "jogo", "2d", "phaser", "plataforma", "platformer", "fisica", "pulo", "moedas", "touch", "mobile"],
|
|
9
|
+
"compatibilidade": { "banco": [], "auth": [] },
|
|
10
|
+
"recursos_suportados": ["mobile", "touch", "teclado"],
|
|
11
|
+
"versao": "1.0.0",
|
|
12
|
+
"descricao": "Jogo de plataforma completo em Phaser 3 com física arcade: pulo com gravidade, plataformas, moedas para coletar, espinhos que matam, vitória ao pegar tudo, placar, reinício, controles por teclado (setas/WASD) e botões de toque no celular. SEM assets externos — as texturas são geradas em código (Graphics), então roda na hora com Vite (npx vite). Base ideal para plataforma, puzzle ou top-down."
|
|
13
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.g3d {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
5
|
+
min-height: 360px;
|
|
6
|
+
border-radius: 12px;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
background: #0b1021;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.g3d-hud {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 12px;
|
|
14
|
+
left: 12px;
|
|
15
|
+
right: 12px;
|
|
16
|
+
display: flex;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
z-index: 2;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.g3d-stat {
|
|
23
|
+
font-family: system-ui, sans-serif;
|
|
24
|
+
font-size: 18px;
|
|
25
|
+
font-weight: 800;
|
|
26
|
+
color: #fff;
|
|
27
|
+
background: rgba(10, 14, 32, 0.55);
|
|
28
|
+
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
29
|
+
border-radius: 10px;
|
|
30
|
+
padding: 6px 14px;
|
|
31
|
+
backdrop-filter: blur(4px);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.g3d-over {
|
|
35
|
+
position: absolute;
|
|
36
|
+
inset: 0;
|
|
37
|
+
z-index: 3;
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
background: rgba(5, 8, 20, 0.7);
|
|
42
|
+
backdrop-filter: blur(4px);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.g3d-over-card {
|
|
46
|
+
text-align: center;
|
|
47
|
+
font-family: system-ui, sans-serif;
|
|
48
|
+
color: #fff;
|
|
49
|
+
padding: 28px 36px;
|
|
50
|
+
background: rgba(20, 26, 53, 0.9);
|
|
51
|
+
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
52
|
+
border-radius: 16px;
|
|
53
|
+
}
|
|
54
|
+
.g3d-over-card h2 { margin: 0 0 8px; font-size: 26px; }
|
|
55
|
+
.g3d-over-card p { margin: 0 0 18px; opacity: 0.85; }
|
|
56
|
+
|
|
57
|
+
.g3d-btn {
|
|
58
|
+
font-size: 15px;
|
|
59
|
+
font-weight: 700;
|
|
60
|
+
padding: 11px 28px;
|
|
61
|
+
border: none;
|
|
62
|
+
border-radius: 10px;
|
|
63
|
+
background: linear-gradient(135deg, #6366f1, #8b5cf6);
|
|
64
|
+
color: #fff;
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
}
|
|
67
|
+
.g3d-btn:active { transform: scale(0.97); }
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Canvas, useFrame } from '@react-three/fiber';
|
|
3
|
+
import type { Mesh } from 'three';
|
|
4
|
+
import './GameScene.css';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Mini-jogo 3D em React Three Fiber: clique nas caixas para pontuar antes
|
|
8
|
+
* do tempo acabar. Cada caixa clicada renasce em outra posição.
|
|
9
|
+
*
|
|
10
|
+
* R3F = Three.js declarativo: a cena vive DENTRO do React, então placar,
|
|
11
|
+
* overlay e estado usam os hooks normais do seu app.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const GAME_SECONDS = 30;
|
|
15
|
+
const NUM_BOXES = 6;
|
|
16
|
+
|
|
17
|
+
function randomPos(): [number, number, number] {
|
|
18
|
+
return [(Math.random() * 2 - 1) * 4.5, 0.6 + Math.random() * 3, (Math.random() * 2 - 1) * 2.5];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface TargetBoxProps {
|
|
22
|
+
onHit: () => void;
|
|
23
|
+
paused: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Caixa-alvo: flutua e gira (useFrame roda a cada frame); clique = ponto. */
|
|
27
|
+
function TargetBox({ onHit, paused }: TargetBoxProps) {
|
|
28
|
+
const mesh = useRef<Mesh>(null);
|
|
29
|
+
const [pos, setPos] = useState<[number, number, number]>(randomPos);
|
|
30
|
+
const [hovered, setHovered] = useState(false);
|
|
31
|
+
// Fase aleatória para cada caixa flutuar fora de sincronia
|
|
32
|
+
const phase = useRef(Math.random() * Math.PI * 2);
|
|
33
|
+
|
|
34
|
+
useFrame((state, dt) => {
|
|
35
|
+
if (!mesh.current || paused) return;
|
|
36
|
+
mesh.current.rotation.x += dt * 0.8;
|
|
37
|
+
mesh.current.rotation.y += dt * 1.2;
|
|
38
|
+
// Flutuação vertical suave em torno do y da posição
|
|
39
|
+
mesh.current.position.y = pos[1] + Math.sin(state.clock.elapsedTime * 2 + phase.current) * 0.25;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const hit = () => {
|
|
43
|
+
if (paused) return;
|
|
44
|
+
onHit();
|
|
45
|
+
setPos(randomPos()); // renasce em outro lugar
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<mesh
|
|
50
|
+
ref={mesh}
|
|
51
|
+
position={pos}
|
|
52
|
+
castShadow
|
|
53
|
+
onClick={hit}
|
|
54
|
+
onPointerOver={() => setHovered(true)}
|
|
55
|
+
onPointerOut={() => setHovered(false)}
|
|
56
|
+
scale={hovered ? 1.25 : 1}
|
|
57
|
+
>
|
|
58
|
+
<boxGeometry args={[0.7, 0.7, 0.7]} />
|
|
59
|
+
<meshStandardMaterial color={hovered ? '#fbbf24' : '#6366f1'} roughness={0.3} />
|
|
60
|
+
</mesh>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function GameScene() {
|
|
65
|
+
const [score, setScore] = useState(0);
|
|
66
|
+
const [timeLeft, setTimeLeft] = useState(GAME_SECONDS);
|
|
67
|
+
const over = timeLeft <= 0;
|
|
68
|
+
|
|
69
|
+
// Cronômetro regressivo (fora do canvas — estado React normal)
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (over) return;
|
|
72
|
+
const t = setInterval(() => setTimeLeft((s) => s - 1), 1000);
|
|
73
|
+
return () => clearInterval(t);
|
|
74
|
+
}, [over]);
|
|
75
|
+
|
|
76
|
+
const restart = () => {
|
|
77
|
+
setScore(0);
|
|
78
|
+
setTimeLeft(GAME_SECONDS);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div className="g3d">
|
|
83
|
+
{/* HUD em HTML normal, por cima do canvas */}
|
|
84
|
+
<div className="g3d-hud">
|
|
85
|
+
<span className="g3d-stat">🎯 {score}</span>
|
|
86
|
+
<span className="g3d-stat">⏱ {Math.max(0, timeLeft)}s</span>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{over && (
|
|
90
|
+
<div className="g3d-over">
|
|
91
|
+
<div className="g3d-over-card">
|
|
92
|
+
<h2>⏰ Fim de jogo!</h2>
|
|
93
|
+
<p>Você acertou <strong>{score}</strong> caixa{score === 1 ? '' : 's'}.</p>
|
|
94
|
+
<button className="g3d-btn" onClick={restart}>Jogar de novo</button>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
|
|
99
|
+
<Canvas shadows camera={{ position: [0, 4, 9], fov: 55 }}>
|
|
100
|
+
<color attach="background" args={['#0b1021']} />
|
|
101
|
+
<fog attach="fog" args={['#0b1021', 10, 24]} />
|
|
102
|
+
|
|
103
|
+
<ambientLight intensity={0.5} />
|
|
104
|
+
<directionalLight
|
|
105
|
+
position={[6, 10, 4]}
|
|
106
|
+
intensity={1.4}
|
|
107
|
+
castShadow
|
|
108
|
+
shadow-mapSize-width={1024}
|
|
109
|
+
shadow-mapSize-height={1024}
|
|
110
|
+
/>
|
|
111
|
+
|
|
112
|
+
{/* Chão */}
|
|
113
|
+
<mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
|
|
114
|
+
<planeGeometry args={[30, 30]} />
|
|
115
|
+
<meshStandardMaterial color="#141a35" roughness={0.9} />
|
|
116
|
+
</mesh>
|
|
117
|
+
|
|
118
|
+
{Array.from({ length: NUM_BOXES }, (_, i) => (
|
|
119
|
+
<TargetBox key={i} paused={over} onHit={() => setScore((s) => s + 1)} />
|
|
120
|
+
))}
|
|
121
|
+
</Canvas>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Exemplo de uso (o componente ocupa o tamanho do pai):
|
|
127
|
+
|
|
128
|
+
<div style={{ width: '100%', height: '100dvh' }}>
|
|
129
|
+
<GameScene />
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
Dependências: npm i three @react-three/fiber
|
|
133
|
+
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "game-r3f-01",
|
|
3
|
+
"nome": "Cena 3D React Three Fiber",
|
|
4
|
+
"categoria": "game",
|
|
5
|
+
"framework": "react",
|
|
6
|
+
"linguagem": "typescript",
|
|
7
|
+
"dependencias": ["react", "three", "@react-three/fiber"],
|
|
8
|
+
"tags": ["game", "jogo", "3d", "threejs", "three.js", "react-three-fiber", "r3f", "webgl", "interativo", "clique"],
|
|
9
|
+
"compatibilidade": { "banco": [], "auth": [] },
|
|
10
|
+
"recursos_suportados": ["dark-mode", "mobile", "typescript", "touch"],
|
|
11
|
+
"versao": "1.0.0",
|
|
12
|
+
"descricao": "Mini-jogo 3D DENTRO do React com React Three Fiber (Three.js declarativo): caixas flutuando que giram, crescem no hover e somam pontos ao clicar (renascem em posição nova), luzes com sombra, chão, placar e cronômetro regressivo com fim de jogo em overlay HTML. Ideal quando o app já é React e você quer 3D integrado ao estado/UI existente (ao contrário do game-threejs-01, que é standalone)."
|
|
13
|
+
}
|