nexus-2d 0.0.1 → 0.0.3

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.
@@ -0,0 +1,112 @@
1
+ export class CharacterController2D extends RigidBody2D {
2
+ speed: any;
3
+ acceleration: any;
4
+ airAcceleration: any;
5
+ airFriction: any;
6
+ jumpForce: any;
7
+ maxFallSpeed: any;
8
+ jumpCutMultiplier: any;
9
+ coyoteTime: any;
10
+ jumpBufferTime: any;
11
+ coyoteTimer: number;
12
+ jumpBufferTimer: number;
13
+ grounded: boolean;
14
+ wasGrounded: boolean;
15
+ jumping: boolean;
16
+ state: string;
17
+ moveInput: number;
18
+ jumpPressed: boolean;
19
+ jumpHeld: boolean;
20
+ jumpReleased: boolean;
21
+ groundContacts: Set<any>;
22
+ onJump: any;
23
+ onLand: any;
24
+ spriteNode: any;
25
+ animatedSprite: any;
26
+ collisionWidth: any;
27
+ collisionHeight: any;
28
+ collisionPaddingX: any;
29
+ collisionPaddingY: any;
30
+ debugDraw: any;
31
+ debugColor: any;
32
+ setupSprite(sprite: any): void;
33
+ setupCollision(): void;
34
+ setupAnimations(animatedSprite: any): void;
35
+ prevState: any;
36
+ updateAnimations(): void;
37
+ getAnimationForState(state: any): any;
38
+ handleCollisionEnter(other: any, contact: any): void;
39
+ handleCollisionStay(other: any, contact: any): void;
40
+ handleCollisionExit(other: any, contact: any): void;
41
+ updateTimers(delta: any): void;
42
+ handleMovement(delta: any): void;
43
+ handleJump(delta: any): void;
44
+ updateState(): void;
45
+ setMoveInput(direction: any): void;
46
+ setJumpInput(pressed: any, held: any, released: any): void;
47
+ }
48
+ export class CharacterInputController {
49
+ constructor(character: any, inputMap: any);
50
+ character: any;
51
+ inputMap: any;
52
+ prevJumpHeld: boolean;
53
+ update(): void;
54
+ }
55
+ /**
56
+ * TopDownController - 8-directional movement for dynamic bodies
57
+ *
58
+ * Uses high damping for tight, responsive controls
59
+ * Dynamic body type allows collision with static geometry
60
+ */
61
+ export class TopDownController extends RigidBody2D {
62
+ speed: any;
63
+ acceleration: any;
64
+ canDash: any;
65
+ dashSpeed: any;
66
+ dashDuration: any;
67
+ dashCooldown: any;
68
+ isDashing: boolean;
69
+ dashTimer: number;
70
+ dashCooldownTimer: number;
71
+ dashDirection: {
72
+ x: number;
73
+ y: number;
74
+ };
75
+ moveInput: {
76
+ x: number;
77
+ y: number;
78
+ };
79
+ dashInput: boolean;
80
+ state: string;
81
+ collisionWidth: any;
82
+ collisionHeight: any;
83
+ collisionPaddingX: any;
84
+ collisionPaddingY: any;
85
+ debugDraw: any;
86
+ debugColor: any;
87
+ onDashStart: any;
88
+ onDashEnd: any;
89
+ spriteNode: any;
90
+ animatedSprite: any;
91
+ setupSprite(sprite: any): void;
92
+ setupCollision(): void;
93
+ setupAnimations(animatedSprite: any): void;
94
+ prevState: any;
95
+ updateAnimations(): void;
96
+ getAnimationForState(state: any): any;
97
+ handleNormalMovement(delta: any): void;
98
+ handleDashMovement(delta: any): void;
99
+ startDash(): void;
100
+ endDash(): void;
101
+ updateState(): void;
102
+ setMoveInput(x: any, y: any): void;
103
+ setDashInput(pressed: any): void;
104
+ }
105
+ export class TopDownInputController {
106
+ constructor(character: any, inputMap: any);
107
+ character: any;
108
+ inputMap: any;
109
+ prevDashHeld: boolean;
110
+ update(): void;
111
+ }
112
+ import { RigidBody2D } from "./physicsv2.js";
@@ -0,0 +1,183 @@
1
+ /**
2
+ * AudioManager - high-level audio management
3
+ *
4
+ * Features:
5
+ * - Named audio assets (play by name, not handle)
6
+ * - Volume groups (SFX, music, master)
7
+ * - Fade in/out effects
8
+ * - Spatial audio (2D positional sound)
9
+ * - Audio groups (random variation)
10
+ * - Preloading
11
+ *
12
+ * Why this wrapper:
13
+ * - tessera.js is low-level (handles, no names)
14
+ * - Need organized asset management
15
+ * - Need fade effects for polish
16
+ * - Need volume groups for settings
17
+ */
18
+ export class AudioManagerClass {
19
+ audio: any;
20
+ sounds: Map<any, any>;
21
+ music: Map<any, any>;
22
+ masterVolume: number;
23
+ sfxVolume: number;
24
+ musicVolume: number;
25
+ activeSounds: Map<any, any>;
26
+ activeMusic: any;
27
+ groups: Map<any, any>;
28
+ listenerPosition: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ maxHearingDistance: number;
33
+ /**
34
+ * Initialize with tessera.js audio interface
35
+ *
36
+ * @param {Object} audioInterface - renderer.audio from tessera.js
37
+ */
38
+ init(audioInterface: any): void;
39
+ /**
40
+ * Load sound effect (fully loaded into memory)
41
+ *
42
+ * @param {string} name - Unique name for this sound
43
+ * @param {string} filePath - Path to audio file
44
+ * @returns {Promise<boolean>} - Success
45
+ */
46
+ loadSound(name: string, filePath: string): Promise<boolean>;
47
+ /**
48
+ * Load music (streamed from disk)
49
+ *
50
+ * @param {string} name - Unique name for this music
51
+ * @param {string} filePath - Path to audio file
52
+ * @returns {Promise<boolean>} - Success
53
+ */
54
+ loadMusic(name: string, filePath: string): Promise<boolean>;
55
+ /**
56
+ * Play sound effect
57
+ *
58
+ * @param {string} name - Sound name
59
+ * @param {Object} options - { volume, pitch, loop }
60
+ * @returns {boolean} - Success
61
+ */
62
+ playSound(name: string, options?: any): boolean;
63
+ /**
64
+ * Play music with fade options
65
+ *
66
+ * @param {string} name - Music name
67
+ * @param {Object} options - { fadeIn, loop, volume }
68
+ * @returns {boolean} - Success
69
+ */
70
+ playMusic(name: string, options?: any): boolean;
71
+ /**
72
+ * Stop music with fade out
73
+ *
74
+ * @param {string} name - Music name
75
+ * @param {Object} options - { fadeOut }
76
+ */
77
+ stopMusic(name: string, options?: any): void;
78
+ /**
79
+ * Pause music
80
+ */
81
+ pauseMusic(name: any): void;
82
+ /**
83
+ * Resume music
84
+ */
85
+ resumeMusic(name: any): void;
86
+ /**
87
+ * Play sound with 2D spatial positioning
88
+ *
89
+ * Volume falls off with distance from listener
90
+ *
91
+ * @param {string} name - Sound name
92
+ * @param {number} x - Sound world X
93
+ * @param {number} y - Sound world Y
94
+ * @param {number} listenerX - Listener world X (camera/player)
95
+ * @param {number} listenerY - Listener world Y
96
+ */
97
+ playSoundAt(name: string, x: number, y: number, listenerX: number, listenerY: number): void;
98
+ /**
99
+ * Set master volume (affects all audio)
100
+ */
101
+ setMasterVolume(volume: any): void;
102
+ /**
103
+ * Set SFX volume group
104
+ */
105
+ setSFXVolume(volume: any): void;
106
+ /**
107
+ * Set music volume group
108
+ */
109
+ setMusicVolume(volume: any): void;
110
+ /**
111
+ * Update volumes for all active audio
112
+ */
113
+ updateAllVolumes(): void;
114
+ /**
115
+ * Create audio group for random variation
116
+ *
117
+ * Example: footsteps group contains step1, step2, step3
118
+ *
119
+ * @param {string} groupName - Group name
120
+ * @param {Array<string>} soundNames - Sound names in group
121
+ */
122
+ createGroup(groupName: string, soundNames: Array<string>): void;
123
+ /**
124
+ * Play random sound from group
125
+ */
126
+ playRandomFromGroup(groupName: any, options?: {}): boolean;
127
+ /**
128
+ * Update fade effects (call every frame)
129
+ *
130
+ * @param {number} delta - Time delta in seconds
131
+ */
132
+ update(delta: number): void;
133
+ /**
134
+ * Check if sound is playing
135
+ */
136
+ isSoundPlaying(name: any): any;
137
+ /**
138
+ * Check if music is playing
139
+ */
140
+ isMusicPlaying(name: any): any;
141
+ /**
142
+ * Unload sound
143
+ */
144
+ unloadSound(name: any): void;
145
+ /**
146
+ * Unload music
147
+ */
148
+ unloadMusic(name: any): void;
149
+ /**
150
+ * Unload all audio
151
+ */
152
+ unloadAll(): void;
153
+ /**
154
+ * Get audio statistics
155
+ */
156
+ getStats(): {
157
+ soundsLoaded: number;
158
+ musicLoaded: number;
159
+ activeSounds: number;
160
+ musicPlaying: boolean;
161
+ masterVolume: number;
162
+ sfxVolume: number;
163
+ musicVolume: number;
164
+ };
165
+ }
166
+ export const AudioManager: AudioManagerClass;
167
+ /**
168
+ * AudioPresets - common audio patterns
169
+ */
170
+ export class AudioPresets {
171
+ /**
172
+ * UI sound pack
173
+ */
174
+ static loadUIAudio(): Promise<void>;
175
+ /**
176
+ * Player action sounds
177
+ */
178
+ static loadPlayerAudio(): Promise<void>;
179
+ /**
180
+ * Background music
181
+ */
182
+ static loadMusicTracks(): Promise<void>;
183
+ }
@@ -0,0 +1,94 @@
1
+ export function vec2(x?: number, y?: number): {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export class Camera2D extends Node {
6
+ zoom: number;
7
+ /**
8
+ * @type {Viewport}
9
+ */
10
+ viewport: Viewport;
11
+ near: number;
12
+ far: number;
13
+ worldZoom: number;
14
+ projectionDirty: boolean;
15
+ frustum: {
16
+ left: number;
17
+ right: number;
18
+ top: number;
19
+ bottom: number;
20
+ near: number;
21
+ far: number;
22
+ };
23
+ bounds: {
24
+ left: number;
25
+ right: number;
26
+ top: number;
27
+ bottom: number;
28
+ };
29
+ viewWidth: number;
30
+ viewHeight: number;
31
+ cullingEnabled: boolean;
32
+ _viewMatrix: any;
33
+ _projectionMatrix: any;
34
+ _viewProjectionMatrix: any;
35
+ setBounds(bounds: any): void;
36
+ /**
37
+ * viewport
38
+ * @param {*} width
39
+ * @param {*} height
40
+ */
41
+ setViewSize(width: any, height: any): void;
42
+ /**
43
+ * visible space in world
44
+ */
45
+ _updateFrustum(): void;
46
+ worldToScreen(worldX: any, worldY: any, applyViewport?: boolean): {
47
+ x: any;
48
+ y: any;
49
+ };
50
+ screenToWorld(screenX: any, screenY: any): {
51
+ x: number;
52
+ y: number;
53
+ };
54
+ getVisibility(x: any, y: any, width?: number, height?: number): 0 | 1 | 2;
55
+ isVisible(x: any, y: any, margin?: number): boolean;
56
+ /**
57
+ * Check if an axis-aligned bounding box (AABB) is visible in the camera view
58
+ * @param {number} worldX - Center X of the AABB in world space
59
+ * @param {number} worldY - Center Y of the AABB in world space
60
+ * @param {number} width - Width of the AABB
61
+ * @param {number} height - Height of the AABB
62
+ * @returns {boolean} True if the AABB is at least partially visible
63
+ */
64
+ isAABBVisible(worldX: number, worldY: number, width: number, height: number): boolean;
65
+ getVisibleBounds(): {
66
+ left: number;
67
+ right: number;
68
+ top: number;
69
+ bottom: number;
70
+ width: number;
71
+ height: number;
72
+ };
73
+ moveLocal(dx: any, dy: any): void;
74
+ moveWorld(dx: any, dy: any): void;
75
+ setPosition(x: any, y: any): void;
76
+ /**
77
+ * Zoom with optional pivot point (world space)
78
+ * Pivot allows zooming toward a specific point (like mouse position)
79
+ */
80
+ zoomTo(factor: any, pivotX?: any, pivotY?: any): void;
81
+ applyShake(intensity: any, decay?: number): number;
82
+ }
83
+ export class Viewport {
84
+ constructor(x: any, y: any, width: any, height: any);
85
+ x: any;
86
+ y: any;
87
+ width: any;
88
+ height: any;
89
+ scissorEnabled: boolean;
90
+ contains(screenX: any, screenY: any): boolean;
91
+ setScissor(enabled: any): void;
92
+ shouldClip(canvasX: any, canvasY: any, margin?: number): boolean;
93
+ }
94
+ import { Node } from "./core.js";
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Camera2D - transforms world space to screen space
3
+ *
4
+ * Why extend Node:
5
+ * - Inherits transform system (position, rotation)
6
+ * - Can be child of other nodes (camera attached to vehicle)
7
+ * - Participates in scene graph updates
8
+ *
9
+ * Common use cases:
10
+ * - Follow player smoothly
11
+ * - Screen shake effects
12
+ * - Zoom in/out
13
+ * - Split-screen (multiple cameras, multiple viewports)
14
+ */
15
+ export class Camera2D extends Node {
16
+ zoom: number;
17
+ viewport: any;
18
+ target: any;
19
+ followSmoothing: number;
20
+ deadzone: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ limits: {
25
+ minX: any;
26
+ minY: any;
27
+ maxX: any;
28
+ maxY: any;
29
+ };
30
+ limitSmoothing: number;
31
+ shakeAmount: number;
32
+ shakeDuration: number;
33
+ shakeDecay: number;
34
+ shakeOffset: {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ screenWidth: number;
39
+ screenHeight: number;
40
+ setTarget(target: any, options?: {}): void;
41
+ setLimits(minX: any, minY: any, maxX: any, maxY: any): void;
42
+ shake(amount: any, duration?: number): void;
43
+ worldToScreen(worldX: any, worldY: any): {
44
+ x: number;
45
+ y: number;
46
+ };
47
+ screenToWorld(screenX: any, screenY: any): {
48
+ x: any;
49
+ y: any;
50
+ };
51
+ isVisible(worldX: any, worldY: any, margin?: number): boolean;
52
+ isAABBVisible(worldX: any, worldY: any, width: any, height: any): boolean;
53
+ getVisibleBounds(): {
54
+ minX: any;
55
+ minY: any;
56
+ maxX: any;
57
+ maxY: any;
58
+ width: number;
59
+ height: number;
60
+ };
61
+ }
62
+ /**
63
+ * Viewport - defines a rectangular region of the screen
64
+ *
65
+ * why viewports exist:
66
+ * - Split-screen multiplayer (2-4 cameras, each with own viewport)
67
+ * - Picture-in-picture (minimap)
68
+ * - UI overlays (render game to viewport, UI to full screen)
69
+ *
70
+ * common use case: 2-player split-screen
71
+ * Player 1 viewport: (0, 0, 400, 600)
72
+ * Player 2 viewport: (400, 0, 400, 600)
73
+ */
74
+ export class Viewport {
75
+ /**
76
+ * create viewport from canvas (full screen)
77
+ */
78
+ static fromCanvas(canvas: any): Viewport;
79
+ constructor(x: any, y: any, width: any, height: any);
80
+ x: any;
81
+ y: any;
82
+ width: any;
83
+ height: any;
84
+ /**
85
+ * Check if screen point is inside viewport
86
+ */
87
+ contains(screenX: any, screenY: any): boolean;
88
+ /**
89
+ * get aspect ratio (useful for maintaining proportions)
90
+ */
91
+ getAspectRatio(): number;
92
+ }
93
+ /**
94
+ * CameraController - common camera behaviors
95
+ *
96
+ * - Camera2D is low-level (transform math)
97
+ * - CameraController is high-level (gameplay behaviors)
98
+ * - Swap controllers for different game types
99
+ */
100
+ export class CameraController extends Node {
101
+ constructor(name: any, camera: any);
102
+ camera: any;
103
+ }
104
+ /**
105
+ * FollowCameraController - smooth following with lookahead
106
+ *
107
+ * Features:
108
+ * - Smooth following
109
+ * - Lookahead (camera shows more space ahead of player)
110
+ * - Speed-based zoom out (see more when moving fast)
111
+ */
112
+ export class FollowCameraController extends CameraController {
113
+ constructor(camera: any, target: any, options?: {});
114
+ target: any;
115
+ smoothing: any;
116
+ lookahead: any;
117
+ lookaheadSmoothing: any;
118
+ currentLookahead: {
119
+ x: number;
120
+ y: number;
121
+ };
122
+ zoomSpeed: any;
123
+ minZoom: any;
124
+ maxZoom: any;
125
+ }
126
+ /**
127
+ * PlatformerCameraController - platformer-specific camera
128
+ *
129
+ * Features:
130
+ * - Vertical lookahead (look down when falling, up when jumping)
131
+ * - Horizontal smoothing (don't jitter left/right)
132
+ * - Jump anticipation (camera rises slightly before player jumps)
133
+ */
134
+ export class PlatformerCameraController extends CameraController {
135
+ constructor(camera: any, target: any, options?: {});
136
+ target: any;
137
+ horizontalSmoothing: any;
138
+ verticalSmoothing: any;
139
+ verticalLookahead: any;
140
+ currentVerticalOffset: number;
141
+ }
142
+ import { Node } from './core.js';