@causyne/agent 0.0.0-stage → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -0
- package/README.md +31 -2
- package/SECURITY.md +24 -0
- package/bin/causyne.js +13 -0
- package/docs/ARCHITECTURE.md +63 -0
- package/docs/PROVENANCE.md +29 -0
- package/docs/SECURITY_REVIEW.md +89 -0
- package/docs/THIRD_PARTY_NOTICES.md +49 -0
- package/native-skills/ai-engineering/context-window-management/SKILL.md +43 -0
- package/native-skills/ai-engineering/llm-evaluation/SKILL.md +46 -0
- package/native-skills/ai-engineering/model-cost-and-latency/SKILL.md +46 -0
- package/native-skills/ai-engineering/prompt-construction/SKILL.md +42 -0
- package/native-skills/ai-engineering/retrieval-augmented-generation/SKILL.md +42 -0
- package/native-skills/ai-engineering/structured-output-and-schemas/SKILL.md +45 -0
- package/native-skills/ai-engineering/tool-calling-agents/SKILL.md +43 -0
- package/native-skills/android/app-performance-profiling/SKILL.md +42 -0
- package/native-skills/android/background-work-scheduling/SKILL.md +47 -0
- package/native-skills/android/compose-state-and-recomposition/SKILL.md +43 -0
- package/native-skills/android/gradle-build-configuration/SKILL.md +41 -0
- package/native-skills/android/lifecycle-and-leaks/SKILL.md +46 -0
- package/native-skills/android/play-store-release/SKILL.md +43 -0
- package/native-skills/android/room-and-persistence/SKILL.md +40 -0
- package/native-skills/backend/authentication-and-sessions/SKILL.md +45 -0
- package/native-skills/backend/background-jobs-and-queues/SKILL.md +42 -0
- package/native-skills/backend/caching-strategy/SKILL.md +44 -0
- package/native-skills/backend/graceful-shutdown/SKILL.md +42 -0
- package/native-skills/backend/rate-limiting-and-quotas/SKILL.md +40 -0
- package/native-skills/backend/rest-api-design/SKILL.md +40 -0
- package/native-skills/backend/webhook-delivery-and-receipt/SKILL.md +43 -0
- package/native-skills/cloud/cost-optimisation/SKILL.md +46 -0
- package/native-skills/cloud/iam-least-privilege/SKILL.md +43 -0
- package/native-skills/cloud/infrastructure-as-code/SKILL.md +43 -0
- package/native-skills/cloud/multi-region-and-failover/SKILL.md +43 -0
- package/native-skills/cloud/serverless-patterns/SKILL.md +47 -0
- package/native-skills/data/data-quality-monitoring/SKILL.md +51 -0
- package/native-skills/data/etl-pipeline-reliability/SKILL.md +43 -0
- package/native-skills/data/exploratory-analysis/SKILL.md +43 -0
- package/native-skills/data/metric-definition/SKILL.md +42 -0
- package/native-skills/data/notebook-to-production/SKILL.md +43 -0
- package/native-skills/database/backup-and-recovery/SKILL.md +43 -0
- package/native-skills/database/connection-pooling/SKILL.md +42 -0
- package/native-skills/database/data-integrity-and-constraints/SKILL.md +42 -0
- package/native-skills/database/query-optimisation/SKILL.md +38 -0
- package/native-skills/database/safe-migrations/SKILL.md +47 -0
- package/native-skills/database/schema-design/SKILL.md +38 -0
- package/native-skills/database/transactions-and-isolation/SKILL.md +41 -0
- package/native-skills/design/colour-system-construction/SKILL.md +38 -0
- package/native-skills/design/design-direction-brief/SKILL.md +41 -0
- package/native-skills/design/motion-and-transitions/SKILL.md +38 -0
- package/native-skills/design/responsive-strategy/SKILL.md +39 -0
- package/native-skills/design/spacing-and-rhythm/SKILL.md +38 -0
- package/native-skills/design/type-scale-and-hierarchy/SKILL.md +39 -0
- package/native-skills/design/visual-qa-loop/SKILL.md +42 -0
- package/native-skills/devops/docker-multi-stage-builds/SKILL.md +60 -0
- package/native-skills/devops/github-actions-ci/SKILL.md +60 -0
- package/native-skills/devops/incident-triage/SKILL.md +38 -0
- package/native-skills/devops/kubernetes-deployment-hardening/SKILL.md +64 -0
- package/native-skills/devops/observability-baseline/SKILL.md +38 -0
- package/native-skills/devops/secret-management/SKILL.md +40 -0
- package/native-skills/devops/terraform-state-and-modules/SKILL.md +36 -0
- package/native-skills/devops/zero-downtime-deploys/SKILL.md +40 -0
- package/native-skills/git/bisect-regression-hunt/SKILL.md +43 -0
- package/native-skills/git/branch-strategy/SKILL.md +39 -0
- package/native-skills/git/commit-hygiene/SKILL.md +41 -0
- package/native-skills/git/history-recovery/SKILL.md +44 -0
- package/native-skills/git/large-repository-surgery/SKILL.md +46 -0
- package/native-skills/git/merge-conflict-resolution/SKILL.md +42 -0
- package/native-skills/media/cinematic-3d-shot/SKILL.md +104 -0
- package/native-skills/mobile/app-startup-optimisation/SKILL.md +41 -0
- package/native-skills/mobile/cross-platform-tradeoffs/SKILL.md +42 -0
- package/native-skills/mobile/deep-linking/SKILL.md +39 -0
- package/native-skills/mobile/mobile-storage-security/SKILL.md +45 -0
- package/native-skills/mobile/offline-first-sync/SKILL.md +42 -0
- package/native-skills/mobile/push-notifications/SKILL.md +38 -0
- package/native-skills/performance/algorithmic-complexity/SKILL.md +43 -0
- package/native-skills/performance/concurrency-and-parallelism/SKILL.md +42 -0
- package/native-skills/performance/load-testing/SKILL.md +42 -0
- package/native-skills/performance/memory-and-leak-hunting/SKILL.md +41 -0
- package/native-skills/performance/network-and-payload-efficiency/SKILL.md +42 -0
- package/native-skills/performance/profiling-methodology/SKILL.md +46 -0
- package/native-skills/python/async-correctness/SKILL.md +40 -0
- package/native-skills/python/cli-tool-construction/SKILL.md +44 -0
- package/native-skills/python/data-processing-pipelines/SKILL.md +38 -0
- package/native-skills/python/environment-isolation/SKILL.md +41 -0
- package/native-skills/python/packaging-and-distribution/SKILL.md +56 -0
- package/native-skills/python/pytest-suite-design/SKILL.md +39 -0
- package/native-skills/python/type-hints-and-static-checking/SKILL.md +42 -0
- package/native-skills/security/authorization-model/SKILL.md +42 -0
- package/native-skills/security/crypto-usage/SKILL.md +48 -0
- package/native-skills/security/dependency-supply-chain/SKILL.md +42 -0
- package/native-skills/security/input-validation-and-injection/SKILL.md +44 -0
- package/native-skills/security/secure-file-uploads/SKILL.md +46 -0
- package/native-skills/security/security-headers-and-csp/SKILL.md +44 -0
- package/native-skills/security/threat-modelling/SKILL.md +46 -0
- package/native-skills/testing/end-to-end-test-stability/SKILL.md +42 -0
- package/native-skills/testing/property-based-testing/SKILL.md +46 -0
- package/native-skills/testing/regression-test-from-a-bug/SKILL.md +41 -0
- package/native-skills/testing/snapshot-and-visual-regression/SKILL.md +42 -0
- package/native-skills/testing/test-doubles-and-mocking/SKILL.md +43 -0
- package/native-skills/testing/test-strategy-and-pyramid/SKILL.md +39 -0
- package/native-skills/testing/writing-good-assertions/SKILL.md +42 -0
- package/native-skills/web/accessible-components/SKILL.md +45 -0
- package/native-skills/web/api-client-resilience/SKILL.md +39 -0
- package/native-skills/web/bundle-size-reduction/SKILL.md +38 -0
- package/native-skills/web/core-web-vitals/SKILL.md +40 -0
- package/native-skills/web/css-layout-systems/SKILL.md +41 -0
- package/native-skills/web/form-validation-ux/SKILL.md +39 -0
- package/native-skills/web/react-state-architecture/SKILL.md +41 -0
- package/native-skills/web/ssr-hydration-correctness/SKILL.md +45 -0
- package/package.json +68 -4
- package/src/agentLoop.js +2458 -0
- package/src/appChannel.js +109 -0
- package/src/approvalGrants.js +66 -0
- package/src/auditLog.js +52 -0
- package/src/autoUpdate.js +12 -0
- package/src/capabilities.js +36 -0
- package/src/checkpoints.js +1199 -0
- package/src/cliMode.js +638 -0
- package/src/commands.js +805 -0
- package/src/compiledSkills.js +540 -0
- package/src/config.js +130 -0
- package/src/contextManager.js +498 -0
- package/src/cortex/autoCondenser.js +192 -0
- package/src/cortex/provisioner.js +27 -0
- package/src/cortex/vectorDb.js +447 -0
- package/src/designPalettes.js +99 -0
- package/src/devMode.js +6 -0
- package/src/embodimentSession.js +180 -0
- package/src/entrypoint.js +194 -0
- package/src/execSafe.js +21 -0
- package/src/gitSnapshot.js +378 -0
- package/src/mcp/jsonRpc.js +165 -0
- package/src/mcp/mcpClient.js +136 -0
- package/src/mcp/mcpRegistry.js +207 -0
- package/src/memory.js +62 -0
- package/src/memoryManager.js +124 -0
- package/src/modelCatalogue.js +132 -0
- package/src/modelIds.js +42 -0
- package/src/modelRouter.js +145 -0
- package/src/outputStore.js +246 -0
- package/src/perception.js +124 -0
- package/src/planCache.js +437 -0
- package/src/procSignal.js +32 -0
- package/src/providers/anthropic.js +408 -0
- package/src/providers/base.js +328 -0
- package/src/providers/dashscope-byok.js +86 -0
- package/src/providers/deepseek.js +80 -0
- package/src/providers/factory.js +37 -0
- package/src/providers/gemini.js +346 -0
- package/src/providers/moonshot.js +73 -0
- package/src/providers/muse.js +169 -0
- package/src/providers/ollama.js +104 -0
- package/src/providers/openai-compatible.js +84 -0
- package/src/providers/openai.js +20 -0
- package/src/providers/qwen-byok.js +76 -0
- package/src/providers/xai.js +73 -0
- package/src/provisioning/capabilityConsent.js +24 -0
- package/src/provisioning/capabilityProvisioner.js +271 -0
- package/src/provisioning/capabilityTools.js +29 -0
- package/src/reporting.js +373 -0
- package/src/sandbox.js +529 -0
- package/src/sessionStore.js +279 -0
- package/src/skillsManager.js +288 -0
- package/src/slopDetector.js +307 -0
- package/src/taskBuffer.js +45 -0
- package/src/taskShape.js +241 -0
- package/src/textDiff.js +150 -0
- package/src/tokenTracker.js +560 -0
- package/src/tool-scripts/ax_snapshot.applescript +39 -0
- package/src/tool-scripts/ax_snapshot.ps1 +10 -0
- package/src/tool-scripts/desktop_act.applescript +58 -0
- package/src/tool-scripts/resolve_automator.py +119 -0
- package/src/toolPacks.js +524 -0
- package/src/tools/archive.js +63 -0
- package/src/tools/astryxOracle.js +78 -0
- package/src/tools/axSnapshot.js +165 -0
- package/src/tools/blenderAutomator.js +349 -0
- package/src/tools/browserAutomator.js +252 -0
- package/src/tools/checkSystemSpecs.js +64 -0
- package/src/tools/clipboard.js +36 -0
- package/src/tools/codeSearchAst.js +101 -0
- package/src/tools/codeSearcher.js +230 -0
- package/src/tools/codeTools.js +262 -0
- package/src/tools/codebaseSearch.js +75 -0
- package/src/tools/createSkill.js +129 -0
- package/src/tools/deferredMcpSearch.js +246 -0
- package/src/tools/desktopAct.js +208 -0
- package/src/tools/desktopOpen.js +34 -0
- package/src/tools/dynamicLoader.js +44 -0
- package/src/tools/executeProceduralMedia.js +93 -0
- package/src/tools/fsDelete.js +51 -0
- package/src/tools/fsEdit.js +105 -0
- package/src/tools/fsFind.js +128 -0
- package/src/tools/fsList.js +77 -0
- package/src/tools/fsMove.js +57 -0
- package/src/tools/fsRead.js +87 -0
- package/src/tools/fsSearch.js +198 -0
- package/src/tools/fsWrite.js +41 -0
- package/src/tools/gameAiBehaviorTree.js +208 -0
- package/src/tools/gameAnimationRig.js +194 -0
- package/src/tools/gameAssetFetcher.js +372 -0
- package/src/tools/gameAssetHarvester.js +210 -0
- package/src/tools/gameAudioSynth.js +267 -0
- package/src/tools/gameBuilder.js +886 -0
- package/src/tools/gameCanvasAudit.js +101 -0
- package/src/tools/gameCinematicSequencer.js +151 -0
- package/src/tools/gameDataForge.js +124 -0
- package/src/tools/gameDialogueTreeGen.js +166 -0
- package/src/tools/gameEconomyBalancer.js +161 -0
- package/src/tools/gameEntitySpawner.js +207 -0
- package/src/tools/gameLoreForge.js +153 -0
- package/src/tools/gameQuestArcBuilder.js +152 -0
- package/src/tools/gameSceneBuilder.js +158 -0
- package/src/tools/gameShaderForge.js +181 -0
- package/src/tools/gameTilemapGenerator.js +164 -0
- package/src/tools/gameUiHudBuilder.js +292 -0
- package/src/tools/gameVfxEmitterGen.js +108 -0
- package/src/tools/gameWebRuntimeInspector.js +91 -0
- package/src/tools/generateMediaViaApi.js +358 -0
- package/src/tools/gitExec.js +54 -0
- package/src/tools/godotAutomator.js +437 -0
- package/src/tools/manageLocalAiDependencies.js +220 -0
- package/src/tools/memoryWrite.js +99 -0
- package/src/tools/multiEdit.js +107 -0
- package/src/tools/palmierAutomator.js +104 -0
- package/src/tools/pdfReader.js +112 -0
- package/src/tools/persistentShell.js +148 -0
- package/src/tools/printer.js +316 -0
- package/src/tools/procTerm.js +91 -0
- package/src/tools/processList.js +52 -0
- package/src/tools/readNativeSkill.js +39 -0
- package/src/tools/registry.js +277 -0
- package/src/tools/resolveAutomator.js +102 -0
- package/src/tools/screenshot.js +75 -0
- package/src/tools/subagentOrchestrator.js +305 -0
- package/src/tools/sysRun.js +125 -0
- package/src/tools/todoWrite.js +75 -0
- package/src/tools/toolDispatch.js +127 -0
- package/src/tools/toolForge.js +124 -0
- package/src/tools/updatePlan.js +88 -0
- package/src/tools/viewImage.js +82 -0
- package/src/tools/visionInspector.js +154 -0
- package/src/tools/webFetch.js +74 -0
- package/src/tools/webSearch.js +82 -0
- package/src/tui/ask.js +164 -0
- package/src/tui/banner.js +158 -0
- package/src/tui/block.js +152 -0
- package/src/tui/chatRenderer.js +953 -0
- package/src/tui/completion.js +424 -0
- package/src/tui/dialogs.js +606 -0
- package/src/tui/diff.js +296 -0
- package/src/tui/history.js +135 -0
- package/src/tui/home.js +217 -0
- package/src/tui/invocation.js +105 -0
- package/src/tui/keys.js +443 -0
- package/src/tui/lineEditor.js +256 -0
- package/src/tui/overlay.js +256 -0
- package/src/tui/prompt.js +1258 -0
- package/src/tui/selectList.js +335 -0
- package/src/tui/stage.js +330 -0
- package/src/tui/stageSurface.js +609 -0
- package/src/tui/statusLine.js +254 -0
- package/src/tui/text.js +345 -0
- package/src/tui/theme.js +393 -0
- package/src/tui/toolDisplay.js +176 -0
- package/src/tui/transcript.js +235 -0
- package/src/tui/viewport.js +337 -0
- package/src/uncertainty.js +271 -0
- package/src/userSkills.js +265 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/inquirer.js +12 -0
- package/src/utils/paths.js +37 -0
- package/src/version.js +38 -0
- package/src/vfeTracker.js +220 -0
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import fsSync from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
function getWorkspaceTempDir() {
|
|
6
|
+
const tmpDir = path.join(process.cwd(), '.tmp_causyne_3d');
|
|
7
|
+
if (!fsSync.existsSync(tmpDir)) {
|
|
8
|
+
fsSync.mkdirSync(tmpDir, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
return tmpDir;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// -----------------------------------------------------------------------------
|
|
14
|
+
// Benchmark Template 1: 3D Space Defense (Three.js WebGL + Web Audio + Joysticks)
|
|
15
|
+
// -----------------------------------------------------------------------------
|
|
16
|
+
function getSpaceDefense3dTemplate(title, includeAudio = true) {
|
|
17
|
+
return `<!DOCTYPE html>
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="UTF-8">
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
22
|
+
<title>${title} — Causyne Sovereign Edge Game</title>
|
|
23
|
+
<style>
|
|
24
|
+
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
|
|
25
|
+
body { background: #000; overflow: hidden; font-family: 'Outfit', sans-serif; }
|
|
26
|
+
#canvas-container { width: 100vw; height: 100vh; display: block; }
|
|
27
|
+
#hud {
|
|
28
|
+
position: absolute; top: 20px; left: 20px; right: 20px;
|
|
29
|
+
display: flex; justify-content: space-between; align-items: center; pointer-events: none;
|
|
30
|
+
color: #fff; text-shadow: 0 0 10px rgba(0, 255, 204, 0.8);
|
|
31
|
+
}
|
|
32
|
+
.hud-box {
|
|
33
|
+
background: rgba(10, 15, 25, 0.6); border: 1px solid rgba(0, 255, 204, 0.4);
|
|
34
|
+
padding: 10px 20px; border-radius: 8px; backdrop-filter: blur(10px); pointer-events: auto;
|
|
35
|
+
}
|
|
36
|
+
.hud-score { font-size: 24px; font-weight: 800; color: #00ffcc; }
|
|
37
|
+
.hud-health { font-size: 18px; color: #ff3366; }
|
|
38
|
+
#mute-btn {
|
|
39
|
+
background: rgba(10, 15, 25, 0.8); border: 1px solid #00ffcc; color: #fff;
|
|
40
|
+
padding: 8px 14px; border-radius: 20px; font-size: 18px; cursor: pointer; pointer-events: auto;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Mobile Controls Overlay */
|
|
44
|
+
#mobile-controls {
|
|
45
|
+
position: absolute; bottom: 30px; left: 30px; right: 30px;
|
|
46
|
+
display: flex; justify-content: space-between; align-items: flex-end;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
}
|
|
49
|
+
.touch-pad {
|
|
50
|
+
width: 120px; height: 120px; background: rgba(255, 255, 255, 0.1);
|
|
51
|
+
border: 2px solid rgba(0, 255, 204, 0.4); border-radius: 50%;
|
|
52
|
+
position: relative; pointer-events: auto; touch-action: none;
|
|
53
|
+
}
|
|
54
|
+
.touch-knob {
|
|
55
|
+
width: 50px; height: 50px; background: rgba(0, 255, 204, 0.8);
|
|
56
|
+
border-radius: 50%; position: absolute; top: 35px; left: 35px;
|
|
57
|
+
box-shadow: 0 0 15px #00ffcc; transition: transform 0.05s ease;
|
|
58
|
+
}
|
|
59
|
+
.btn-fire {
|
|
60
|
+
width: 90px; height: 90px; background: rgba(255, 51, 102, 0.8);
|
|
61
|
+
border: 2px solid #fff; border-radius: 50%; font-weight: bold; color: #fff;
|
|
62
|
+
display: flex; align-items: center; justify-content: center; font-size: 18px;
|
|
63
|
+
pointer-events: auto; box-shadow: 0 0 20px rgba(255, 51, 102, 0.8);
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
.btn-fire:active { transform: scale(0.95); background: #ff0044; }
|
|
67
|
+
#game-over {
|
|
68
|
+
position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
|
|
69
|
+
background: rgba(0, 0, 0, 0.85); display: none; flex-direction: column;
|
|
70
|
+
align-items: center; justify-content: center; color: #fff; z-index: 100;
|
|
71
|
+
}
|
|
72
|
+
#game-over h1 { font-size: 48px; color: #ff3366; margin-bottom: 20px; }
|
|
73
|
+
.restart-btn {
|
|
74
|
+
padding: 15px 40px; background: #00ffcc; color: #000; font-weight: 800;
|
|
75
|
+
border: none; border-radius: 30px; font-size: 20px; cursor: pointer;
|
|
76
|
+
box-shadow: 0 0 25px rgba(0, 255, 204, 0.8);
|
|
77
|
+
}
|
|
78
|
+
</style>
|
|
79
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<div id="canvas-container"></div>
|
|
83
|
+
<div id="hud">
|
|
84
|
+
<div class="hud-box"><span class="hud-score" id="score">SCORE: 0</span></div>
|
|
85
|
+
<button id="mute-btn" title="Toggle Audio">🔊</button>
|
|
86
|
+
<div class="hud-box"><span class="hud-health" id="health">SHIELD: 100%</span></div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<div id="mobile-controls">
|
|
90
|
+
<div class="touch-pad" id="joystick">
|
|
91
|
+
<div class="touch-knob" id="knob"></div>
|
|
92
|
+
</div>
|
|
93
|
+
<div class="btn-fire" id="fire-btn">FIRE</div>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<div id="game-over">
|
|
97
|
+
<h1>MISSION TERMINATED</h1>
|
|
98
|
+
<p style="font-size: 22px; margin-bottom: 30px;">Final Sovereign Score: <span id="final-score" style="color: #00ffcc;">0</span></p>
|
|
99
|
+
<button class="restart-btn" onclick="location.reload()">RE-INITIALIZE</button>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<script>
|
|
103
|
+
// ── Sovereign Web Audio API Synthesizer ──
|
|
104
|
+
class SovereignAudioEngine {
|
|
105
|
+
constructor() {
|
|
106
|
+
this.ctx = null;
|
|
107
|
+
this.muted = false;
|
|
108
|
+
this.bgmTimer = null;
|
|
109
|
+
}
|
|
110
|
+
init() {
|
|
111
|
+
if (!this.ctx) {
|
|
112
|
+
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
113
|
+
if (AudioCtx) this.ctx = new AudioCtx();
|
|
114
|
+
}
|
|
115
|
+
if (this.ctx && this.ctx.state === 'suspended') {
|
|
116
|
+
this.ctx.resume();
|
|
117
|
+
}
|
|
118
|
+
if (!this.bgmTimer && !this.muted) {
|
|
119
|
+
this.startBGM();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
toggleMute() {
|
|
123
|
+
this.muted = !this.muted;
|
|
124
|
+
const btn = document.getElementById('mute-btn');
|
|
125
|
+
if (btn) btn.innerText = this.muted ? '🔇' : '🔊';
|
|
126
|
+
if (this.muted && this.bgmTimer) {
|
|
127
|
+
clearInterval(this.bgmTimer);
|
|
128
|
+
this.bgmTimer = null;
|
|
129
|
+
} else if (!this.muted) {
|
|
130
|
+
this.startBGM();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
playSFX(type) {
|
|
134
|
+
if (this.muted || !this.ctx) return;
|
|
135
|
+
try {
|
|
136
|
+
const osc = this.ctx.createOscillator();
|
|
137
|
+
const gain = this.ctx.createGain();
|
|
138
|
+
osc.connect(gain);
|
|
139
|
+
gain.connect(this.ctx.destination);
|
|
140
|
+
const now = this.ctx.currentTime;
|
|
141
|
+
|
|
142
|
+
if (type === 'laser') {
|
|
143
|
+
osc.type = 'sawtooth';
|
|
144
|
+
osc.frequency.setValueAtTime(800, now);
|
|
145
|
+
osc.frequency.exponentialRampToValueAtTime(120, now + 0.18);
|
|
146
|
+
gain.gain.setValueAtTime(0.25, now);
|
|
147
|
+
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.18);
|
|
148
|
+
osc.start(now);
|
|
149
|
+
osc.stop(now + 0.18);
|
|
150
|
+
} else if (type === 'explosion') {
|
|
151
|
+
const bufferSize = this.ctx.sampleRate * 0.5;
|
|
152
|
+
const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);
|
|
153
|
+
const data = buffer.getChannelData(0);
|
|
154
|
+
for (let i = 0; i < bufferSize; i++) data[i] = Math.random() * 2 - 1;
|
|
155
|
+
const noise = this.ctx.createBufferSource();
|
|
156
|
+
noise.buffer = buffer;
|
|
157
|
+
const filter = this.ctx.createBiquadFilter();
|
|
158
|
+
filter.type = 'lowpass';
|
|
159
|
+
filter.frequency.setValueAtTime(400, now);
|
|
160
|
+
filter.frequency.linearRampToValueAtTime(60, now + 0.5);
|
|
161
|
+
noise.connect(filter);
|
|
162
|
+
filter.connect(gain);
|
|
163
|
+
gain.gain.setValueAtTime(0.4, now);
|
|
164
|
+
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.5);
|
|
165
|
+
noise.start(now);
|
|
166
|
+
}
|
|
167
|
+
} catch (e) {}
|
|
168
|
+
}
|
|
169
|
+
startBGM() {
|
|
170
|
+
if (this.muted || !this.ctx || this.bgmTimer) return;
|
|
171
|
+
const notes = [130.81, 164.81, 196.00, 233.08]; // C3, E3, G3, Bb3 Synthwave Arp
|
|
172
|
+
let idx = 0;
|
|
173
|
+
this.bgmTimer = setInterval(() => {
|
|
174
|
+
if (this.muted || !this.ctx) return;
|
|
175
|
+
try {
|
|
176
|
+
const osc = this.ctx.createOscillator();
|
|
177
|
+
const gain = this.ctx.createGain();
|
|
178
|
+
osc.type = 'triangle';
|
|
179
|
+
osc.frequency.value = notes[idx % notes.length];
|
|
180
|
+
idx++;
|
|
181
|
+
osc.connect(gain);
|
|
182
|
+
gain.connect(this.ctx.destination);
|
|
183
|
+
const now = this.ctx.currentTime;
|
|
184
|
+
gain.gain.setValueAtTime(0.06, now);
|
|
185
|
+
gain.gain.exponentialRampToValueAtTime(0.005, now + 0.16);
|
|
186
|
+
osc.start(now);
|
|
187
|
+
osc.stop(now + 0.16);
|
|
188
|
+
} catch (e) {}
|
|
189
|
+
}, 180);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const audio = new SovereignAudioEngine();
|
|
193
|
+
document.getElementById('mute-btn').addEventListener('click', () => audio.toggleMute());
|
|
194
|
+
window.addEventListener('pointerdown', () => audio.init(), { once: true });
|
|
195
|
+
window.addEventListener('keydown', () => audio.init(), { once: true });
|
|
196
|
+
|
|
197
|
+
// Scene, Camera, Renderer
|
|
198
|
+
const container = document.getElementById('canvas-container');
|
|
199
|
+
const scene = new THREE.Scene();
|
|
200
|
+
scene.fog = new THREE.FogExp2(0x050811, 0.015);
|
|
201
|
+
|
|
202
|
+
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
203
|
+
camera.position.set(0, 4, 12);
|
|
204
|
+
camera.lookAt(0, 0, -10);
|
|
205
|
+
|
|
206
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
|
|
207
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
208
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
209
|
+
renderer.shadowMap.enabled = true;
|
|
210
|
+
container.appendChild(renderer.domElement);
|
|
211
|
+
|
|
212
|
+
// Lighting
|
|
213
|
+
const ambLight = new THREE.AmbientLight(0x223344, 1.5);
|
|
214
|
+
scene.add(ambLight);
|
|
215
|
+
|
|
216
|
+
const dirLight = new THREE.DirectionalLight(0x00ffcc, 2.0);
|
|
217
|
+
dirLight.position.set(10, 20, 10);
|
|
218
|
+
scene.add(dirLight);
|
|
219
|
+
|
|
220
|
+
// Player Ship Rig (Cyberpunk Jet)
|
|
221
|
+
const shipGroup = new THREE.Group();
|
|
222
|
+
const bodyGeo = new THREE.ConeGeometry(0.8, 2.5, 4);
|
|
223
|
+
bodyGeo.rotateX(Math.PI / 2);
|
|
224
|
+
const bodyMat = new THREE.MeshStandardMaterial({ color: 0x00ffcc, metalness: 0.8, roughness: 0.2, wireframe: false });
|
|
225
|
+
const shipBody = new THREE.Mesh(bodyGeo, bodyMat);
|
|
226
|
+
shipGroup.add(shipBody);
|
|
227
|
+
|
|
228
|
+
const wingGeo = new THREE.BoxGeometry(3.0, 0.1, 0.8);
|
|
229
|
+
const wingMat = new THREE.MeshStandardMaterial({ color: 0x112233, metalness: 0.9 });
|
|
230
|
+
const shipWings = new THREE.Mesh(wingGeo, wingMat);
|
|
231
|
+
shipWings.position.set(0, -0.2, 0.5);
|
|
232
|
+
shipGroup.add(shipWings);
|
|
233
|
+
scene.add(shipGroup);
|
|
234
|
+
shipGroup.position.set(0, 0, 0);
|
|
235
|
+
|
|
236
|
+
// Grid Tunnel Environment
|
|
237
|
+
const gridHelper = new THREE.GridHelper(200, 50, 0x00ffcc, 0x112233);
|
|
238
|
+
gridHelper.position.y = -3;
|
|
239
|
+
scene.add(gridHelper);
|
|
240
|
+
|
|
241
|
+
// Game State & Arrays
|
|
242
|
+
let score = 0;
|
|
243
|
+
let health = 100;
|
|
244
|
+
let isGameOver = false;
|
|
245
|
+
const lasers = [];
|
|
246
|
+
const enemies = [];
|
|
247
|
+
const particles = [];
|
|
248
|
+
|
|
249
|
+
// Controls State
|
|
250
|
+
const keys = { Left: false, Right: false, Up: false, Down: false, Space: false };
|
|
251
|
+
let joyX = 0, joyY = 0;
|
|
252
|
+
|
|
253
|
+
window.addEventListener('keydown', (e) => {
|
|
254
|
+
if (e.code === 'ArrowLeft' || e.code === 'KeyA') keys.Left = true;
|
|
255
|
+
if (e.code === 'ArrowRight' || e.code === 'KeyD') keys.Right = true;
|
|
256
|
+
if (e.code === 'ArrowUp' || e.code === 'KeyW') keys.Up = true;
|
|
257
|
+
if (e.code === 'ArrowDown' || e.code === 'KeyS') keys.Down = true;
|
|
258
|
+
if (e.code === 'Space') { keys.Space = true; fireLaser(); }
|
|
259
|
+
});
|
|
260
|
+
window.addEventListener('keyup', (e) => {
|
|
261
|
+
if (e.code === 'ArrowLeft' || e.code === 'KeyA') keys.Left = false;
|
|
262
|
+
if (e.code === 'ArrowRight' || e.code === 'KeyD') keys.Right = false;
|
|
263
|
+
if (e.code === 'ArrowUp' || e.code === 'KeyW') keys.Up = false;
|
|
264
|
+
if (e.code === 'ArrowDown' || e.code === 'KeyS') keys.Down = false;
|
|
265
|
+
if (e.code === 'Space') keys.Space = false;
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const joystick = document.getElementById('joystick');
|
|
269
|
+
const knob = document.getElementById('knob');
|
|
270
|
+
joystick.addEventListener('pointermove', (e) => {
|
|
271
|
+
if (e.buttons !== 1) return;
|
|
272
|
+
const rect = joystick.getBoundingClientRect();
|
|
273
|
+
const cx = rect.left + rect.width / 2;
|
|
274
|
+
const cy = rect.top + rect.height / 2;
|
|
275
|
+
let dx = e.clientX - cx;
|
|
276
|
+
let dy = e.clientY - cy;
|
|
277
|
+
const dist = Math.min(35, Math.hypot(dx, dy));
|
|
278
|
+
const angle = Math.atan2(dy, dx);
|
|
279
|
+
knob.style.transform = \`translate(\${Math.cos(angle)*dist}px, \${Math.sin(angle)*dist}px)\`;
|
|
280
|
+
joyX = (Math.cos(angle) * dist) / 35;
|
|
281
|
+
joyY = (Math.sin(angle) * dist) / 35;
|
|
282
|
+
});
|
|
283
|
+
joystick.addEventListener('pointerup', () => {
|
|
284
|
+
knob.style.transform = 'translate(0, 0)';
|
|
285
|
+
joyX = 0; joyY = 0;
|
|
286
|
+
});
|
|
287
|
+
document.getElementById('fire-btn').addEventListener('pointerdown', fireLaser);
|
|
288
|
+
|
|
289
|
+
function fireLaser() {
|
|
290
|
+
if (isGameOver) return;
|
|
291
|
+
audio.init();
|
|
292
|
+
audio.playSFX('laser');
|
|
293
|
+
const laserGeo = new THREE.CylinderGeometry(0.1, 0.1, 1.5, 8);
|
|
294
|
+
laserGeo.rotateX(Math.PI / 2);
|
|
295
|
+
const laserMat = new THREE.MeshBasicMaterial({ color: 0xff3366 });
|
|
296
|
+
const laser = new THREE.Mesh(laserGeo, laserMat);
|
|
297
|
+
laser.position.copy(shipGroup.position);
|
|
298
|
+
laser.position.z -= 1.5;
|
|
299
|
+
scene.add(laser);
|
|
300
|
+
lasers.push(laser);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function spawnEnemy() {
|
|
304
|
+
if (isGameOver) return;
|
|
305
|
+
const geo = new THREE.DodecahedronGeometry(1.2, 0);
|
|
306
|
+
const mat = new THREE.MeshStandardMaterial({ color: 0xff3366, roughness: 0.4, metalness: 0.6 });
|
|
307
|
+
const enemy = new THREE.Mesh(geo, mat);
|
|
308
|
+
enemy.position.set((Math.random() - 0.5) * 20, (Math.random() - 0.5) * 10, -60);
|
|
309
|
+
scene.add(enemy);
|
|
310
|
+
enemies.push(enemy);
|
|
311
|
+
}
|
|
312
|
+
setInterval(spawnEnemy, 1200);
|
|
313
|
+
|
|
314
|
+
function spawnExplosion(pos, colorHex) {
|
|
315
|
+
for (let i = 0; i < 12; i++) {
|
|
316
|
+
const pGeo = new THREE.SphereGeometry(0.2, 4, 4);
|
|
317
|
+
const pMat = new THREE.MeshBasicMaterial({ color: colorHex });
|
|
318
|
+
const p = new THREE.Mesh(pGeo, pMat);
|
|
319
|
+
p.position.copy(pos);
|
|
320
|
+
p.userData = {
|
|
321
|
+
vx: (Math.random() - 0.5) * 0.8,
|
|
322
|
+
vy: (Math.random() - 0.5) * 0.8,
|
|
323
|
+
vz: (Math.random() - 0.5) * 0.8,
|
|
324
|
+
life: 1.0
|
|
325
|
+
};
|
|
326
|
+
scene.add(p);
|
|
327
|
+
particles.push(p);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function animate() {
|
|
332
|
+
if (isGameOver) return;
|
|
333
|
+
requestAnimationFrame(animate);
|
|
334
|
+
|
|
335
|
+
let vx = (joyX + (keys.Right ? 1 : 0) - (keys.Left ? 1 : 0)) * 0.35;
|
|
336
|
+
let vy = (-joyY + (keys.Up ? 1 : 0) - (keys.Down ? 1 : 0)) * 0.35;
|
|
337
|
+
shipGroup.position.x = Math.max(-12, Math.min(12, shipGroup.position.x + vx));
|
|
338
|
+
shipGroup.position.y = Math.max(-2, Math.min(8, shipGroup.position.y + vy));
|
|
339
|
+
shipGroup.rotation.z = -vx * 1.5;
|
|
340
|
+
shipGroup.rotation.x = vy * 0.5;
|
|
341
|
+
|
|
342
|
+
gridHelper.position.z = (gridHelper.position.z + 0.4) % 4;
|
|
343
|
+
|
|
344
|
+
for (let i = lasers.length - 1; i >= 0; i--) {
|
|
345
|
+
lasers[i].position.z -= 1.8;
|
|
346
|
+
if (lasers[i].position.z < -80) {
|
|
347
|
+
scene.remove(lasers[i]);
|
|
348
|
+
lasers.splice(i, 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
for (let i = enemies.length - 1; i >= 0; i--) {
|
|
353
|
+
const en = enemies[i];
|
|
354
|
+
en.position.z += 0.45;
|
|
355
|
+
en.rotation.x += 0.02;
|
|
356
|
+
en.rotation.y += 0.03;
|
|
357
|
+
|
|
358
|
+
if (en.position.distanceTo(shipGroup.position) < 2.0) {
|
|
359
|
+
audio.playSFX('explosion');
|
|
360
|
+
spawnExplosion(en.position, 0xff3366);
|
|
361
|
+
scene.remove(en);
|
|
362
|
+
enemies.splice(i, 1);
|
|
363
|
+
health -= 25;
|
|
364
|
+
document.getElementById('health').innerText = \`SHIELD: \${Math.max(0, health)}%\`;
|
|
365
|
+
if (health <= 0) triggerGameOver();
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
for (let j = lasers.length - 1; j >= 0; j--) {
|
|
370
|
+
if (en.position.distanceTo(lasers[j].position) < 1.8) {
|
|
371
|
+
audio.playSFX('explosion');
|
|
372
|
+
spawnExplosion(en.position, 0x00ffcc);
|
|
373
|
+
scene.remove(en);
|
|
374
|
+
scene.remove(lasers[j]);
|
|
375
|
+
enemies.splice(i, 1);
|
|
376
|
+
lasers.splice(j, 1);
|
|
377
|
+
score += 100;
|
|
378
|
+
document.getElementById('score').innerText = \`SCORE: \${score}\`;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (en && en.position.z > 15) {
|
|
384
|
+
scene.remove(en);
|
|
385
|
+
enemies.splice(i, 1);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
for (let i = particles.length - 1; i >= 0; i--) {
|
|
390
|
+
const p = particles[i];
|
|
391
|
+
p.position.x += p.userData.vx;
|
|
392
|
+
p.position.y += p.userData.vy;
|
|
393
|
+
p.position.z += p.userData.vz;
|
|
394
|
+
p.userData.life -= 0.04;
|
|
395
|
+
p.scale.setScalar(p.userData.life);
|
|
396
|
+
if (p.userData.life <= 0) {
|
|
397
|
+
scene.remove(p);
|
|
398
|
+
particles.splice(i, 1);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
renderer.render(scene, camera);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function triggerGameOver() {
|
|
406
|
+
isGameOver = true;
|
|
407
|
+
document.getElementById('final-score').innerText = score;
|
|
408
|
+
document.getElementById('game-over').style.display = 'flex';
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
window.addEventListener('resize', () => {
|
|
412
|
+
camera.aspect = window.innerWidth / window.innerHeight;
|
|
413
|
+
camera.updateProjectionMatrix();
|
|
414
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
animate();
|
|
418
|
+
</script>
|
|
419
|
+
</body>
|
|
420
|
+
</html>`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// -----------------------------------------------------------------------------
|
|
424
|
+
// Benchmark Template 2: 2D Cyberpunk Platformer (Canvas 2D + Web Audio)
|
|
425
|
+
// -----------------------------------------------------------------------------
|
|
426
|
+
function getArcadePlatformer2dTemplate(title, includeAudio = true) {
|
|
427
|
+
return `<!DOCTYPE html>
|
|
428
|
+
<html lang="en">
|
|
429
|
+
<head>
|
|
430
|
+
<meta charset="UTF-8">
|
|
431
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
432
|
+
<title>${title} — Causyne 2D Arcade Engine</title>
|
|
433
|
+
<style>
|
|
434
|
+
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
|
|
435
|
+
body { background: #080a12; overflow: hidden; font-family: 'JetBrains Mono', monospace; display: flex; align-items: center; justify-content: center; height: 100vh; }
|
|
436
|
+
canvas { background: #0d1220; border: 2px solid #00ffcc; box-shadow: 0 0 30px rgba(0, 255, 204, 0.3); max-width: 100vw; max-height: 100vh; }
|
|
437
|
+
#hud { position: absolute; top: 20px; left: 20px; right: 20px; display: flex; justify-content: space-between; pointer-events: none; }
|
|
438
|
+
#mute-btn {
|
|
439
|
+
background: rgba(10, 15, 25, 0.8); border: 1px solid #00ffcc; color: #fff;
|
|
440
|
+
padding: 8px 14px; border-radius: 20px; font-size: 18px; cursor: pointer; pointer-events: auto;
|
|
441
|
+
}
|
|
442
|
+
#mobile-controls {
|
|
443
|
+
position: absolute; bottom: 20px; left: 20px; right: 20px;
|
|
444
|
+
display: flex; justify-content: space-between; pointer-events: none;
|
|
445
|
+
}
|
|
446
|
+
.btn-group { display: flex; gap: 15px; pointer-events: auto; }
|
|
447
|
+
.touch-btn {
|
|
448
|
+
width: 70px; height: 70px; background: rgba(0, 255, 204, 0.2);
|
|
449
|
+
border: 2px solid #00ffcc; border-radius: 12px; color: #fff; font-size: 24px;
|
|
450
|
+
font-weight: bold; display: flex; align-items: center; justify-content: center;
|
|
451
|
+
}
|
|
452
|
+
.touch-btn:active { background: #00ffcc; color: #000; }
|
|
453
|
+
</style>
|
|
454
|
+
</head>
|
|
455
|
+
<body>
|
|
456
|
+
<div id="hud">
|
|
457
|
+
<span style="color: #fff; font-size: 24px; font-weight: bold;"></span>
|
|
458
|
+
<button id="mute-btn" title="Toggle Audio">🔊</button>
|
|
459
|
+
</div>
|
|
460
|
+
<canvas id="gameCanvas" width="960" height="540"></canvas>
|
|
461
|
+
|
|
462
|
+
<div id="mobile-controls">
|
|
463
|
+
<div class="btn-group">
|
|
464
|
+
<div class="touch-btn" id="btn-left">◀</div>
|
|
465
|
+
<div class="touch-btn" id="btn-right">▶</div>
|
|
466
|
+
</div>
|
|
467
|
+
<div class="btn-group">
|
|
468
|
+
<div class="touch-btn" id="btn-jump" style="background: rgba(255, 51, 102, 0.2); border-color: #ff3366;">▲</div>
|
|
469
|
+
</div>
|
|
470
|
+
</div>
|
|
471
|
+
|
|
472
|
+
<script>
|
|
473
|
+
// ── Sovereign Web Audio API Synthesizer ──
|
|
474
|
+
class SovereignAudioEngine {
|
|
475
|
+
constructor() {
|
|
476
|
+
this.ctx = null;
|
|
477
|
+
this.muted = false;
|
|
478
|
+
this.bgmTimer = null;
|
|
479
|
+
}
|
|
480
|
+
init() {
|
|
481
|
+
if (!this.ctx) {
|
|
482
|
+
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
483
|
+
if (AudioCtx) this.ctx = new AudioCtx();
|
|
484
|
+
}
|
|
485
|
+
if (this.ctx && this.ctx.state === 'suspended') {
|
|
486
|
+
this.ctx.resume();
|
|
487
|
+
}
|
|
488
|
+
if (!this.bgmTimer && !this.muted) {
|
|
489
|
+
this.startBGM();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
toggleMute() {
|
|
493
|
+
this.muted = !this.muted;
|
|
494
|
+
const btn = document.getElementById('mute-btn');
|
|
495
|
+
if (btn) btn.innerText = this.muted ? '🔇' : '🔊';
|
|
496
|
+
if (this.muted && this.bgmTimer) {
|
|
497
|
+
clearInterval(this.bgmTimer);
|
|
498
|
+
this.bgmTimer = null;
|
|
499
|
+
} else if (!this.muted) {
|
|
500
|
+
this.startBGM();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
playSFX(type) {
|
|
504
|
+
if (this.muted || !this.ctx) return;
|
|
505
|
+
try {
|
|
506
|
+
const osc = this.ctx.createOscillator();
|
|
507
|
+
const gain = this.ctx.createGain();
|
|
508
|
+
osc.connect(gain);
|
|
509
|
+
gain.connect(this.ctx.destination);
|
|
510
|
+
const now = this.ctx.currentTime;
|
|
511
|
+
|
|
512
|
+
if (type === 'jump') {
|
|
513
|
+
osc.type = 'square';
|
|
514
|
+
osc.frequency.setValueAtTime(260, now);
|
|
515
|
+
osc.frequency.linearRampToValueAtTime(560, now + 0.15);
|
|
516
|
+
gain.gain.setValueAtTime(0.2, now);
|
|
517
|
+
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.15);
|
|
518
|
+
osc.start(now);
|
|
519
|
+
osc.stop(now + 0.15);
|
|
520
|
+
} else if (type === 'coin') {
|
|
521
|
+
osc.type = 'sine';
|
|
522
|
+
osc.frequency.setValueAtTime(1200, now);
|
|
523
|
+
osc.frequency.setValueAtTime(1800, now + 0.08);
|
|
524
|
+
gain.gain.setValueAtTime(0.25, now);
|
|
525
|
+
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.28);
|
|
526
|
+
osc.start(now);
|
|
527
|
+
osc.stop(now + 0.28);
|
|
528
|
+
}
|
|
529
|
+
} catch (e) {}
|
|
530
|
+
}
|
|
531
|
+
startBGM() {
|
|
532
|
+
if (this.muted || !this.ctx || this.bgmTimer) return;
|
|
533
|
+
const notes = [164.81, 196.00, 220.00, 261.63]; // E3, G3, A3, C4 Arp
|
|
534
|
+
let idx = 0;
|
|
535
|
+
this.bgmTimer = setInterval(() => {
|
|
536
|
+
if (this.muted || !this.ctx) return;
|
|
537
|
+
try {
|
|
538
|
+
const osc = this.ctx.createOscillator();
|
|
539
|
+
const gain = this.ctx.createGain();
|
|
540
|
+
osc.type = 'triangle';
|
|
541
|
+
osc.frequency.value = notes[idx % notes.length];
|
|
542
|
+
idx++;
|
|
543
|
+
osc.connect(gain);
|
|
544
|
+
gain.connect(this.ctx.destination);
|
|
545
|
+
const now = this.ctx.currentTime;
|
|
546
|
+
gain.gain.setValueAtTime(0.06, now);
|
|
547
|
+
gain.gain.exponentialRampToValueAtTime(0.005, now + 0.16);
|
|
548
|
+
osc.start(now);
|
|
549
|
+
osc.stop(now + 0.16);
|
|
550
|
+
} catch (e) {}
|
|
551
|
+
}, 180);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const audio = new SovereignAudioEngine();
|
|
555
|
+
document.getElementById('mute-btn').addEventListener('click', () => audio.toggleMute());
|
|
556
|
+
window.addEventListener('pointerdown', () => audio.init(), { once: true });
|
|
557
|
+
window.addEventListener('keydown', () => audio.init(), { once: true });
|
|
558
|
+
|
|
559
|
+
const canvas = document.getElementById('gameCanvas');
|
|
560
|
+
const ctx = canvas.getContext('2d');
|
|
561
|
+
|
|
562
|
+
const player = {
|
|
563
|
+
x: 100, y: 300, w: 36, h: 48, vx: 0, vy: 0, speed: 6, jump: -14,
|
|
564
|
+
grounded: false, color: '#00ffcc'
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const gravity = 0.65;
|
|
568
|
+
const keys = { left: false, right: false, up: false };
|
|
569
|
+
|
|
570
|
+
const platforms = [
|
|
571
|
+
{ x: 0, y: 500, w: 960, h: 40, color: '#1a243a' },
|
|
572
|
+
{ x: 180, y: 380, w: 200, h: 20, color: '#00ffcc' },
|
|
573
|
+
{ x: 450, y: 280, w: 180, h: 20, color: '#ff3366' },
|
|
574
|
+
{ x: 700, y: 180, w: 200, h: 20, color: '#00ffcc' }
|
|
575
|
+
];
|
|
576
|
+
|
|
577
|
+
const coins = [
|
|
578
|
+
{ x: 260, y: 340, r: 12, collected: false },
|
|
579
|
+
{ x: 530, y: 240, r: 12, collected: false },
|
|
580
|
+
{ x: 780, y: 140, r: 12, collected: false }
|
|
581
|
+
];
|
|
582
|
+
let score = 0;
|
|
583
|
+
|
|
584
|
+
window.addEventListener('keydown', (e) => {
|
|
585
|
+
if (e.code === 'ArrowLeft' || e.code === 'KeyA') keys.left = true;
|
|
586
|
+
if (e.code === 'ArrowRight' || e.code === 'KeyD') keys.right = true;
|
|
587
|
+
if ((e.code === 'ArrowUp' || e.code === 'Space') && player.grounded) {
|
|
588
|
+
player.vy = player.jump; player.grounded = false;
|
|
589
|
+
audio.init(); audio.playSFX('jump');
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
window.addEventListener('keyup', (e) => {
|
|
593
|
+
if (e.code === 'ArrowLeft' || e.code === 'KeyA') keys.left = false;
|
|
594
|
+
if (e.code === 'ArrowRight' || e.code === 'KeyD') keys.right = false;
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
document.getElementById('btn-left').addEventListener('pointerdown', () => keys.left = true);
|
|
598
|
+
document.getElementById('btn-left').addEventListener('pointerup', () => keys.left = false);
|
|
599
|
+
document.getElementById('btn-right').addEventListener('pointerdown', () => keys.right = true);
|
|
600
|
+
document.getElementById('btn-right').addEventListener('pointerup', () => keys.right = false);
|
|
601
|
+
document.getElementById('btn-jump').addEventListener('pointerdown', () => {
|
|
602
|
+
if (player.grounded) {
|
|
603
|
+
player.vy = player.jump; player.grounded = false;
|
|
604
|
+
audio.init(); audio.playSFX('jump');
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
function update() {
|
|
609
|
+
if (keys.left) player.vx = -player.speed;
|
|
610
|
+
else if (keys.right) player.vx = player.speed;
|
|
611
|
+
else player.vx *= 0.8;
|
|
612
|
+
|
|
613
|
+
player.x += player.vx;
|
|
614
|
+
player.vy += gravity;
|
|
615
|
+
player.y += player.vy;
|
|
616
|
+
player.grounded = false;
|
|
617
|
+
|
|
618
|
+
for (const p of platforms) {
|
|
619
|
+
if (player.x < p.x + p.w && player.x + player.w > p.x &&
|
|
620
|
+
player.y + player.h > p.y && player.y + player.h < p.y + p.h + player.vy) {
|
|
621
|
+
player.y = p.y - player.h;
|
|
622
|
+
player.vy = 0;
|
|
623
|
+
player.grounded = true;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
for (const c of coins) {
|
|
628
|
+
if (!c.collected && Math.hypot(player.x + player.w/2 - c.x, player.y + player.h/2 - c.y) < c.r + 18) {
|
|
629
|
+
c.collected = true;
|
|
630
|
+
score += 100;
|
|
631
|
+
audio.playSFX('coin');
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (player.x < 0) player.x = 0;
|
|
636
|
+
if (player.x + player.w > canvas.width) player.x = canvas.width - player.w;
|
|
637
|
+
if (player.y > canvas.height) { player.x = 100; player.y = 300; player.vy = 0; }
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function draw() {
|
|
641
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
642
|
+
|
|
643
|
+
for (const p of platforms) {
|
|
644
|
+
ctx.fillStyle = p.color;
|
|
645
|
+
ctx.fillRect(p.x, p.y, p.w, p.h);
|
|
646
|
+
ctx.shadowColor = p.color;
|
|
647
|
+
ctx.shadowBlur = 10;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
for (const c of coins) {
|
|
651
|
+
if (!c.collected) {
|
|
652
|
+
ctx.beginPath();
|
|
653
|
+
ctx.arc(c.x, c.y, c.r, 0, Math.PI * 2);
|
|
654
|
+
ctx.fillStyle = '#ffcc00';
|
|
655
|
+
ctx.fill();
|
|
656
|
+
ctx.shadowColor = '#ffcc00';
|
|
657
|
+
ctx.shadowBlur = 15;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
ctx.fillStyle = player.color;
|
|
662
|
+
ctx.fillRect(player.x, player.y, player.w, player.h);
|
|
663
|
+
ctx.shadowColor = player.color;
|
|
664
|
+
ctx.shadowBlur = 20;
|
|
665
|
+
|
|
666
|
+
ctx.shadowBlur = 0;
|
|
667
|
+
ctx.fillStyle = '#fff';
|
|
668
|
+
ctx.font = 'bold 24px JetBrains Mono';
|
|
669
|
+
ctx.fillText(\`SCORE: \${score}\`, 20, 40);
|
|
670
|
+
|
|
671
|
+
requestAnimationFrame(() => { update(); draw(); });
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
draw();
|
|
675
|
+
</script>
|
|
676
|
+
</body>
|
|
677
|
+
</html>`;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// -----------------------------------------------------------------------------
|
|
681
|
+
// Benchmark Template 3: 3D Cyberpunk Highway Racer (Three.js + Web Audio)
|
|
682
|
+
// -----------------------------------------------------------------------------
|
|
683
|
+
function getCyberpunkRacer3dTemplate(title, includeAudio = true) {
|
|
684
|
+
return `<!DOCTYPE html>
|
|
685
|
+
<html lang="en">
|
|
686
|
+
<head>
|
|
687
|
+
<meta charset="UTF-8">
|
|
688
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
689
|
+
<title>${title} — Cyberpunk Racer 3D</title>
|
|
690
|
+
<style>
|
|
691
|
+
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
|
|
692
|
+
body { background: #03050c; overflow: hidden; font-family: 'Outfit', sans-serif; }
|
|
693
|
+
#canvas-container { width: 100vw; height: 100vh; display: block; }
|
|
694
|
+
#hud {
|
|
695
|
+
position: absolute; top: 20px; left: 20px; right: 20px;
|
|
696
|
+
display: flex; justify-content: space-between; align-items: center; pointer-events: none;
|
|
697
|
+
color: #fff; text-shadow: 0 0 10px #00ffcc;
|
|
698
|
+
}
|
|
699
|
+
.hud-box {
|
|
700
|
+
background: rgba(10, 15, 25, 0.7); border: 1px solid #00ffcc;
|
|
701
|
+
padding: 12px 24px; border-radius: 8px; backdrop-filter: blur(10px); pointer-events: auto;
|
|
702
|
+
}
|
|
703
|
+
.speed-val { font-size: 28px; font-weight: 800; color: #ff0055; }
|
|
704
|
+
</style>
|
|
705
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
706
|
+
</head>
|
|
707
|
+
<body>
|
|
708
|
+
<div id="canvas-container"></div>
|
|
709
|
+
<div id="hud">
|
|
710
|
+
<div class="hud-box"><span class="speed-val" id="speed-hud">SPEED: 0 MPH</span></div>
|
|
711
|
+
<div class="hud-box"><span id="score-hud" style="font-size: 24px; font-weight: bold; color: #00ffcc;">DISTANCE: 0 M</span></div>
|
|
712
|
+
</div>
|
|
713
|
+
<script>
|
|
714
|
+
const container = document.getElementById('canvas-container');
|
|
715
|
+
const scene = new THREE.Scene();
|
|
716
|
+
scene.fog = new THREE.FogExp2(0x050814, 0.02);
|
|
717
|
+
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
718
|
+
camera.position.set(0, 4, 10);
|
|
719
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
720
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
721
|
+
container.appendChild(renderer.domElement);
|
|
722
|
+
|
|
723
|
+
const ambLight = new THREE.AmbientLight(0x223344, 2.0);
|
|
724
|
+
scene.add(ambLight);
|
|
725
|
+
const dirLight = new THREE.DirectionalLight(0x00ffcc, 1.5);
|
|
726
|
+
dirLight.position.set(10, 20, 10);
|
|
727
|
+
scene.add(dirLight);
|
|
728
|
+
|
|
729
|
+
// Road
|
|
730
|
+
const roadGeo = new THREE.PlaneGeometry(16, 600, 10, 100);
|
|
731
|
+
roadGeo.rotateX(-Math.PI / 2);
|
|
732
|
+
const roadMat = new THREE.MeshStandardMaterial({ color: 0x0f1422, roughness: 0.8 });
|
|
733
|
+
const road = new THREE.Mesh(roadGeo, roadMat);
|
|
734
|
+
scene.add(road);
|
|
735
|
+
|
|
736
|
+
// Car
|
|
737
|
+
const carGeo = new THREE.BoxGeometry(2.0, 0.8, 4.0);
|
|
738
|
+
const carMat = new THREE.MeshStandardMaterial({ color: 0xff0055, metalness: 0.9, roughness: 0.1 });
|
|
739
|
+
const car = new THREE.Mesh(carGeo, carMat);
|
|
740
|
+
car.position.set(0, 0.5, 3);
|
|
741
|
+
scene.add(car);
|
|
742
|
+
|
|
743
|
+
let speed = 0, targetSpeed = 120, distance = 0;
|
|
744
|
+
const keys = { Left: false, Right: false, Up: false, Down: false };
|
|
745
|
+
window.addEventListener('keydown', e => { if(e.code==='ArrowLeft'||e.code==='KeyA') keys.Left=true; if(e.code==='ArrowRight'||e.code==='KeyD') keys.Right=true; if(e.code==='ArrowUp'||e.code==='KeyW') keys.Up=true; });
|
|
746
|
+
window.addEventListener('keyup', e => { if(e.code==='ArrowLeft'||e.code==='KeyA') keys.Left=false; if(e.code==='ArrowRight'||e.code==='KeyD') keys.Right=false; if(e.code==='ArrowUp'||e.code==='KeyW') keys.Up=false; });
|
|
747
|
+
|
|
748
|
+
function animate() {
|
|
749
|
+
requestAnimationFrame(animate);
|
|
750
|
+
if (keys.Up) speed = Math.min(220, speed + 1.5); else speed = Math.max(30, speed - 0.5);
|
|
751
|
+
if (keys.Left) car.position.x = Math.max(-6, car.position.x - 0.25);
|
|
752
|
+
if (keys.Right) car.position.x = Math.min(6, car.position.x + 0.25);
|
|
753
|
+
car.rotation.z = (car.position.x * -0.05);
|
|
754
|
+
distance += speed * 0.05;
|
|
755
|
+
document.getElementById('speed-hud').innerText = \`SPEED: \${Math.round(speed)} MPH\`;
|
|
756
|
+
document.getElementById('score-hud').innerText = \`DISTANCE: \${Math.round(distance)} M\`;
|
|
757
|
+
renderer.render(scene, camera);
|
|
758
|
+
}
|
|
759
|
+
animate();
|
|
760
|
+
</script>
|
|
761
|
+
</body>
|
|
762
|
+
</html>`;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// -----------------------------------------------------------------------------
|
|
766
|
+
// Benchmark Template 4: 2D Top-Down RPG (Canvas 2D + Web Audio)
|
|
767
|
+
// -----------------------------------------------------------------------------
|
|
768
|
+
function getTopdownRpg2dTemplate(title, includeAudio = true) {
|
|
769
|
+
return `<!DOCTYPE html>
|
|
770
|
+
<html lang="en">
|
|
771
|
+
<head>
|
|
772
|
+
<meta charset="UTF-8">
|
|
773
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
774
|
+
<title>${title} — Topdown RPG 2D</title>
|
|
775
|
+
<style>
|
|
776
|
+
body { margin: 0; background: #11141a; display: flex; align-items: center; justify-content: center; height: 100vh; font-family: sans-serif; color: #fff; }
|
|
777
|
+
canvas { background: #1b2233; border: 2px solid #3a86ff; box-shadow: 0 0 20px rgba(58,134,255,0.4); }
|
|
778
|
+
</style>
|
|
779
|
+
</head>
|
|
780
|
+
<body>
|
|
781
|
+
<canvas id="rpgCanvas" width="800" height="600"></canvas>
|
|
782
|
+
<script>
|
|
783
|
+
const canvas = document.getElementById('rpgCanvas');
|
|
784
|
+
const ctx = canvas.getContext('2d');
|
|
785
|
+
const hero = { x: 400, y: 300, r: 18, speed: 4, color: '#3a86ff' };
|
|
786
|
+
const keys = {};
|
|
787
|
+
window.addEventListener('keydown', e => keys[e.code] = true);
|
|
788
|
+
window.addEventListener('keyup', e => keys[e.code] = false);
|
|
789
|
+
|
|
790
|
+
function loop() {
|
|
791
|
+
if (keys['KeyW'] || keys['ArrowUp']) hero.y -= hero.speed;
|
|
792
|
+
if (keys['KeyS'] || keys['ArrowDown']) hero.y += hero.speed;
|
|
793
|
+
if (keys['KeyA'] || keys['ArrowLeft']) hero.x -= hero.speed;
|
|
794
|
+
if (keys['KeyD'] || keys['ArrowRight']) hero.x += hero.speed;
|
|
795
|
+
hero.x = Math.max(hero.r, Math.min(canvas.width - hero.r, hero.x));
|
|
796
|
+
hero.y = Math.max(hero.r, Math.min(canvas.height - hero.r, hero.y));
|
|
797
|
+
|
|
798
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
799
|
+
ctx.fillStyle = '#1e293b';
|
|
800
|
+
for(let x=0; x<canvas.width; x+=40) {
|
|
801
|
+
for(let y=0; y<canvas.height; y+=40) {
|
|
802
|
+
ctx.strokeRect(x, y, 40, 40);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
ctx.beginPath();
|
|
806
|
+
ctx.arc(hero.x, hero.y, hero.r, 0, Math.PI * 2);
|
|
807
|
+
ctx.fillStyle = hero.color;
|
|
808
|
+
ctx.fill();
|
|
809
|
+
ctx.shadowColor = hero.color;
|
|
810
|
+
ctx.shadowBlur = 15;
|
|
811
|
+
ctx.font = 'bold 20px sans-serif';
|
|
812
|
+
ctx.fillText('${title}', 20, 35);
|
|
813
|
+
requestAnimationFrame(loop);
|
|
814
|
+
}
|
|
815
|
+
loop();
|
|
816
|
+
</script>
|
|
817
|
+
</body>
|
|
818
|
+
</html>`;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export const gameBuilder = {
|
|
822
|
+
schema: {
|
|
823
|
+
name: 'game.build_html5',
|
|
824
|
+
description: 'Instant Sovereign HTML5 Game Engine Builder (`100% offline edge ready`). Generates complete, browser-playable 3D WebGL (Three.js) or 2D Arcade (Canvas 2D) games with procedural sound effects (`SFX`), looping background music (`BGM`), mobile touch controls, and WASD controls directly inside local workspace buffers (`space_defense_3d`, `arcade_platformer_2d`, `cyberpunk_racer_3d`, `topdown_rpg_2d`, `custom`).',
|
|
825
|
+
parameters: {
|
|
826
|
+
type: 'object',
|
|
827
|
+
properties: {
|
|
828
|
+
title: { type: 'string', description: 'Title of the game (`Sovereign Space Defense`, `Cyberpunk Racer 3D`).' },
|
|
829
|
+
engine: { type: 'string', enum: ['threejs', 'canvas2d'], description: 'Game engine selection: `threejs` (3D WebGL) or `canvas2d` (2D Arcade Physics).' },
|
|
830
|
+
template: {
|
|
831
|
+
type: 'string',
|
|
832
|
+
enum: ['space_defense_3d', 'arcade_platformer_2d', 'cyberpunk_racer_3d', 'topdown_rpg_2d', 'custom'],
|
|
833
|
+
description: 'Preset benchmark template (`space_defense_3d`, `arcade_platformer_2d`, `cyberpunk_racer_3d`, `topdown_rpg_2d`) or `custom` for custom script.'
|
|
834
|
+
},
|
|
835
|
+
audio: { type: 'boolean', description: 'Whether to embed the SovereignAudioEngine for procedural SFX & Synthwave BGM (default: true).' },
|
|
836
|
+
customScript: { type: 'string', description: 'Complete custom HTML/JS code if `template` is `custom`.' },
|
|
837
|
+
outputDir: { type: 'string', description: 'Target output directory. Defaults to `.tmp_causyne_3d` in current workspace.' },
|
|
838
|
+
filename: { type: 'string', description: 'Name of HTML file to write (default: `game.html`).' }
|
|
839
|
+
},
|
|
840
|
+
required: ['title', 'engine']
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
|
|
844
|
+
async execute(args) {
|
|
845
|
+
try {
|
|
846
|
+
const { title, engine, template, audio = true, customScript, outputDir, filename = 'game.html' } = args;
|
|
847
|
+
const targetDir = outputDir || getWorkspaceTempDir();
|
|
848
|
+
if (!fsSync.existsSync(targetDir)) {
|
|
849
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
let htmlContent = '';
|
|
853
|
+
if (template === 'custom' && customScript) {
|
|
854
|
+
htmlContent = customScript;
|
|
855
|
+
} else if (template === 'cyberpunk_racer_3d') {
|
|
856
|
+
htmlContent = getCyberpunkRacer3dTemplate(title, audio);
|
|
857
|
+
} else if (template === 'topdown_rpg_2d') {
|
|
858
|
+
htmlContent = getTopdownRpg2dTemplate(title, audio);
|
|
859
|
+
} else if (engine === 'threejs' || template === 'space_defense_3d') {
|
|
860
|
+
htmlContent = getSpaceDefense3dTemplate(title, audio);
|
|
861
|
+
} else {
|
|
862
|
+
htmlContent = getArcadePlatformer2dTemplate(title, audio);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const filePath = path.join(targetDir, filename);
|
|
866
|
+
await fs.writeFile(filePath, htmlContent, 'utf8');
|
|
867
|
+
|
|
868
|
+
return {
|
|
869
|
+
success: true,
|
|
870
|
+
output: JSON.stringify({
|
|
871
|
+
engine: engine === 'threejs' ? 'Three.js (3D WebGL + Web Audio)' : 'Canvas 2D Arcade Engine (+ Web Audio)',
|
|
872
|
+
template: template || (engine === 'threejs' ? 'space_defense_3d' : 'arcade_platformer_2d'),
|
|
873
|
+
title: title,
|
|
874
|
+
audio_enabled: audio,
|
|
875
|
+
output_file: filePath,
|
|
876
|
+
size_bytes: Buffer.byteLength(htmlContent, 'utf8'),
|
|
877
|
+
ready_to_play: true,
|
|
878
|
+
instructions: `Open ${filePath} directly in Google Chrome or via browser_act to play instantly across Desktop and Mobile.`
|
|
879
|
+
}, null, 2)
|
|
880
|
+
};
|
|
881
|
+
} catch (e) {
|
|
882
|
+
return { success: false, error: e.message };
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
|