@rpgjs/common 4.3.0 → 5.0.0-alpha.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/dist/Physic.d.ts +619 -0
- package/dist/Player.d.ts +198 -0
- package/{lib → dist}/Utils.d.ts +19 -2
- package/dist/database/Item.d.ts +10 -0
- package/dist/database/index.d.ts +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +16741 -0
- package/dist/index.js.map +1 -0
- package/dist/modules.d.ts +92 -0
- package/dist/movement/MovementManager.d.ts +84 -0
- package/dist/movement/MovementStrategy.d.ts +39 -0
- package/dist/movement/index.d.ts +12 -0
- package/dist/movement/strategies/CompositeMovement.d.ts +76 -0
- package/dist/movement/strategies/Dash.d.ts +52 -0
- package/dist/movement/strategies/IceMovement.d.ts +87 -0
- package/dist/movement/strategies/Knockback.d.ts +50 -0
- package/dist/movement/strategies/LinearMove.d.ts +43 -0
- package/dist/movement/strategies/LinearRepulsion.d.ts +55 -0
- package/dist/movement/strategies/Oscillate.d.ts +60 -0
- package/dist/movement/strategies/PathFollow.d.ts +78 -0
- package/dist/movement/strategies/ProjectileMovement.d.ts +138 -0
- package/dist/movement/strategies/SeekAvoid.d.ts +27 -0
- package/dist/rooms/Map.d.ts +109 -0
- package/dist/services/updateMap.d.ts +7 -0
- package/package.json +17 -17
- package/src/Physic.ts +1644 -0
- package/src/Player.ts +262 -26
- package/src/{gui/PrebuiltGui.ts → PrebuiltGui.ts} +1 -1
- package/src/Utils.ts +184 -123
- package/src/database/Item.ts +19 -0
- package/src/database/index.ts +1 -0
- package/src/index.ts +9 -25
- package/src/modules.ts +230 -0
- package/src/movement/MovementManager.ts +142 -0
- package/src/movement/MovementStrategy.ts +42 -0
- package/src/movement/index.ts +15 -0
- package/src/movement/strategies/CompositeMovement.ts +173 -0
- package/src/movement/strategies/Dash.ts +82 -0
- package/src/movement/strategies/IceMovement.ts +158 -0
- package/src/movement/strategies/Knockback.ts +81 -0
- package/src/movement/strategies/LinearMove.ts +58 -0
- package/src/movement/strategies/LinearRepulsion.ts +128 -0
- package/src/movement/strategies/Oscillate.ts +144 -0
- package/src/movement/strategies/PathFollow.ts +156 -0
- package/src/movement/strategies/ProjectileMovement.ts +322 -0
- package/src/movement/strategies/SeekAvoid.ts +123 -0
- package/src/rooms/Map.ts +272 -0
- package/src/services/updateMap.ts +9 -0
- package/tests/physic.spec.ts +454 -0
- package/tsconfig.json +8 -3
- package/vite.config.ts +21 -0
- package/CHANGELOG.md +0 -160
- package/LICENSE +0 -19
- package/browser/manifest.json +0 -7
- package/browser/rpg.common.js +0 -11357
- package/browser/rpg.common.umd.cjs +0 -11358
- package/lib/AbstractObject.d.ts +0 -322
- package/lib/AbstractObject.js +0 -872
- package/lib/AbstractObject.js.map +0 -1
- package/lib/Color.d.ts +0 -1
- package/lib/Color.js +0 -25
- package/lib/Color.js.map +0 -1
- package/lib/DefaultInput.d.ts +0 -2
- package/lib/DefaultInput.js +0 -26
- package/lib/DefaultInput.js.map +0 -1
- package/lib/Event.d.ts +0 -3
- package/lib/Event.js +0 -4
- package/lib/Event.js.map +0 -1
- package/lib/EventEmitter.d.ts +0 -10
- package/lib/EventEmitter.js +0 -61
- package/lib/EventEmitter.js.map +0 -1
- package/lib/Game.d.ts +0 -28
- package/lib/Game.js +0 -127
- package/lib/Game.js.map +0 -1
- package/lib/Hit.d.ts +0 -16
- package/lib/Hit.js +0 -65
- package/lib/Hit.js.map +0 -1
- package/lib/Inject.d.ts +0 -9
- package/lib/Inject.js +0 -17
- package/lib/Inject.js.map +0 -1
- package/lib/Logger.d.ts +0 -2
- package/lib/Logger.js +0 -7
- package/lib/Logger.js.map +0 -1
- package/lib/Map.d.ts +0 -174
- package/lib/Map.js +0 -263
- package/lib/Map.js.map +0 -1
- package/lib/Module.d.ts +0 -16
- package/lib/Module.js +0 -139
- package/lib/Module.js.map +0 -1
- package/lib/Player.d.ts +0 -26
- package/lib/Player.js +0 -19
- package/lib/Player.js.map +0 -1
- package/lib/Plugin.d.ts +0 -67
- package/lib/Plugin.js +0 -92
- package/lib/Plugin.js.map +0 -1
- package/lib/Scheduler.d.ts +0 -26
- package/lib/Scheduler.js +0 -90
- package/lib/Scheduler.js.map +0 -1
- package/lib/Shape.d.ts +0 -127
- package/lib/Shape.js +0 -261
- package/lib/Shape.js.map +0 -1
- package/lib/Utils.js +0 -181
- package/lib/Utils.js.map +0 -1
- package/lib/Vector2d.d.ts +0 -20
- package/lib/Vector2d.js +0 -63
- package/lib/Vector2d.js.map +0 -1
- package/lib/VirtualGrid.d.ts +0 -26
- package/lib/VirtualGrid.js +0 -68
- package/lib/VirtualGrid.js.map +0 -1
- package/lib/Worker.d.ts +0 -7
- package/lib/Worker.js +0 -13
- package/lib/Worker.js.map +0 -1
- package/lib/WorldMaps.d.ts +0 -105
- package/lib/WorldMaps.js +0 -184
- package/lib/WorldMaps.js.map +0 -1
- package/lib/gui/PrebuiltGui.js +0 -29
- package/lib/gui/PrebuiltGui.js.map +0 -1
- package/lib/index.d.ts +0 -25
- package/lib/index.js +0 -26
- package/lib/index.js.map +0 -1
- package/lib/transports/io.d.ts +0 -22
- package/lib/transports/io.js +0 -82
- package/lib/transports/io.js.map +0 -1
- package/lib/workers/move.d.ts +0 -1
- package/lib/workers/move.js +0 -57
- package/lib/workers/move.js.map +0 -1
- package/rpg.toml +0 -11
- package/src/AbstractObject.ts +0 -973
- package/src/Color.ts +0 -29
- package/src/DefaultInput.ts +0 -26
- package/src/Event.ts +0 -3
- package/src/EventEmitter.ts +0 -65
- package/src/Game.ts +0 -159
- package/src/Hit.ts +0 -70
- package/src/Inject.ts +0 -22
- package/src/Logger.ts +0 -7
- package/src/Map.ts +0 -335
- package/src/Module.ts +0 -144
- package/src/Plugin.ts +0 -100
- package/src/Scheduler.ts +0 -95
- package/src/Shape.ts +0 -302
- package/src/Vector2d.ts +0 -70
- package/src/VirtualGrid.ts +0 -78
- package/src/Worker.ts +0 -17
- package/src/WorldMaps.ts +0 -204
- package/src/transports/io.ts +0 -91
- package/src/workers/move.ts +0 -61
- /package/{lib/gui → dist}/PrebuiltGui.d.ts +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Context, Provider } from '@signe/di';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare const ModulesToken = "ModulesToken";
|
|
4
|
+
export declare class Hooks {
|
|
5
|
+
private modules;
|
|
6
|
+
private namespace;
|
|
7
|
+
/**
|
|
8
|
+
* Store of all module hooks by ID
|
|
9
|
+
*/
|
|
10
|
+
private moduleHooks;
|
|
11
|
+
/**
|
|
12
|
+
* Store of all hook functions by ID
|
|
13
|
+
*/
|
|
14
|
+
private hookFunctions;
|
|
15
|
+
constructor(modules: any[], namespace: string);
|
|
16
|
+
private init;
|
|
17
|
+
/**
|
|
18
|
+
* Call hooks for a specific ID, passing arguments to all subscribed hooks
|
|
19
|
+
*
|
|
20
|
+
* @param hookId - The unique identifier of the module hook
|
|
21
|
+
* @param args - Arguments to pass to the hook functions
|
|
22
|
+
* @returns An Observable that emits an array with all hook results when subscribed
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Call all hook functions for the ID 'my-namespace-type-hook'
|
|
26
|
+
* callHooks('my-namespace-type-hook', { x: 10, y: 20 }).subscribe(results => {
|
|
27
|
+
* console.log('Hook results:', results); // Array of all hook function results
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Hook functions are only executed when you subscribe to the returned Observable
|
|
31
|
+
* const observable = callHooks('my-namespace-type-hook', player);
|
|
32
|
+
* // ... later ...
|
|
33
|
+
* observable.subscribe(results => {
|
|
34
|
+
* // Process results array
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
callHooks(hookId: string, ...args: any[]): Observable<any[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Provide modules configuration to Angular Dependency Injection
|
|
42
|
+
* Registers hook functions for later execution
|
|
43
|
+
*
|
|
44
|
+
* @param modules - Array of modules to provide
|
|
45
|
+
* @param namespace - Namespace to prefix hook IDs
|
|
46
|
+
* @returns Provider configuration for Angular DI
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Define modules
|
|
50
|
+
* const modules = [
|
|
51
|
+
* {
|
|
52
|
+
* player: {
|
|
53
|
+
* onMove: (player) => {
|
|
54
|
+
* // Handle player movement
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ];
|
|
59
|
+
*
|
|
60
|
+
* // Provide modules
|
|
61
|
+
* const provider = provideModules(modules, 'game');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function provideModules(modules: any[], namespace: string, transform?: (modules: any, context: Context) => any): {
|
|
65
|
+
provide: string;
|
|
66
|
+
useFactory: (context: Context) => Hooks;
|
|
67
|
+
};
|
|
68
|
+
export declare function findModules(context: Context, namespace: string): any[];
|
|
69
|
+
/**
|
|
70
|
+
* Create module providers from a token name and array of providers
|
|
71
|
+
* Transforms objects with server/client properties into separate ModuleServer and ModuleClient providers
|
|
72
|
+
*
|
|
73
|
+
* @param tokenName - The base token name for the module
|
|
74
|
+
* @param providers - Array of providers that can be regular providers or objects with server/client properties
|
|
75
|
+
* @returns Flattened array of providers with transformed server/client objects
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Input: createModule('battle', [{ server: serverModule, client: clientModule }])
|
|
79
|
+
* // Output: [
|
|
80
|
+
* // { provide: 'battleModuleServer', useValue: { server: serverModule, client: clientModule }, meta: { server: true, isModule: true } },
|
|
81
|
+
* // { provide: 'battleModuleClient', useValue: { server: serverModule, client: clientModule }, meta: { client: true, isModule: true } }
|
|
82
|
+
* // ]
|
|
83
|
+
*
|
|
84
|
+
* // Regular providers are passed through unchanged
|
|
85
|
+
* createModule('battle', [regularProvider, { server, client }])
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function createModule(tokenName: string, providers: (Provider | Provider[] | ({
|
|
89
|
+
server?: any;
|
|
90
|
+
client?: any;
|
|
91
|
+
}))[]): any[];
|
|
92
|
+
export declare function defineModule<T>(options: T): T;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MovementStrategy } from './MovementStrategy';
|
|
2
|
+
import { RpgCommonPhysic } from '../Physic';
|
|
3
|
+
/**
|
|
4
|
+
* Manager for entity movement strategies
|
|
5
|
+
*
|
|
6
|
+
* Handles the execution and lifecycle of all movement strategies
|
|
7
|
+
* for entities in the game world.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // In game loop
|
|
12
|
+
* const movementManager = new MovementManager();
|
|
13
|
+
*
|
|
14
|
+
* // Add dash movement to player
|
|
15
|
+
* movementManager.add('player1', new Dash(200, { x: 1, y: 0 }, 300));
|
|
16
|
+
*
|
|
17
|
+
* // Update in game loop
|
|
18
|
+
* function gameLoop(dt) {
|
|
19
|
+
* movementManager.update(dt, physic);
|
|
20
|
+
* physic.update(dt);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class MovementManager {
|
|
25
|
+
/** Map of entity IDs to their active movement strategies */
|
|
26
|
+
private strategies;
|
|
27
|
+
/**
|
|
28
|
+
* Add a movement strategy to an entity
|
|
29
|
+
*
|
|
30
|
+
* @param id - Entity ID
|
|
31
|
+
* @param strategy - Movement strategy to apply
|
|
32
|
+
*/
|
|
33
|
+
add(id: string, strategy: MovementStrategy): void;
|
|
34
|
+
/**
|
|
35
|
+
* Remove a specific movement strategy from an entity
|
|
36
|
+
*
|
|
37
|
+
* @param id - Entity ID
|
|
38
|
+
* @param strategy - The strategy instance to remove
|
|
39
|
+
* @returns True if the strategy was found and removed
|
|
40
|
+
*/
|
|
41
|
+
remove(id: string, strategy: MovementStrategy): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Remove all movement strategies from an entity
|
|
44
|
+
*
|
|
45
|
+
* @param id - Entity ID
|
|
46
|
+
*/
|
|
47
|
+
clear(id: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Check if an entity has any active movement strategies
|
|
50
|
+
*
|
|
51
|
+
* @param id - Entity ID
|
|
52
|
+
* @returns True if entity has active strategies
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // Check if player has active movements
|
|
57
|
+
* if (movementManager.hasActiveStrategies('player1')) {
|
|
58
|
+
* // Don't accept input while movements are active
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
hasActiveStrategies(id: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Get all active movement strategies for an entity
|
|
65
|
+
*
|
|
66
|
+
* @param id - Entity ID
|
|
67
|
+
* @returns Array of active strategies or empty array if none
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* // Get all player movements
|
|
72
|
+
* const movements = movementManager.getStrategies('player1');
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
getStrategies(id: string): MovementStrategy[];
|
|
76
|
+
/**
|
|
77
|
+
* Update all movement strategies
|
|
78
|
+
* Must be called BEFORE physics.update()
|
|
79
|
+
*
|
|
80
|
+
* @param dt - Time delta in milliseconds
|
|
81
|
+
* @param physic - Physics system to get bodies from
|
|
82
|
+
*/
|
|
83
|
+
update(dt: number, physic: RpgCommonPhysic): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Matter from 'matter-js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface defining the contract for movement strategies
|
|
4
|
+
*
|
|
5
|
+
* Movement strategies are responsible for calculating how a body should move
|
|
6
|
+
* each frame without directly modifying the physics engine.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* class SimpleMove implements MovementStrategy {
|
|
11
|
+
* constructor(private vx: number, private vy: number) {}
|
|
12
|
+
*
|
|
13
|
+
* update(body: Matter.Body, dt: number): void {
|
|
14
|
+
* Matter.Body.setVelocity(body, { x: this.vx, y: this.vy });
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface MovementStrategy {
|
|
20
|
+
/**
|
|
21
|
+
* Called each frame BEFORE the physics engine update
|
|
22
|
+
* Calculates and applies movement to the provided body
|
|
23
|
+
*
|
|
24
|
+
* @param body - The Matter.js body to move
|
|
25
|
+
* @param dt - Time delta in milliseconds
|
|
26
|
+
*/
|
|
27
|
+
update(body: Matter.Body, dt: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns true when the movement is finished (optional)
|
|
30
|
+
* If implemented, the strategy will be automatically removed
|
|
31
|
+
* from the movement manager when it returns true
|
|
32
|
+
*/
|
|
33
|
+
isFinished?(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Event triggered when the movement completes (optional)
|
|
36
|
+
* Useful for chaining movements
|
|
37
|
+
*/
|
|
38
|
+
onFinished?(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './MovementStrategy';
|
|
2
|
+
export * from './MovementManager';
|
|
3
|
+
export * from './strategies/LinearMove';
|
|
4
|
+
export * from './strategies/Dash';
|
|
5
|
+
export * from './strategies/Knockback';
|
|
6
|
+
export * from './strategies/PathFollow';
|
|
7
|
+
export * from './strategies/Oscillate';
|
|
8
|
+
export * from './strategies/CompositeMovement';
|
|
9
|
+
export * from './strategies/SeekAvoid';
|
|
10
|
+
export * from './strategies/LinearRepulsion';
|
|
11
|
+
export * from './strategies/IceMovement';
|
|
12
|
+
export * from './strategies/ProjectileMovement';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Combines multiple movement strategies into a single movement
|
|
5
|
+
*
|
|
6
|
+
* Allows composition of movement patterns by either:
|
|
7
|
+
* - Running multiple strategies in parallel (adding their effects)
|
|
8
|
+
* - Running strategies in sequence (one after another)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Parallel movement (oscillate while following a path)
|
|
13
|
+
* const composite = new CompositeMovement('parallel', [
|
|
14
|
+
* new PathFollow(waypoints, 2),
|
|
15
|
+
* new Oscillate({ x: 0, y: 1 }, 10, 1000)
|
|
16
|
+
* ]);
|
|
17
|
+
*
|
|
18
|
+
* // Sequential movement (dash, then knockback)
|
|
19
|
+
* const sequence = new CompositeMovement('sequence', [
|
|
20
|
+
* new Dash(8, { x: 1, y: 0 }, 200),
|
|
21
|
+
* new Knockback({ x: -0.5, y: 0 }, 3, 300)
|
|
22
|
+
* ]);
|
|
23
|
+
*
|
|
24
|
+
* movementManager.add('entity1', composite);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class CompositeMovement implements MovementStrategy {
|
|
28
|
+
private mode;
|
|
29
|
+
private strategies;
|
|
30
|
+
private currentStrategyIndex;
|
|
31
|
+
/**
|
|
32
|
+
* Create a composite movement
|
|
33
|
+
*
|
|
34
|
+
* @param mode - How to combine strategies ('parallel' or 'sequence')
|
|
35
|
+
* @param strategies - Array of movement strategies to combine
|
|
36
|
+
*/
|
|
37
|
+
constructor(mode: 'parallel' | 'sequence', strategies: MovementStrategy[]);
|
|
38
|
+
/**
|
|
39
|
+
* Apply the composite movement
|
|
40
|
+
*
|
|
41
|
+
* @param body - Matter.js body to move
|
|
42
|
+
* @param dt - Time delta in milliseconds
|
|
43
|
+
*/
|
|
44
|
+
update(body: Matter.Body, dt: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Update all strategies in parallel
|
|
47
|
+
*/
|
|
48
|
+
private updateParallel;
|
|
49
|
+
/**
|
|
50
|
+
* Update strategies in sequence
|
|
51
|
+
*/
|
|
52
|
+
private updateSequence;
|
|
53
|
+
/**
|
|
54
|
+
* Check if all strategies have finished
|
|
55
|
+
*
|
|
56
|
+
* @returns True if all strategies are completed
|
|
57
|
+
*/
|
|
58
|
+
isFinished(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Add a new strategy to the composite
|
|
61
|
+
*
|
|
62
|
+
* @param strategy - Movement strategy to add
|
|
63
|
+
*/
|
|
64
|
+
add(strategy: MovementStrategy): void;
|
|
65
|
+
/**
|
|
66
|
+
* Remove a strategy from the composite
|
|
67
|
+
*
|
|
68
|
+
* @param strategy - Movement strategy to remove
|
|
69
|
+
* @returns True if the strategy was found and removed
|
|
70
|
+
*/
|
|
71
|
+
remove(strategy: MovementStrategy): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Reset the composite to start from the beginning
|
|
74
|
+
*/
|
|
75
|
+
reset(): void;
|
|
76
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements a dash movement in a specified direction for a limited time
|
|
5
|
+
*
|
|
6
|
+
* Dash applies high velocity movement in a direction for a short duration
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // Dash right for 200ms at speed 10
|
|
11
|
+
* movementManager.add('player1', new Dash(10, { x: 1, y: 0 }, 200));
|
|
12
|
+
*
|
|
13
|
+
* // Dash diagonally (normalized)
|
|
14
|
+
* movementManager.add('player1', new Dash(8, { x: 0.7071, y: 0.7071 }, 150));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class Dash implements MovementStrategy {
|
|
18
|
+
private speed;
|
|
19
|
+
private direction;
|
|
20
|
+
private duration;
|
|
21
|
+
private elapsed;
|
|
22
|
+
private finished;
|
|
23
|
+
/**
|
|
24
|
+
* Create a dash movement
|
|
25
|
+
*
|
|
26
|
+
* @param speed - Movement speed (pixels per frame)
|
|
27
|
+
* @param direction - Normalized direction vector { x, y }
|
|
28
|
+
* @param duration - Duration in milliseconds
|
|
29
|
+
*/
|
|
30
|
+
constructor(speed: number, direction: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
}, duration: number);
|
|
34
|
+
/**
|
|
35
|
+
* Apply dash movement to the body
|
|
36
|
+
*
|
|
37
|
+
* @param body - Matter.js body to move
|
|
38
|
+
* @param dt - Time delta in milliseconds
|
|
39
|
+
*/
|
|
40
|
+
update(body: Matter.Body, dt: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Check if dash duration has elapsed
|
|
43
|
+
*
|
|
44
|
+
* @returns True if dash is complete
|
|
45
|
+
*/
|
|
46
|
+
isFinished(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Optional callback for when dash completes
|
|
49
|
+
* Can be used to chain into another movement
|
|
50
|
+
*/
|
|
51
|
+
onFinished(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements a slippery movement for icy surfaces
|
|
5
|
+
*
|
|
6
|
+
* Creates a realistic ice-physics effect with:
|
|
7
|
+
* - Slow acceleration when starting to move
|
|
8
|
+
* - Slippery inertia when stopping
|
|
9
|
+
* - Gradual turning with momentum
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Apply ice movement to player on ice terrain
|
|
14
|
+
* movementManager.add('player1', new IceMovement({ x: 1, y: 0 }, 5));
|
|
15
|
+
*
|
|
16
|
+
* // Update direction when player changes direction
|
|
17
|
+
* iceMovement.setTargetDirection({ x: 0, y: 1 });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class IceMovement implements MovementStrategy {
|
|
21
|
+
private targetDirection;
|
|
22
|
+
private maxSpeed;
|
|
23
|
+
private acceleration;
|
|
24
|
+
private friction;
|
|
25
|
+
private duration?;
|
|
26
|
+
private currentVx;
|
|
27
|
+
private currentVy;
|
|
28
|
+
private stopped;
|
|
29
|
+
private elapsed;
|
|
30
|
+
/**
|
|
31
|
+
* Create an ice movement behavior
|
|
32
|
+
*
|
|
33
|
+
* @param targetDirection - Desired movement direction (normalized vector)
|
|
34
|
+
* @param maxSpeed - Maximum speed when fully accelerated
|
|
35
|
+
* @param acceleration - Acceleration rate (0-1, lower = more slippery start)
|
|
36
|
+
* @param friction - Friction rate (0-1, lower = more slippery stop)
|
|
37
|
+
* @param duration - Optional duration limit for the movement
|
|
38
|
+
*/
|
|
39
|
+
constructor(targetDirection: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
}, maxSpeed?: number, acceleration?: number, friction?: number, duration?: number | undefined);
|
|
43
|
+
/**
|
|
44
|
+
* Update the ice movement physics
|
|
45
|
+
*
|
|
46
|
+
* @param body - Matter.js body to move
|
|
47
|
+
* @param dt - Time delta in milliseconds
|
|
48
|
+
*/
|
|
49
|
+
update(body: Matter.Body, dt: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Check if movement is finished
|
|
52
|
+
* (movement is considered finished when almost stopped)
|
|
53
|
+
*
|
|
54
|
+
* @returns True if movement is effectively stopped
|
|
55
|
+
*/
|
|
56
|
+
isFinished(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Stop the movement (will start applying friction)
|
|
59
|
+
*/
|
|
60
|
+
stop(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Resume movement in the current direction
|
|
63
|
+
*/
|
|
64
|
+
resume(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Set a new target direction
|
|
67
|
+
* The actual movement will gradually change toward this direction
|
|
68
|
+
*
|
|
69
|
+
* @param direction - New target direction
|
|
70
|
+
*/
|
|
71
|
+
setTargetDirection(direction: {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}): void;
|
|
75
|
+
/**
|
|
76
|
+
* Set movement parameters
|
|
77
|
+
*
|
|
78
|
+
* @param maxSpeed - New maximum speed
|
|
79
|
+
* @param acceleration - New acceleration rate
|
|
80
|
+
* @param friction - New friction rate
|
|
81
|
+
*/
|
|
82
|
+
setParameters(maxSpeed?: number, acceleration?: number, friction?: number): void;
|
|
83
|
+
/**
|
|
84
|
+
* Normalize the direction vector
|
|
85
|
+
*/
|
|
86
|
+
private normalizeDirection;
|
|
87
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements a knockback effect with decreasing force over time
|
|
5
|
+
*
|
|
6
|
+
* Applies an initial velocity that gradually decreases to simulate
|
|
7
|
+
* being pushed back by an impact
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Knockback player to the left with force 8 for 300ms
|
|
12
|
+
* movementManager.add('player1', new Knockback({ x: -1, y: 0 }, 8, 300));
|
|
13
|
+
*
|
|
14
|
+
* // Knockback with decay (resistance)
|
|
15
|
+
* movementManager.add('enemy1', new Knockback({ x: 0, y: 1 }, 5, 200, 0.9));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class Knockback implements MovementStrategy {
|
|
19
|
+
private direction;
|
|
20
|
+
private force;
|
|
21
|
+
private duration;
|
|
22
|
+
private decayFactor;
|
|
23
|
+
private elapsed;
|
|
24
|
+
private currentSpeed;
|
|
25
|
+
/**
|
|
26
|
+
* Create a knockback movement
|
|
27
|
+
*
|
|
28
|
+
* @param direction - Normalized direction vector { x, y }
|
|
29
|
+
* @param force - Initial force of the knockback
|
|
30
|
+
* @param duration - Duration in milliseconds
|
|
31
|
+
* @param decayFactor - Speed decay multiplier per frame (0.8-0.95 typical)
|
|
32
|
+
*/
|
|
33
|
+
constructor(direction: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
}, force: number, duration: number, decayFactor?: number);
|
|
37
|
+
/**
|
|
38
|
+
* Apply knockback movement with decreasing force
|
|
39
|
+
*
|
|
40
|
+
* @param body - Matter.js body to move
|
|
41
|
+
* @param dt - Time delta in milliseconds
|
|
42
|
+
*/
|
|
43
|
+
update(body: Matter.Body, dt: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if knockback duration has elapsed
|
|
46
|
+
*
|
|
47
|
+
* @returns True if knockback is complete
|
|
48
|
+
*/
|
|
49
|
+
isFinished(): boolean;
|
|
50
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Applies constant velocity movement in a specified direction
|
|
5
|
+
*
|
|
6
|
+
* Used for simple linear movement at a constant speed
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // Move entity right at 5 pixels per frame
|
|
11
|
+
* movementManager.add('entity1', new LinearMove(5, 0));
|
|
12
|
+
*
|
|
13
|
+
* // Move diagonally
|
|
14
|
+
* movementManager.add('entity1', new LinearMove(3, 3));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class LinearMove implements MovementStrategy {
|
|
18
|
+
private vx;
|
|
19
|
+
private vy;
|
|
20
|
+
private duration?;
|
|
21
|
+
/**
|
|
22
|
+
* Create a linear movement
|
|
23
|
+
*
|
|
24
|
+
* @param vx - X velocity component
|
|
25
|
+
* @param vy - Y velocity component
|
|
26
|
+
* @param duration - Optional duration in milliseconds (if not set, movement continues indefinitely)
|
|
27
|
+
*/
|
|
28
|
+
constructor(vx: number, vy: number, duration?: number | undefined);
|
|
29
|
+
private elapsed;
|
|
30
|
+
/**
|
|
31
|
+
* Apply velocity to the body
|
|
32
|
+
*
|
|
33
|
+
* @param body - Matter.js body to move
|
|
34
|
+
* @param dt - Time delta in milliseconds
|
|
35
|
+
*/
|
|
36
|
+
update(body: Matter.Body, dt: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Check if movement duration has elapsed
|
|
39
|
+
*
|
|
40
|
+
* @returns True if movement should stop
|
|
41
|
+
*/
|
|
42
|
+
isFinished(): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RpgCommonPhysic } from '../../Physic';
|
|
2
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
3
|
+
import * as Matter from 'matter-js';
|
|
4
|
+
/**
|
|
5
|
+
* Implements a seek behavior with linear obstacle avoidance
|
|
6
|
+
*
|
|
7
|
+
* Similar to SeekAvoid but uses a linear repulsion model instead of inverse square.
|
|
8
|
+
* This creates a smoother avoidance field with gradual transitions.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Make enemy follow player with smooth avoidance
|
|
13
|
+
* const playerPosition = () => Matter.Vector.create(player.x(), player.y());
|
|
14
|
+
* movementManager.add('enemy1', new LinearRepulsion(physics, playerPosition, 3, 50, 5));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class LinearRepulsion implements MovementStrategy {
|
|
18
|
+
private phys;
|
|
19
|
+
private target;
|
|
20
|
+
private maxSpeed;
|
|
21
|
+
private repulseRadius;
|
|
22
|
+
private repulseWeight;
|
|
23
|
+
private repulseRadius2;
|
|
24
|
+
/**
|
|
25
|
+
* Create a seeking movement with linear obstacle avoidance
|
|
26
|
+
*
|
|
27
|
+
* @param phys - Physics system to query for nearby obstacles
|
|
28
|
+
* @param target - Function returning the current target position
|
|
29
|
+
* @param maxSpeed - Maximum movement speed
|
|
30
|
+
* @param repulseRadius - Radius around entity to check for obstacles
|
|
31
|
+
* @param repulseWeight - Strength of repulsion from obstacles
|
|
32
|
+
*/
|
|
33
|
+
constructor(phys: RpgCommonPhysic, target: () => Matter.Vector, maxSpeed?: number, repulseRadius?: number, repulseWeight?: number);
|
|
34
|
+
/**
|
|
35
|
+
* Update seek and avoid behavior with linear repulsion
|
|
36
|
+
*
|
|
37
|
+
* @param body - Matter.js body to move
|
|
38
|
+
* @param dt - Time delta in milliseconds
|
|
39
|
+
*/
|
|
40
|
+
update(body: Matter.Body, dt: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Update the target to follow
|
|
43
|
+
*
|
|
44
|
+
* @param newTarget - Function returning the new target position
|
|
45
|
+
*/
|
|
46
|
+
setTarget(newTarget: () => Matter.Vector): void;
|
|
47
|
+
/**
|
|
48
|
+
* Update movement parameters
|
|
49
|
+
*
|
|
50
|
+
* @param maxSpeed - New maximum speed
|
|
51
|
+
* @param repulseRadius - New repulsion radius
|
|
52
|
+
* @param repulseWeight - New repulsion weight
|
|
53
|
+
*/
|
|
54
|
+
setParameters(maxSpeed?: number, repulseRadius?: number, repulseWeight?: number): void;
|
|
55
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MovementStrategy } from '../MovementStrategy';
|
|
2
|
+
import * as Matter from 'matter-js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements an oscillating movement pattern
|
|
5
|
+
*
|
|
6
|
+
* Entity moves back and forth along a single axis or in a pattern
|
|
7
|
+
* like sine wave, useful for patrols or ambient movements
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Horizontal oscillation with amplitude 100 and period 3000ms
|
|
12
|
+
* movementManager.add('entity1', new Oscillate({ x: 1, y: 0 }, 100, 3000));
|
|
13
|
+
*
|
|
14
|
+
* // Vertical oscillation
|
|
15
|
+
* movementManager.add('entity1', new Oscillate({ x: 0, y: 1 }, 50, 2000));
|
|
16
|
+
*
|
|
17
|
+
* // Circular oscillation
|
|
18
|
+
* movementManager.add('entity1', new Oscillate({ x: 1, y: 0 }, 100, 4000, 'circular'));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class Oscillate implements MovementStrategy {
|
|
22
|
+
private direction;
|
|
23
|
+
private amplitude;
|
|
24
|
+
private period;
|
|
25
|
+
private type;
|
|
26
|
+
private duration?;
|
|
27
|
+
private elapsed;
|
|
28
|
+
private startPosition;
|
|
29
|
+
private positionSet;
|
|
30
|
+
/**
|
|
31
|
+
* Create an oscillating movement
|
|
32
|
+
*
|
|
33
|
+
* @param direction - Primary axis of oscillation (normalized)
|
|
34
|
+
* @param amplitude - Maximum distance from center position
|
|
35
|
+
* @param period - Time in ms for a complete cycle
|
|
36
|
+
* @param type - Oscillation pattern type ('linear', 'sine', 'circular')
|
|
37
|
+
* @param duration - Optional total duration in ms (undefined for infinite)
|
|
38
|
+
*/
|
|
39
|
+
constructor(direction: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
}, amplitude: number, period: number, type?: 'linear' | 'sine' | 'circular', duration?: number | undefined);
|
|
43
|
+
/**
|
|
44
|
+
* Apply oscillating movement
|
|
45
|
+
*
|
|
46
|
+
* @param body - Matter.js body to move
|
|
47
|
+
* @param dt - Time delta in milliseconds
|
|
48
|
+
*/
|
|
49
|
+
update(body: Matter.Body, dt: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Check if oscillation duration has elapsed
|
|
52
|
+
*
|
|
53
|
+
* @returns True if movement is finished
|
|
54
|
+
*/
|
|
55
|
+
isFinished(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Reset the oscillation to start from the current position
|
|
58
|
+
*/
|
|
59
|
+
reset(): void;
|
|
60
|
+
}
|