action-engine-js 1.0.2 → 1.0.4

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 CHANGED
@@ -1,425 +1,425 @@
1
- # Action Engine JS
2
-
3
- A comprehensive JavaScript game framework that abstracts away the complexity of game development boilerplate, letting you focus on building your game.
4
-
5
- ## Overview
6
-
7
- Action Engine simplifies game creation by handling all the tedious infrastructure—input systems, audio, rendering, physics, and multi-layer canvas management—so you can focus on game logic.
8
-
9
- ### Core Features
10
-
11
- - **Multi-Layer Canvas System**: Separate game, UI, and debug rendering layers
12
- - **Built-in Input System**: Keyboard, mouse, and touch input handling
13
- - **Advanced Audio Engine**: MIDI instruments, FM synthesis, noise generation, reverb, echo, and more
14
- - **3D Physics & Rendering**: WebGL-based 3D rendering with rigid body physics
15
- - **Math Utilities**: Vector2, Vector3, and Matrix4 classes
16
- - **Procedural Geometry**: GeometryBuilder for creating complex 3D objects with automatic triangle winding
17
- - **Character System**: Ready-to-use character controller with animation states
18
- - **P2P Networking**: Peer-to-peer multiplayer support with signaling
19
-
20
- ## Quick Start
21
-
22
- ### Installation
23
-
24
- **Option 1: CDN (instant, no build step)**
25
- ```html
26
- <!DOCTYPE html>
27
- <html>
28
- <head>
29
- <meta charset="UTF-8" />
30
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
31
- <title>My Game</title>
32
- <style>
33
- html, body {
34
- margin: 0;
35
- padding: 0;
36
- background: #0a0a2a;
37
- width: 100%;
38
- height: 100%;
39
- overflow: hidden;
40
- }
41
- </style>
42
- </head>
43
- <body>
44
- <div id="appContainer">
45
- <div id="UIControlsContainer"></div>
46
- </div>
47
-
48
- <script src="https://unpkg.com/action-engine-js@latest/dist/action-engine.min.js"></script>
49
- <script src="game.js"></script>
50
- </body>
51
- </html>
52
- ```
53
-
54
- **Option 2: npm (for bundlers)**
55
- ```bash
56
- npm install action-engine-js
57
- ```
58
-
59
- ```html
60
- <!DOCTYPE html>
61
- <html>
62
- <head>
63
- <meta charset="UTF-8" />
64
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
65
- <title>My Game</title>
66
- <style>
67
- html, body {
68
- margin: 0;
69
- padding: 0;
70
- background: #0a0a2a;
71
- width: 100%;
72
- height: 100%;
73
- overflow: hidden;
74
- }
75
- </style>
76
- </head>
77
- <body>
78
- <div id="appContainer">
79
- <div id="UIControlsContainer"></div>
80
- </div>
81
-
82
- <script src="node_modules/action-engine-js/dist/action-engine.min.js"></script>
83
- <script src="game.js"></script>
84
- </body>
85
- </html>
86
- ```
87
-
88
- ### Create a Game Class
89
-
90
- ```javascript
91
- class Game {
92
- static get WIDTH() { return 800; }
93
- static get HEIGHT() { return 600; }
94
-
95
- constructor(canvases, input, audio) {
96
- this.gameCanvas = canvases.gameCanvas;
97
- this.guiCtx = canvases.guiCtx;
98
- this.debugCtx = canvases.debugCtx;
99
- this.input = input;
100
- this.audio = audio;
101
- }
102
-
103
- action_update(deltaTime) {
104
- // Update game logic
105
- }
106
-
107
- action_draw() {
108
- // Render your game
109
- }
110
- }
111
- ```
112
-
113
- ### Canvas Layers
114
-
115
- Action Engine provides three canvas layers:
116
-
117
- | Layer | Type | Purpose |
118
- |-------|------|---------|
119
- | **gameCanvas** | 2D or WebGL | Main game world (3D physics demo uses WebGL) |
120
- | **guiCanvas** | 2D | UI overlays (menus, HUD, buttons) |
121
- | **debugCanvas** | 2D | Debug visualization (toggle with F9) |
122
-
123
- All canvases use a fixed 800×600 coordinate system with automatic scaling.
124
-
125
- ## Core Systems
126
-
127
- ### Input System
128
-
129
- ```javascript
130
- // Keyboard
131
- this.input.isKeyPressed("DirUp") // Arrow keys
132
- this.input.isKeyPressed("Action1") // Space bar
133
- this.input.isKeyPressed("F9") // Toggle debug
134
-
135
- // Mouse
136
- this.input.getMouseX()
137
- this.input.getMouseY()
138
-
139
- // Element detection
140
- this.input.isElementHovered("debugButton", "debug")
141
- ```
142
-
143
- ### Audio System
144
-
145
- #### MIDI Instruments
146
-
147
- ```javascript
148
- this.audio.createMIDISound("kick", {
149
- instrument: "acoustic_bass_drum",
150
- note: 36,
151
- duration: 0.5,
152
- velocity: 100
153
- });
154
- ```
155
-
156
- #### FM Synthesis
157
-
158
- ```javascript
159
- this.audio.createFMSound("synthPad", {
160
- carrierFreq: 440,
161
- modulatorFreq: 220,
162
- modulationIndex: 50,
163
- duration: 1.0,
164
- envelope: { attack: 0.2, decay: 0.3, sustain: 0.6, release: 0.5 }
165
- });
166
- ```
167
-
168
- #### Noise & Effects
169
-
170
- ```javascript
171
- this.audio.createNoiseSound("wind", {
172
- noiseType: "pink",
173
- duration: 2.0,
174
- filterOptions: { frequency: 800, type: "lowpass" }
175
- });
176
- ```
177
-
178
- ### 3D Physics & Rendering
179
-
180
- #### Setting Up
181
-
182
- ```javascript
183
- this.renderer3D = new ActionRenderer3D(this.gameCanvas);
184
- this.physicsWorld = new ActionPhysicsWorld3D();
185
- this.camera = new ActionCamera();
186
- ```
187
-
188
- #### Creating Physics Objects
189
-
190
- ```javascript
191
- // Box
192
- const box = this.createBox(5, 5, 5, 1, new Vector3(0, 15, 0), "#FF6B6B");
193
-
194
- // Sphere
195
- const sphere = this.createSphere(3, 1, new Vector3(8, 20, 0));
196
-
197
- // Capsule (height must be > 2 × radius)
198
- const capsule = this.createCapsule(1.5, 8, 1, new Vector3(-8, 18, 0));
199
-
200
- // Cone
201
- const cone = this.createCone(2, 10, 1, new Vector3(0, 15, 0));
202
- ```
203
-
204
- **Colors**: Pass hex strings like `"#FF6B6B"` or `null` for defaults (box: green, sphere: white, capsule: red, cone: orange).
205
-
206
- ### Procedural Geometry with GeometryBuilder
207
-
208
- GeometryBuilder automatically handles triangle winding orientation, making complex 3D objects easy to create:
209
-
210
- ```javascript
211
- const builder = new GeometryBuilder();
212
- const vertices = [];
213
- const normals = [];
214
- const colors = [];
215
- const indices = [];
216
-
217
- // Set reference point at geometry center for automatic winding
218
- builder.setReferencePoint({ x: 0, y: 1, z: 0 });
219
-
220
- // Add vertices
221
- vertices.push(0, 0, 0, 1, 1, 1, -1, 1, 0); // x,y,z for each vertex
222
-
223
- // Create triangles
224
- builder.createTriangle(indices, vertices, 0, 1, 2);
225
- builder.createQuad(indices, vertices, 0, 1, 3, 2);
226
-
227
- // Convert to physics object
228
- const mesh = builder.createPhysicsObject(
229
- this.physicsWorld,
230
- vertices,
231
- normals,
232
- colors,
233
- indices,
234
- mass,
235
- position
236
- );
237
- ```
238
-
239
- **Key Point**: Set `setReferencePoint()` to the actual center of your geometry for correct automatic winding.
240
-
241
- ### Character System
242
-
243
- Spawn a playable character with built-in state management:
244
-
245
- ```javascript
246
- const player = this.spawnCharacter(new Vector3(0, 10, 0));
247
- ```
248
-
249
- Character has predefined states (idle, walking, jumping, falling) and handles input automatically. Access debug info:
250
-
251
- ```javascript
252
- console.log(player.debugInfo.state.current); // Current state
253
- console.log(player.debugInfo.physics.position); // Position vector
254
- console.log(player.debugInfo.physics.velocity); // Velocity vector
255
- ```
256
-
257
- ### Math Classes
258
-
259
- ```javascript
260
- // Vector2
261
- const v = Vector2.create(10, 20);
262
- const normalized = Vector2.normalize(v);
263
- const distance = Vector2.distance(v1, v2);
264
-
265
- // Vector3
266
- const pos = new Vector3(1, 2, 3);
267
- const dir = Vector3.normalize(pos);
268
-
269
- // Matrix4
270
- const transform = new Matrix4();
271
- transform.translate(x, y, z);
272
- transform.rotateX(angle);
273
- ```
274
-
275
- ## Directory Structure
276
-
277
- ```
278
- ActionEngineJS/
279
- ├── actionengine/ # Core engine code
280
- │ ├── 3rdparty/ # Third-party libraries
281
- │ ├── camera/ # Camera system
282
- │ ├── character/ # Character controller & animations
283
- │ ├── core/ # Main application loop
284
- │ ├── debug/ # Debug utilities
285
- │ ├── display/ # Rendering systems (2D/3D)
286
- │ ├── input/ # Input handler
287
- │ ├── math/ # Vector, Matrix utilities
288
- │ ├── network/ # Networking (client, server, P2P)
289
- │ └── sound/ # Audio engine
290
- ├── demos/ # Example games
291
- │ ├── audio/ # Audio synthesis demo (Breakout game)
292
- │ ├── input/ # Input handling demo (Asteroids game)
293
- │ └── p2p/ # P2P networking example
294
- ├── docs/ # Documentation
295
- ├── demo.js # Main demo game
296
- ├── game.js # Minimal game template
297
- ├── index.html # Entry point
298
- └── demo.html # Demo entry point
299
- ```
300
-
301
- ## Networking
302
-
303
- ### P2P (Peer-to-Peer)
304
-
305
- Connect games directly without a server:
306
-
307
- ```javascript
308
- const peer = new ActionNetPeer(peerId, trackerUrl);
309
- peer.connect(otherPeerId);
310
- peer.on("data", (data) => {
311
- console.log("Received:", data);
312
- });
313
- peer.send(data);
314
- ```
315
-
316
- ### Server-Based
317
-
318
- Host a central server for client connections:
319
-
320
- ```javascript
321
- const server = new ActionNetServer(port);
322
- server.on("client-connect", (client) => {
323
- client.send({ type: "welcome" });
324
- });
325
- ```
326
-
327
- ## Common Patterns
328
-
329
- ### Drawing to GUI Layer
330
-
331
- ```javascript
332
- action_draw() {
333
- // Draw game world
334
- this.renderer3D.render({
335
- renderableObjects: Array.from(this.physicsWorld.objects),
336
- camera: this.camera
337
- });
338
-
339
- // Draw UI on GUI layer
340
- this.guiCtx.fillStyle = "#fff";
341
- this.guiCtx.font = "20px Arial";
342
- this.guiCtx.fillText("Score: 100", 10, 30);
343
- }
344
- ```
345
-
346
- ### Debug Overlay with F9
347
-
348
- ```javascript
349
- if (this.showDebug) {
350
- this.drawDebugLayer();
351
- }
352
-
353
- // Toggle with F9 key (handled by input system)
354
- ```
355
-
356
- ### Handling Input
357
-
358
- ```javascript
359
- action_update(deltaTime) {
360
- if (this.input.isKeyPressed("DirUp")) {
361
- // Move up
362
- }
363
-
364
- if (this.input.isKeyJustPressed("Action1")) {
365
- this.player.jump();
366
- }
367
- }
368
- ```
369
-
370
- ### Playing Sounds
371
-
372
- ```javascript
373
- this.audio.playSound("kick", {
374
- volume: 0.8,
375
- repeat: false,
376
- onComplete: () => {
377
- console.log("Sound finished");
378
- }
379
- });
380
- ```
381
-
382
- ## Tips & Gotchas
383
-
384
- 1. **Fixed Canvas Size**: Always use `Game.WIDTH` and `Game.HEIGHT` (800×600) for positioning—scaling is automatic
385
- 2. **Capsule Height**: Ensure capsule `height > 2 × radius` or physics will error
386
- 3. **Reference Points in GeometryBuilder**: Set the reference point to your geometry's actual center for correct winding
387
- 4. **Color Handling**: Pass `null` to use shape defaults, or use hex strings like `"#FF6B6B"`
388
- 5. **Audio Envelopes**: Use subtle attack/release times (0.01s+) for smooth audio
389
- 6. **Debug Layer Performance**: Toggle debug mode sparingly in production; it adds overhead
390
-
391
- ## Files to Start With
392
-
393
- - **game.js** - Minimal template for your own game
394
- - **demo.js** - Full-featured demo showcasing all systems
395
- - **actionengine/core/app.js** - Main application loop
396
- - **actionengine/character/** - Character controller implementation
397
- - **actionengine/display/** - 3D rendering and geometry builders
398
-
399
- ## What's Included
400
-
401
- - ✅ Fully-featured game loop with fixed/regular updates
402
- - ✅ Multi-layer canvas rendering
403
- - ✅ Comprehensive input handling
404
- - ✅ Advanced audio with synthesis and effects
405
- - ✅ 3D physics and WebGL rendering
406
- - ✅ Procedural geometry builder
407
- - ✅ Character controller with states
408
- - ✅ P2P and server networking
409
- - ✅ Math utilities (vectors, matrices)
410
- - ✅ Debug visualization tools
411
-
412
- ## Development
413
-
414
- To build the minified bundle locally:
415
-
416
- ```bash
417
- npm install
418
- npm run build
419
- ```
420
-
421
- This generates `dist/action-engine.min.js` from all source files in dependency order.
422
-
423
- ---
424
-
425
- **Ready to build?** Start with the HTML template above, create your `game.js`, and you're good to go!
1
+ # Action Engine JS
2
+
3
+ A comprehensive JavaScript game framework that abstracts away the complexity of game development boilerplate, letting you focus on building your game.
4
+
5
+ ## Overview
6
+
7
+ Action Engine simplifies game creation by handling all the tedious infrastructure—input systems, audio, rendering, physics, and multi-layer canvas management—so you can focus on game logic.
8
+
9
+ ### Core Features
10
+
11
+ - **Multi-Layer Canvas System**: Separate game, UI, and debug rendering layers
12
+ - **Built-in Input System**: Keyboard, mouse, and touch input handling
13
+ - **Advanced Audio Engine**: MIDI instruments, FM synthesis, noise generation, reverb, echo, and more
14
+ - **3D Physics & Rendering**: WebGL-based 3D rendering with rigid body physics
15
+ - **Math Utilities**: Vector2, Vector3, and Matrix4 classes
16
+ - **Procedural Geometry**: GeometryBuilder for creating complex 3D objects with automatic triangle winding
17
+ - **Character System**: Ready-to-use character controller with animation states
18
+ - **P2P Networking**: Peer-to-peer multiplayer support with signaling
19
+
20
+ ## Quick Start
21
+
22
+ ### Installation
23
+
24
+ **Option 1: CDN (instant, no build step)**
25
+ ```html
26
+ <!DOCTYPE html>
27
+ <html>
28
+ <head>
29
+ <meta charset="UTF-8" />
30
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
31
+ <title>My Game</title>
32
+ <style>
33
+ html, body {
34
+ margin: 0;
35
+ padding: 0;
36
+ background: #0a0a2a;
37
+ width: 100%;
38
+ height: 100%;
39
+ overflow: hidden;
40
+ }
41
+ </style>
42
+ </head>
43
+ <body>
44
+ <div id="appContainer">
45
+ <div id="UIControlsContainer"></div>
46
+ </div>
47
+
48
+ <script src="https://unpkg.com/action-engine-js@latest/dist/action-engine.min.js"></script>
49
+ <script src="game.js"></script>
50
+ </body>
51
+ </html>
52
+ ```
53
+
54
+ **Option 2: npm (for bundlers)**
55
+ ```bash
56
+ npm install action-engine-js
57
+ ```
58
+
59
+ ```html
60
+ <!DOCTYPE html>
61
+ <html>
62
+ <head>
63
+ <meta charset="UTF-8" />
64
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
65
+ <title>My Game</title>
66
+ <style>
67
+ html, body {
68
+ margin: 0;
69
+ padding: 0;
70
+ background: #0a0a2a;
71
+ width: 100%;
72
+ height: 100%;
73
+ overflow: hidden;
74
+ }
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <div id="appContainer">
79
+ <div id="UIControlsContainer"></div>
80
+ </div>
81
+
82
+ <script src="node_modules/action-engine-js/dist/action-engine.min.js"></script>
83
+ <script src="game.js"></script>
84
+ </body>
85
+ </html>
86
+ ```
87
+
88
+ ### Create a Game Class
89
+
90
+ ```javascript
91
+ class Game {
92
+ static get WIDTH() { return 800; }
93
+ static get HEIGHT() { return 600; }
94
+
95
+ constructor(canvases, input, audio) {
96
+ this.gameCanvas = canvases.gameCanvas;
97
+ this.guiCtx = canvases.guiCtx;
98
+ this.debugCtx = canvases.debugCtx;
99
+ this.input = input;
100
+ this.audio = audio;
101
+ }
102
+
103
+ action_update(deltaTime) {
104
+ // Update game logic
105
+ }
106
+
107
+ action_draw() {
108
+ // Render your game
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### Canvas Layers
114
+
115
+ Action Engine provides three canvas layers:
116
+
117
+ | Layer | Type | Purpose |
118
+ |-------|------|---------|
119
+ | **gameCanvas** | 2D or WebGL | Main game world (3D physics demo uses WebGL) |
120
+ | **guiCanvas** | 2D | UI overlays (menus, HUD, buttons) |
121
+ | **debugCanvas** | 2D | Debug visualization (toggle with F9) |
122
+
123
+ All canvases use a fixed 800×600 coordinate system with automatic scaling.
124
+
125
+ ## Core Systems
126
+
127
+ ### Input System
128
+
129
+ ```javascript
130
+ // Keyboard
131
+ this.input.isKeyPressed("DirUp") // Arrow keys
132
+ this.input.isKeyPressed("Action1") // Space bar
133
+ this.input.isKeyPressed("F9") // Toggle debug
134
+
135
+ // Mouse
136
+ this.input.getMouseX()
137
+ this.input.getMouseY()
138
+
139
+ // Element detection
140
+ this.input.isElementHovered("debugButton", "debug")
141
+ ```
142
+
143
+ ### Audio System
144
+
145
+ #### MIDI Instruments
146
+
147
+ ```javascript
148
+ this.audio.createMIDISound("kick", {
149
+ instrument: "acoustic_bass_drum",
150
+ note: 36,
151
+ duration: 0.5,
152
+ velocity: 100
153
+ });
154
+ ```
155
+
156
+ #### FM Synthesis
157
+
158
+ ```javascript
159
+ this.audio.createFMSound("synthPad", {
160
+ carrierFreq: 440,
161
+ modulatorFreq: 220,
162
+ modulationIndex: 50,
163
+ duration: 1.0,
164
+ envelope: { attack: 0.2, decay: 0.3, sustain: 0.6, release: 0.5 }
165
+ });
166
+ ```
167
+
168
+ #### Noise & Effects
169
+
170
+ ```javascript
171
+ this.audio.createNoiseSound("wind", {
172
+ noiseType: "pink",
173
+ duration: 2.0,
174
+ filterOptions: { frequency: 800, type: "lowpass" }
175
+ });
176
+ ```
177
+
178
+ ### 3D Physics & Rendering
179
+
180
+ #### Setting Up
181
+
182
+ ```javascript
183
+ this.renderer3D = new ActionRenderer3D(this.gameCanvas);
184
+ this.physicsWorld = new ActionPhysicsWorld3D();
185
+ this.camera = new ActionCamera();
186
+ ```
187
+
188
+ #### Creating Physics Objects
189
+
190
+ ```javascript
191
+ // Box
192
+ const box = this.createBox(5, 5, 5, 1, new Vector3(0, 15, 0), "#FF6B6B");
193
+
194
+ // Sphere
195
+ const sphere = this.createSphere(3, 1, new Vector3(8, 20, 0));
196
+
197
+ // Capsule (height must be > 2 × radius)
198
+ const capsule = this.createCapsule(1.5, 8, 1, new Vector3(-8, 18, 0));
199
+
200
+ // Cone
201
+ const cone = this.createCone(2, 10, 1, new Vector3(0, 15, 0));
202
+ ```
203
+
204
+ **Colors**: Pass hex strings like `"#FF6B6B"` or `null` for defaults (box: green, sphere: white, capsule: red, cone: orange).
205
+
206
+ ### Procedural Geometry with GeometryBuilder
207
+
208
+ GeometryBuilder automatically handles triangle winding orientation, making complex 3D objects easy to create:
209
+
210
+ ```javascript
211
+ const builder = new GeometryBuilder();
212
+ const vertices = [];
213
+ const normals = [];
214
+ const colors = [];
215
+ const indices = [];
216
+
217
+ // Set reference point at geometry center for automatic winding
218
+ builder.setReferencePoint({ x: 0, y: 1, z: 0 });
219
+
220
+ // Add vertices
221
+ vertices.push(0, 0, 0, 1, 1, 1, -1, 1, 0); // x,y,z for each vertex
222
+
223
+ // Create triangles
224
+ builder.createTriangle(indices, vertices, 0, 1, 2);
225
+ builder.createQuad(indices, vertices, 0, 1, 3, 2);
226
+
227
+ // Convert to physics object
228
+ const mesh = builder.createPhysicsObject(
229
+ this.physicsWorld,
230
+ vertices,
231
+ normals,
232
+ colors,
233
+ indices,
234
+ mass,
235
+ position
236
+ );
237
+ ```
238
+
239
+ **Key Point**: Set `setReferencePoint()` to the actual center of your geometry for correct automatic winding.
240
+
241
+ ### Character System
242
+
243
+ Spawn a playable character with built-in state management:
244
+
245
+ ```javascript
246
+ const player = this.spawnCharacter(new Vector3(0, 10, 0));
247
+ ```
248
+
249
+ Character has predefined states (idle, walking, jumping, falling) and handles input automatically. Access debug info:
250
+
251
+ ```javascript
252
+ console.log(player.debugInfo.state.current); // Current state
253
+ console.log(player.debugInfo.physics.position); // Position vector
254
+ console.log(player.debugInfo.physics.velocity); // Velocity vector
255
+ ```
256
+
257
+ ### Math Classes
258
+
259
+ ```javascript
260
+ // Vector2
261
+ const v = Vector2.create(10, 20);
262
+ const normalized = Vector2.normalize(v);
263
+ const distance = Vector2.distance(v1, v2);
264
+
265
+ // Vector3
266
+ const pos = new Vector3(1, 2, 3);
267
+ const dir = Vector3.normalize(pos);
268
+
269
+ // Matrix4
270
+ const transform = new Matrix4();
271
+ transform.translate(x, y, z);
272
+ transform.rotateX(angle);
273
+ ```
274
+
275
+ ## Directory Structure
276
+
277
+ ```
278
+ ActionEngineJS/
279
+ ├── actionengine/ # Core engine code
280
+ │ ├── 3rdparty/ # Third-party libraries
281
+ │ ├── camera/ # Camera system
282
+ │ ├── character/ # Character controller & animations
283
+ │ ├── core/ # Main application loop
284
+ │ ├── debug/ # Debug utilities
285
+ │ ├── display/ # Rendering systems (2D/3D)
286
+ │ ├── input/ # Input handler
287
+ │ ├── math/ # Vector, Matrix utilities
288
+ │ ├── network/ # Networking (client, server, P2P)
289
+ │ └── sound/ # Audio engine
290
+ ├── demos/ # Example games
291
+ │ ├── audio/ # Audio synthesis demo (Breakout game)
292
+ │ ├── input/ # Input handling demo (Asteroids game)
293
+ │ └── p2p/ # P2P networking example
294
+ ├── docs/ # Documentation
295
+ ├── demo.js # Main demo game
296
+ ├── game.js # Minimal game template
297
+ ├── index.html # Entry point
298
+ └── demo.html # Demo entry point
299
+ ```
300
+
301
+ ## Networking
302
+
303
+ ### P2P (Peer-to-Peer)
304
+
305
+ Connect games directly without a server:
306
+
307
+ ```javascript
308
+ const peer = new ActionNetPeer(peerId, trackerUrl);
309
+ peer.connect(otherPeerId);
310
+ peer.on("data", (data) => {
311
+ console.log("Received:", data);
312
+ });
313
+ peer.send(data);
314
+ ```
315
+
316
+ ### Server-Based
317
+
318
+ Host a central server for client connections:
319
+
320
+ ```javascript
321
+ const server = new ActionNetServer(port);
322
+ server.on("client-connect", (client) => {
323
+ client.send({ type: "welcome" });
324
+ });
325
+ ```
326
+
327
+ ## Common Patterns
328
+
329
+ ### Drawing to GUI Layer
330
+
331
+ ```javascript
332
+ action_draw() {
333
+ // Draw game world
334
+ this.renderer3D.render({
335
+ renderableObjects: Array.from(this.physicsWorld.objects),
336
+ camera: this.camera
337
+ });
338
+
339
+ // Draw UI on GUI layer
340
+ this.guiCtx.fillStyle = "#fff";
341
+ this.guiCtx.font = "20px Arial";
342
+ this.guiCtx.fillText("Score: 100", 10, 30);
343
+ }
344
+ ```
345
+
346
+ ### Debug Overlay with F9
347
+
348
+ ```javascript
349
+ if (this.showDebug) {
350
+ this.drawDebugLayer();
351
+ }
352
+
353
+ // Toggle with F9 key (handled by input system)
354
+ ```
355
+
356
+ ### Handling Input
357
+
358
+ ```javascript
359
+ action_update(deltaTime) {
360
+ if (this.input.isKeyPressed("DirUp")) {
361
+ // Move up
362
+ }
363
+
364
+ if (this.input.isKeyJustPressed("Action1")) {
365
+ this.player.jump();
366
+ }
367
+ }
368
+ ```
369
+
370
+ ### Playing Sounds
371
+
372
+ ```javascript
373
+ this.audio.playSound("kick", {
374
+ volume: 0.8,
375
+ repeat: false,
376
+ onComplete: () => {
377
+ console.log("Sound finished");
378
+ }
379
+ });
380
+ ```
381
+
382
+ ## Tips & Gotchas
383
+
384
+ 1. **Fixed Canvas Size**: Always use `Game.WIDTH` and `Game.HEIGHT` (800×600) for positioning—scaling is automatic
385
+ 2. **Capsule Height**: Ensure capsule `height > 2 × radius` or physics will error
386
+ 3. **Reference Points in GeometryBuilder**: Set the reference point to your geometry's actual center for correct winding
387
+ 4. **Color Handling**: Pass `null` to use shape defaults, or use hex strings like `"#FF6B6B"`
388
+ 5. **Audio Envelopes**: Use subtle attack/release times (0.01s+) for smooth audio
389
+ 6. **Debug Layer Performance**: Toggle debug mode sparingly in production; it adds overhead
390
+
391
+ ## Files to Start With
392
+
393
+ - **game.js** - Minimal template for your own game
394
+ - **demo.js** - Full-featured demo showcasing all systems
395
+ - **actionengine/core/app.js** - Main application loop
396
+ - **actionengine/character/** - Character controller implementation
397
+ - **actionengine/display/** - 3D rendering and geometry builders
398
+
399
+ ## What's Included
400
+
401
+ - ✅ Fully-featured game loop with fixed/regular updates
402
+ - ✅ Multi-layer canvas rendering
403
+ - ✅ Comprehensive input handling
404
+ - ✅ Advanced audio with synthesis and effects
405
+ - ✅ 3D physics and WebGL rendering
406
+ - ✅ Procedural geometry builder
407
+ - ✅ Character controller with states
408
+ - ✅ P2P and server networking
409
+ - ✅ Math utilities (vectors, matrices)
410
+ - ✅ Debug visualization tools
411
+
412
+ ## Development
413
+
414
+ To build the minified bundle locally:
415
+
416
+ ```bash
417
+ npm install
418
+ npm run build
419
+ ```
420
+
421
+ This generates `dist/action-engine.min.js` from all source files in dependency order.
422
+
423
+ ---
424
+
425
+ **Ready to build?** Start with the HTML template above, create your `game.js`, and you're good to go!