@caperjs/plugin-crunch 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +205 -0
- package/lib/Actor.d.ts +227 -0
- package/lib/Actor.d.ts.map +1 -0
- package/lib/CrunchPhysicsPlugin.d.ts +508 -0
- package/lib/CrunchPhysicsPlugin.d.ts.map +1 -0
- package/lib/Entity.d.ts +377 -0
- package/lib/Entity.d.ts.map +1 -0
- package/lib/Group.d.ts +122 -0
- package/lib/Group.d.ts.map +1 -0
- package/lib/Sensor.d.ts +161 -0
- package/lib/Sensor.d.ts.map +1 -0
- package/lib/Solid.d.ts +109 -0
- package/lib/Solid.d.ts.map +1 -0
- package/lib/System.d.ts +265 -0
- package/lib/System.d.ts.map +1 -0
- package/lib/caper-plugin-crunch.mjs +1331 -0
- package/lib/caper-plugin-crunch.mjs.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/interfaces.d.ts +32 -0
- package/lib/interfaces.d.ts.map +1 -0
- package/lib/types.d.ts +246 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils.d.ts +63 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/package.json +42 -0
- package/src/Actor.ts +726 -0
- package/src/CrunchPhysicsPlugin.ts +718 -0
- package/src/Entity.ts +762 -0
- package/src/Group.ts +181 -0
- package/src/Sensor.ts +427 -0
- package/src/Solid.ts +380 -0
- package/src/System.ts +1546 -0
- package/src/collision-layers.d.ts +87 -0
- package/src/index.ts +18 -0
- package/src/interfaces.ts +33 -0
- package/src/types.ts +336 -0
- package/src/utils.ts +72 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { IApplication, IPlugin, Plugin } from '@caperjs/core';
|
|
2
|
+
import { Container as PIXIContainer } from 'pixi.js';
|
|
3
|
+
import { Actor } from './Actor';
|
|
4
|
+
import { Group } from './Group';
|
|
5
|
+
import { AABBLike, CrunchPhysicsOptions } from './interfaces';
|
|
6
|
+
import { Sensor } from './Sensor';
|
|
7
|
+
import { Solid } from './Solid';
|
|
8
|
+
import { System } from './System';
|
|
9
|
+
import { ActorCollision, Collision, PhysicsEntityConfig, RegisteredCollisionLayer } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Interface for the Crunch physics plugin, providing a simple yet powerful 2D physics system
|
|
12
|
+
* inspired by Towerfall's physics mechanics. Supports dynamic actors, static solids, and trigger sensors.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Initialize the physics system
|
|
17
|
+
* const physics = this.app.getPlugin('crunch') as ICrunchPhysicsPlugin;
|
|
18
|
+
*
|
|
19
|
+
* const physics = await this.physics.initialize({
|
|
20
|
+
* gravity: 900,
|
|
21
|
+
* debug: true,
|
|
22
|
+
* gridSize: 32
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Create a player character
|
|
26
|
+
* const playerSprite = this.add.sprite({asset:Texture.WHITE, width: 32, height: 64});
|
|
27
|
+
*
|
|
28
|
+
* const player = physics.createActor({
|
|
29
|
+
* type: 'Player',
|
|
30
|
+
* position: [100, 100],
|
|
31
|
+
* size: [32, 64],
|
|
32
|
+
* view: playerSprite
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Create a platform
|
|
36
|
+
* const platformSprite = this.add.sprite({asset:Texture.WHITE, width: 800, height: 32, tint: 0x00FF00});
|
|
37
|
+
* const platform = physics.createSolid({
|
|
38
|
+
* type: 'Platform',
|
|
39
|
+
* position: [0, 500],
|
|
40
|
+
* size: [800, 32],
|
|
41
|
+
* view: platformSprite
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Create a coin pickup sensor
|
|
45
|
+
* const coinSprite = this.add.sprite({asset:Texture.WHITE, width: 32, height: 32, tint: 0x00FF00});
|
|
46
|
+
* const coin = physics.createSensor({
|
|
47
|
+
* type: 'Coin',
|
|
48
|
+
* position: [400, 400],
|
|
49
|
+
* size: [32, 32],
|
|
50
|
+
* view: coinSprite
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface ICrunchPhysicsPlugin extends IPlugin<CrunchPhysicsOptions> {
|
|
55
|
+
system: System;
|
|
56
|
+
container: PIXIContainer;
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Initializes the physics system with the specified options.
|
|
60
|
+
*/
|
|
61
|
+
initialize(options?: Partial<CrunchPhysicsOptions>, app?: IApplication): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Sets a custom collision resolver function that will be called when collisions occur.
|
|
64
|
+
*
|
|
65
|
+
* @param resolver - Function to handle collisions
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* physics.setCollisionResolver((collisions) => {
|
|
70
|
+
* collisions.forEach(collision => {
|
|
71
|
+
* if (collision.actor.type === 'Player' && collision.solid.type === 'Spike') {
|
|
72
|
+
* player.damage(10);
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
setCollisionResolver(resolver: (collisions: Collision[]) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Sets a custom resolver for actor-to-actor collisions.
|
|
81
|
+
*
|
|
82
|
+
* @param resolver - Function to handle actor-to-actor collisions
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* physics.setActorCollisionResolver((collisions) => {
|
|
87
|
+
* collisions.forEach(collision => {
|
|
88
|
+
* if (collision.actor1.type === 'Player' && collision.actor2.type === 'Enemy') {
|
|
89
|
+
* player.takeDamage(10);
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
setActorCollisionResolver(resolver: (collisions: ActorCollision[]) => void): void;
|
|
96
|
+
/**
|
|
97
|
+
* Enables or disables actor-to-actor collision detection.
|
|
98
|
+
*
|
|
99
|
+
* @param enabled - Whether to enable actor-to-actor collisions
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Enable actor-to-actor collisions
|
|
104
|
+
* physics.setActorCollisionsEnabled(true);
|
|
105
|
+
*
|
|
106
|
+
* // Disable actor-to-actor collisions for performance
|
|
107
|
+
* physics.setActorCollisionsEnabled(false);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
setActorCollisionsEnabled(enabled: boolean): void;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a generic physics entity based on the provided configuration.
|
|
113
|
+
* Use this when you need to create an entity without knowing its specific type at compile time.
|
|
114
|
+
*
|
|
115
|
+
* @param config - Configuration for the physics entity
|
|
116
|
+
* @returns The created physics entity
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const entityConfig = {
|
|
121
|
+
* type: 'Platform',
|
|
122
|
+
* position: [100, 100],
|
|
123
|
+
* size: [200, 32],
|
|
124
|
+
* view: sprite
|
|
125
|
+
* };
|
|
126
|
+
* const entity = physics.createEntity(entityConfig);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
createEntity(config: PhysicsEntityConfig): Actor | Solid | Sensor | Group;
|
|
130
|
+
/**
|
|
131
|
+
* Adds an existing physics entity to the system.
|
|
132
|
+
* Useful when you want to manage entity creation yourself.
|
|
133
|
+
*
|
|
134
|
+
* @param entity - The physics entity to add
|
|
135
|
+
* @returns The added entity
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* class CustomActor extends Actor {
|
|
140
|
+
* constructor() {
|
|
141
|
+
* super({ type: 'Custom', position: [0, 0], size: [32, 32] });
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* const customActor = new CustomActor();
|
|
146
|
+
* physics.addEntity(customActor);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
addEntity(entity: Actor | Solid | Sensor | Group): Actor | Solid | Sensor | Group;
|
|
150
|
+
/**
|
|
151
|
+
* Creates a dynamic physics actor that can move and collide with other entities.
|
|
152
|
+
* Actors are typically used for players, enemies, or any moving game objects.
|
|
153
|
+
*
|
|
154
|
+
* @param config - Configuration for the actor
|
|
155
|
+
* @returns The created actor
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* // Create a player character
|
|
160
|
+
* const player = physics.createActor({
|
|
161
|
+
* type: 'Player',
|
|
162
|
+
* position: [100, 100],
|
|
163
|
+
* size: [32, 64],
|
|
164
|
+
* view: playerSprite
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* // Update player in game loop
|
|
168
|
+
* player.velocity.x = 300; // Move right
|
|
169
|
+
* player.velocity.y = -600; // Jump
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
createActor(config: PhysicsEntityConfig): Actor;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a static solid object that other entities can collide with.
|
|
175
|
+
* Solids are typically used for platforms, walls, and other immovable objects.
|
|
176
|
+
*
|
|
177
|
+
* @param config - Configuration for the solid
|
|
178
|
+
* @returns The created solid
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // Create a static platform
|
|
183
|
+
* const platform = physics.createSolid({
|
|
184
|
+
* type: 'Platform',
|
|
185
|
+
* position: [0, 500],
|
|
186
|
+
* size: [800, 32],
|
|
187
|
+
* view: platformSprite
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* // Create a moving platform
|
|
191
|
+
* const movingPlatform = physics.createSolid({
|
|
192
|
+
* type: 'Platform',
|
|
193
|
+
* position: [100, 300],
|
|
194
|
+
* size: [200, 32],
|
|
195
|
+
* view: platformSprite
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* // Update platform position
|
|
199
|
+
* gsap.to(movingPlatform, {
|
|
200
|
+
* x: 500,
|
|
201
|
+
* duration: 2,
|
|
202
|
+
* yoyo: true,
|
|
203
|
+
* repeat: -1
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
createSolid(config: PhysicsEntityConfig): Solid;
|
|
208
|
+
/**
|
|
209
|
+
* Creates a sensor zone that can detect overlaps with other entities.
|
|
210
|
+
* Sensors are typically used for triggers, collectibles, or detection zones.
|
|
211
|
+
*
|
|
212
|
+
* @param config - Configuration for the sensor
|
|
213
|
+
* @returns The created sensor
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* // Create a coin pickup
|
|
218
|
+
* const coin = physics.createSensor({
|
|
219
|
+
* type: 'Coin',
|
|
220
|
+
* position: [400, 300],
|
|
221
|
+
* size: [32, 32],
|
|
222
|
+
* view: coinSprite
|
|
223
|
+
* });
|
|
224
|
+
*
|
|
225
|
+
* // Handle coin collection
|
|
226
|
+
* coin.onActorEnter = (actor) => {
|
|
227
|
+
* if (actor.type === 'Player') {
|
|
228
|
+
* increaseScore(10);
|
|
229
|
+
* physics.removeSensor(coin);
|
|
230
|
+
* }
|
|
231
|
+
* };
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
createSensor(config: PhysicsEntityConfig): Sensor;
|
|
235
|
+
createGroup(config: PhysicsEntityConfig): Group;
|
|
236
|
+
addActor(actor: Actor): Actor;
|
|
237
|
+
addSolid(solid: Solid): Solid;
|
|
238
|
+
addSensor(sensor: Sensor): Sensor;
|
|
239
|
+
addGroup(group: Group): Group;
|
|
240
|
+
/**
|
|
241
|
+
* Removes an actor from the physics system.
|
|
242
|
+
*
|
|
243
|
+
* @param actor - The actor to remove
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Remove player when they die
|
|
248
|
+
* function killPlayer(player: Actor) {
|
|
249
|
+
* playDeathAnimation();
|
|
250
|
+
* physics.removeActor(player);
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
removeActor(actor: Actor): void;
|
|
255
|
+
/**
|
|
256
|
+
* Removes a solid from the physics system.
|
|
257
|
+
*
|
|
258
|
+
* @param solid - The solid to remove
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // Remove a platform when it's destroyed
|
|
263
|
+
* function destroyPlatform(platform: Solid) {
|
|
264
|
+
* playBreakAnimation();
|
|
265
|
+
* physics.removeSolid(platform);
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
removeSolid(solid: Solid): void;
|
|
270
|
+
/**
|
|
271
|
+
* Removes a sensor from the physics system.
|
|
272
|
+
*
|
|
273
|
+
* @param sensor - The sensor to remove
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* // Remove a coin when it's collected
|
|
278
|
+
* function collectCoin(coin: Sensor) {
|
|
279
|
+
* playCollectSound();
|
|
280
|
+
* physics.removeSensor(coin);
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
removeSensor(sensor: Sensor): void;
|
|
285
|
+
/**
|
|
286
|
+
* Cleans up the physics system and removes all entities.
|
|
287
|
+
* Call this when transitioning between scenes or shutting down the game.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* class GameScene extends Scene {
|
|
292
|
+
* destroy() {
|
|
293
|
+
* this.physics.destroy();
|
|
294
|
+
* super.destroy();
|
|
295
|
+
* }
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
destroy(): void;
|
|
300
|
+
/**
|
|
301
|
+
* Creates a custom collision layer.
|
|
302
|
+
*
|
|
303
|
+
* @param index Index from 0-15 representing which user bit to use (gets shifted to bits 16-31)
|
|
304
|
+
* @returns A unique collision layer value
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* // Create custom collision layers
|
|
309
|
+
* const WATER_LAYER = physics.createCollisionLayer(0);
|
|
310
|
+
* const LAVA_LAYER = physics.createCollisionLayer(1);
|
|
311
|
+
*
|
|
312
|
+
* // Use in entity creation
|
|
313
|
+
* const waterEntity = physics.createActor({
|
|
314
|
+
* type: 'Water',
|
|
315
|
+
* position: [100, 400],
|
|
316
|
+
* size: [800, 100],
|
|
317
|
+
* collisionLayer: WATER_LAYER,
|
|
318
|
+
* collisionMask: CollisionLayer.PLAYER | CollisionLayer.ENEMY
|
|
319
|
+
* });
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
createCollisionLayer(index: number): number;
|
|
323
|
+
/**
|
|
324
|
+
* Creates a collision mask from multiple layers.
|
|
325
|
+
*
|
|
326
|
+
* @param layers Array of collision layers to combine
|
|
327
|
+
* @returns A combined collision mask
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* // Create a mask that collides with players, enemies and projectiles
|
|
332
|
+
* const mask = physics.createCollisionMask([
|
|
333
|
+
* CollisionLayer.PLAYER,
|
|
334
|
+
* CollisionLayer.ENEMY,
|
|
335
|
+
* CollisionLayer.PROJECTILE
|
|
336
|
+
* ]);
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
createCollisionMask(...layers: number[]): number;
|
|
340
|
+
/**
|
|
341
|
+
* Registers a named collision layer for better intellisense support.
|
|
342
|
+
*
|
|
343
|
+
* @param name Name of the collision layer (used for intellisense)
|
|
344
|
+
* @param indexOrDescription Index or description of the layer
|
|
345
|
+
* @param description Optional description of the layer
|
|
346
|
+
* @returns The numeric value of the registered collision layer
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* // Register named collision layers
|
|
351
|
+
* const WATER = physics.registerCollisionLayer('WATER', 0, 'Water surfaces');
|
|
352
|
+
* const LAVA = physics.registerCollisionLayer('LAVA', 1, 'Lava surfaces that damage players');
|
|
353
|
+
*
|
|
354
|
+
* // Use in entity creation
|
|
355
|
+
* const waterEntity = physics.createActor({
|
|
356
|
+
* type: 'Water',
|
|
357
|
+
* position: [100, 400],
|
|
358
|
+
* size: [800, 100],
|
|
359
|
+
* collisionLayer: WATER,
|
|
360
|
+
* collisionMask: CollisionLayer.PLAYER | CollisionLayer.ENEMY
|
|
361
|
+
* });
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
registerCollisionLayer(name: string, indexOrDescription?: number | string, description?: string): number;
|
|
365
|
+
/**
|
|
366
|
+
* Gets a registered collision layer by name.
|
|
367
|
+
*
|
|
368
|
+
* @param name Name of the collision layer
|
|
369
|
+
* @returns The numeric value of the registered collision layer or undefined if not found
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* // Get a registered collision layer
|
|
374
|
+
* const waterLayer = physics.getCollisionLayer('WATER');
|
|
375
|
+
* if (waterLayer !== undefined) {
|
|
376
|
+
* // Use the layer
|
|
377
|
+
* entity.setCollisionLayer(waterLayer);
|
|
378
|
+
* }
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
getCollisionLayer(name: string): number | undefined;
|
|
382
|
+
/**
|
|
383
|
+
* Gets all registered collision layers.
|
|
384
|
+
*
|
|
385
|
+
* @returns Array of all registered collision layers
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* // Get all registered collision layers
|
|
390
|
+
* const layers = physics.getCollisionLayers();
|
|
391
|
+
* console.log(`Registered layers: ${layers.map(l => l.name).join(', ')}`);
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
getCollisionLayers(): RegisteredCollisionLayer[];
|
|
395
|
+
/**
|
|
396
|
+
* Removes a registered collision layer.
|
|
397
|
+
*
|
|
398
|
+
* @param name Name of the collision layer to remove
|
|
399
|
+
* @returns True if the layer was removed, false if it didn't exist
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* // Remove a registered collision layer
|
|
404
|
+
* physics.removeCollisionLayer('WATER');
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
removeCollisionLayer(name: string): boolean;
|
|
408
|
+
/**
|
|
409
|
+
* Clears all registered collision layers.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* // Clear all registered collision layers
|
|
414
|
+
* physics.clearCollisionLayers();
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
clearCollisionLayers(): void;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Implementation of the Crunch physics plugin.
|
|
421
|
+
* See {@link ICrunchPhysicsPlugin} for detailed API documentation and examples.
|
|
422
|
+
*/
|
|
423
|
+
export default class CrunchPhysicsPlugin extends Plugin<CrunchPhysicsOptions> implements ICrunchPhysicsPlugin {
|
|
424
|
+
system: System;
|
|
425
|
+
container: PIXIContainer;
|
|
426
|
+
enabled: boolean;
|
|
427
|
+
private collisionResolver?;
|
|
428
|
+
private overlapResolver?;
|
|
429
|
+
private actorCollisionResolver?;
|
|
430
|
+
constructor();
|
|
431
|
+
private hello;
|
|
432
|
+
initialize(options?: Partial<CrunchPhysicsOptions>, _app: IApplication): Promise<void>;
|
|
433
|
+
setCollisionResolver(resolver: (collisions: Collision[]) => void): void;
|
|
434
|
+
setActorCollisionResolver(resolver: (collisions: ActorCollision[]) => void): void;
|
|
435
|
+
setActorCollisionsEnabled(enabled: boolean): void;
|
|
436
|
+
createEntity(config: PhysicsEntityConfig): Actor | Solid | Sensor | Group;
|
|
437
|
+
addEntity(entity: Actor | Solid | Sensor | Group): Actor | Solid | Sensor | Group;
|
|
438
|
+
createActor(config: PhysicsEntityConfig): Actor;
|
|
439
|
+
createSolid(config: PhysicsEntityConfig): Solid;
|
|
440
|
+
createSensor(config: PhysicsEntityConfig): Sensor;
|
|
441
|
+
createGroup(config: PhysicsEntityConfig): Group;
|
|
442
|
+
addActor(actor: Actor): Actor;
|
|
443
|
+
addSolid(solid: Solid): Solid;
|
|
444
|
+
addSensor(sensor: Sensor): Sensor;
|
|
445
|
+
addGroup(group: Group): Group;
|
|
446
|
+
removeActor(actor: Actor): void;
|
|
447
|
+
removeSolid(solid: Solid): void;
|
|
448
|
+
removeSensor(sensor: Sensor): void;
|
|
449
|
+
removeGroup(group: Group): void;
|
|
450
|
+
destroy(): void;
|
|
451
|
+
private update;
|
|
452
|
+
/**
|
|
453
|
+
* Creates a custom collision layer.
|
|
454
|
+
*
|
|
455
|
+
* @param index Index from 0-15 representing which user bit to use (gets shifted to bits 16-31)
|
|
456
|
+
* @returns A unique collision layer value
|
|
457
|
+
*/
|
|
458
|
+
createCollisionLayer(index: number): number;
|
|
459
|
+
/**
|
|
460
|
+
* Creates a collision mask from multiple layers.
|
|
461
|
+
*
|
|
462
|
+
* @param layers Array of collision layers to combine
|
|
463
|
+
* @returns A combined collision mask
|
|
464
|
+
*/
|
|
465
|
+
createCollisionMask(...layers: number[]): number;
|
|
466
|
+
/**
|
|
467
|
+
* Registers a named collision layer for better intellisense support.
|
|
468
|
+
*
|
|
469
|
+
* @param name Name of the collision layer (used for intellisense)
|
|
470
|
+
* @param indexOrDescription Index or description of the layer
|
|
471
|
+
* @param description Optional description of the layer
|
|
472
|
+
* @returns The numeric value of the registered collision layer
|
|
473
|
+
*/
|
|
474
|
+
registerCollisionLayer(name: string, indexOrDescription?: number | string, description?: string): number;
|
|
475
|
+
/**
|
|
476
|
+
* Gets a registered collision layer by name.
|
|
477
|
+
*
|
|
478
|
+
* @param name Name of the collision layer
|
|
479
|
+
* @returns The numeric value of the registered collision layer or undefined if not found
|
|
480
|
+
*/
|
|
481
|
+
getCollisionLayer(name: string): number | undefined;
|
|
482
|
+
/**
|
|
483
|
+
* Gets all registered collision layers.
|
|
484
|
+
*
|
|
485
|
+
* @returns Array of all registered collision layers
|
|
486
|
+
*/
|
|
487
|
+
getCollisionLayers(): RegisteredCollisionLayer[];
|
|
488
|
+
/**
|
|
489
|
+
* Removes a registered collision layer.
|
|
490
|
+
*
|
|
491
|
+
* @param name Name of the collision layer to remove
|
|
492
|
+
* @returns True if the layer was removed, false if it didn't exist
|
|
493
|
+
*/
|
|
494
|
+
removeCollisionLayer(name: string): boolean;
|
|
495
|
+
/**
|
|
496
|
+
* Clears all registered collision layers.
|
|
497
|
+
*/
|
|
498
|
+
clearCollisionLayers(): void;
|
|
499
|
+
/**
|
|
500
|
+
* Checks if two AABB rectangles overlap.
|
|
501
|
+
*
|
|
502
|
+
* @param a - The first AABB rectangle
|
|
503
|
+
* @param b - The second AABB rectangle
|
|
504
|
+
* @returns True if the rectangles overlap, false otherwise
|
|
505
|
+
*/
|
|
506
|
+
aabbOverlap(a: AABBLike, b: AABBLike): boolean;
|
|
507
|
+
}
|
|
508
|
+
//# sourceMappingURL=CrunchPhysicsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CrunchPhysicsPlugin.d.ts","sourceRoot":"","sources":["../src/CrunchPhysicsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAiB,MAAM,EAAW,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,SAAS,IAAI,aAAa,EAAqB,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM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