@dryanovski/gamefoo 0.0.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/animate.d.ts +129 -0
- package/dist/core/animate.d.ts.map +1 -0
- package/dist/core/asset.d.ts +59 -0
- package/dist/core/asset.d.ts.map +1 -0
- package/dist/core/behaviour.d.ts +118 -0
- package/dist/core/behaviour.d.ts.map +1 -1
- package/dist/core/behaviours/collidable.d.ts +203 -4
- package/dist/core/behaviours/collidable.d.ts.map +1 -1
- package/dist/core/behaviours/control.d.ts +51 -3
- package/dist/core/behaviours/control.d.ts.map +1 -1
- package/dist/core/behaviours/healtkit.d.ts +120 -3
- package/dist/core/behaviours/healtkit.d.ts.map +1 -1
- package/dist/core/behaviours/sprite_render.d.ts +141 -0
- package/dist/core/behaviours/sprite_render.d.ts.map +1 -0
- package/dist/core/camera.d.ts +101 -0
- package/dist/core/camera.d.ts.map +1 -1
- package/dist/core/engine.d.ts +377 -15
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/fonts/font_bitmap.d.ts +156 -0
- package/dist/core/fonts/font_bitmap.d.ts.map +1 -0
- package/dist/core/fonts/font_bitmap_prebuild.d.ts +102 -0
- package/dist/core/fonts/font_bitmap_prebuild.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_3x5.d.ts +76 -0
- package/dist/core/fonts/internal/font_3x5.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_4x6.d.ts +76 -0
- package/dist/core/fonts/internal/font_4x6.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_5x5.d.ts +79 -0
- package/dist/core/fonts/internal/font_5x5.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_6x8.d.ts +76 -0
- package/dist/core/fonts/internal/font_6x8.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_8x13.d.ts +76 -0
- package/dist/core/fonts/internal/font_8x13.d.ts.map +1 -0
- package/dist/core/fonts/internal/font_8x8.d.ts +76 -0
- package/dist/core/fonts/internal/font_8x8.d.ts.map +1 -0
- package/dist/core/game_object_register.d.ts +101 -1
- package/dist/core/game_object_register.d.ts.map +1 -1
- package/dist/core/input.d.ts +131 -0
- package/dist/core/input.d.ts.map +1 -1
- package/dist/core/sprite.d.ts +232 -0
- package/dist/core/sprite.d.ts.map +1 -0
- package/dist/core/utils/perlin_noise.d.ts +136 -0
- package/dist/core/utils/perlin_noise.d.ts.map +1 -0
- package/dist/core/world.d.ts +147 -0
- package/dist/core/world.d.ts.map +1 -1
- package/dist/debug/monitor.d.ts +12 -0
- package/dist/debug/monitor.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/log.d.ts +33 -0
- package/dist/decorators/log.d.ts.map +1 -0
- package/dist/entities/dynamic_entity.d.ts +82 -0
- package/dist/entities/dynamic_entity.d.ts.map +1 -1
- package/dist/entities/entity.d.ts +216 -11
- package/dist/entities/entity.d.ts.map +1 -1
- package/dist/entities/player.d.ts +76 -0
- package/dist/entities/player.d.ts.map +1 -1
- package/dist/entities/text.d.ts +52 -0
- package/dist/entities/text.d.ts.map +1 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -604
- package/dist/index.js.map +3 -15
- package/dist/subsystems/camera_system.d.ts +25 -0
- package/dist/subsystems/camera_system.d.ts.map +1 -0
- package/dist/subsystems/collision_system.d.ts +16 -0
- package/dist/subsystems/collision_system.d.ts.map +1 -0
- package/dist/subsystems/monitor_system.d.ts +17 -0
- package/dist/subsystems/monitor_system.d.ts.map +1 -0
- package/dist/subsystems/object_system.d.ts +18 -0
- package/dist/subsystems/object_system.d.ts.map +1 -0
- package/dist/subsystems/types.d.ts +40 -0
- package/dist/subsystems/types.d.ts.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +25 -11
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame-based sprite animation controller.
|
|
3
|
+
*
|
|
4
|
+
* `Animate` steps through a sequence of spritesheet cells at a given
|
|
5
|
+
* frame rate. It tracks elapsed time internally and advances the
|
|
6
|
+
* current frame index each time the interval elapses.
|
|
7
|
+
*
|
|
8
|
+
* > **Note:** The {@link Animate.draw} method is currently a stub —
|
|
9
|
+
* > it resolves the correct frame but does not yet perform the actual
|
|
10
|
+
* > `drawImage` call. Use {@link SpriteRender} for production
|
|
11
|
+
* > sprite rendering.
|
|
12
|
+
*
|
|
13
|
+
* @category Core
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*
|
|
16
|
+
* @example Creating a walk animation
|
|
17
|
+
* ```ts
|
|
18
|
+
* const walkFrames = [
|
|
19
|
+
* { col: 0, row: 0 },
|
|
20
|
+
* { col: 1, row: 0 },
|
|
21
|
+
* { col: 2, row: 0 },
|
|
22
|
+
* { col: 3, row: 0 },
|
|
23
|
+
* ];
|
|
24
|
+
*
|
|
25
|
+
* const anim = new Animate("walk", walkFrames, 32, 32, 12);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Updating in a game loop
|
|
29
|
+
* ```ts
|
|
30
|
+
* function update(delta: number) {
|
|
31
|
+
* anim.update(delta);
|
|
32
|
+
* anim.draw(ctx, entity.x, entity.y);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see {@link SpriteRender} — behaviour-based alternative for entity rendering
|
|
37
|
+
* @see {@link Sprite} — spritesheet metadata container
|
|
38
|
+
*/
|
|
39
|
+
export default class Animate {
|
|
40
|
+
/** Identifier for this animation (e.g. `"walk"`, `"idle"`). */
|
|
41
|
+
private key;
|
|
42
|
+
/** Ordered list of spritesheet cells that make up the animation. */
|
|
43
|
+
private frames;
|
|
44
|
+
/** Width of a single frame in pixels. */
|
|
45
|
+
private frameW;
|
|
46
|
+
/** Height of a single frame in pixels. */
|
|
47
|
+
private frameH;
|
|
48
|
+
/**
|
|
49
|
+
* Index into {@link Animate.frames} of the frame currently being
|
|
50
|
+
* displayed.
|
|
51
|
+
*
|
|
52
|
+
* @defaultValue `0`
|
|
53
|
+
*/
|
|
54
|
+
private currentFrame;
|
|
55
|
+
/**
|
|
56
|
+
* Milliseconds accumulated since the last frame advance.
|
|
57
|
+
*
|
|
58
|
+
* @defaultValue `0`
|
|
59
|
+
*/
|
|
60
|
+
private elapsed;
|
|
61
|
+
/** Computed time between frames in milliseconds (`1000 / fps`). */
|
|
62
|
+
private interval;
|
|
63
|
+
/** Playback speed in frames per second. */
|
|
64
|
+
private fps;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new animation sequence.
|
|
67
|
+
*
|
|
68
|
+
* @param key - A unique name for this animation (used as a look-up key).
|
|
69
|
+
* @param frames - An ordered array of `{ col, row }` cells from the
|
|
70
|
+
* spritesheet.
|
|
71
|
+
* @param frameW - Width of each frame in pixels.
|
|
72
|
+
* @param frameH - Height of each frame in pixels.
|
|
73
|
+
* @param fps - Playback speed in frames per second.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const idle = new Animate(
|
|
78
|
+
* "idle",
|
|
79
|
+
* [{ col: 0, row: 1 }, { col: 1, row: 1 }],
|
|
80
|
+
* 64, 64,
|
|
81
|
+
* 8,
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
constructor(key: string, frames: {
|
|
86
|
+
col: number;
|
|
87
|
+
row: number;
|
|
88
|
+
}[], frameW: number, frameH: number, fps: number);
|
|
89
|
+
/**
|
|
90
|
+
* Advances the animation clock and moves to the next frame when the
|
|
91
|
+
* interval has elapsed.
|
|
92
|
+
*
|
|
93
|
+
* @param delta - Time elapsed since the last call, **in milliseconds**.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // Inside a requestAnimationFrame loop:
|
|
98
|
+
* anim.update(deltaMs);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
update(delta: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Draws the current animation frame to the canvas.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This method is currently a **stub**. It resolves the correct
|
|
107
|
+
* `{ col, row }` cell but does not perform the actual
|
|
108
|
+
* `ctx.drawImage()` call. Wire it to {@link Asset} or use
|
|
109
|
+
* {@link SpriteRender} for full rendering.
|
|
110
|
+
*
|
|
111
|
+
* @param _ctx - The canvas 2-D rendering context.
|
|
112
|
+
* @param _destX - Destination X coordinate on the canvas.
|
|
113
|
+
* @param _destY - Destination Y coordinate on the canvas.
|
|
114
|
+
*/
|
|
115
|
+
draw(_ctx: CanvasRenderingContext2D, _destX: number, _destY: number): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resets the animation to its first frame.
|
|
118
|
+
*
|
|
119
|
+
* Call this when switching animations or restarting a sequence.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* anim.reset();
|
|
124
|
+
* anim.update(0); // ensures frame 0 is active
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
reset(): void;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=animate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animate.d.ts","sourceRoot":"","sources":["../../src/core/animate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,+DAA+D;IAC/D,OAAO,CAAC,GAAG,CAAS;IAEpB,oEAAoE;IACpE,OAAO,CAAC,MAAM,CAAiC;IAE/C,yCAAyC;IACzC,OAAO,CAAC,MAAM,CAAS;IAEvB,0CAA0C;IAC1C,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;OAKG;IACH,OAAO,CAAC,YAAY,CAAa;IAEjC;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAK;IAEpB,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAS;IAEzB,2CAA2C;IAC3C,OAAO,CAAC,GAAG,CAAS;IAEpB;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAU5G;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM;IAS3B;;;;;;;;;;;;OAYG;IACI,IAAI,CAAC,IAAI,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO1E;;;;;;;;;;OAUG;IACI,KAAK;CAIb"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static image asset loader with an in-memory cache.
|
|
3
|
+
*
|
|
4
|
+
* `Asset` wraps the native `Image` constructor with a `Promise`-based
|
|
5
|
+
* API and caches loaded images by URL so repeated requests for the same
|
|
6
|
+
* source resolve instantly.
|
|
7
|
+
*
|
|
8
|
+
* @category Core
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*
|
|
11
|
+
* @example Loading an image
|
|
12
|
+
* ```ts
|
|
13
|
+
* const image = await Asset.load("sprites/hero.png");
|
|
14
|
+
* ctx.drawImage(image, 0, 0);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Pre-loading multiple assets
|
|
18
|
+
* ```ts
|
|
19
|
+
* await Promise.all([
|
|
20
|
+
* Asset.load("sprites/hero.png"),
|
|
21
|
+
* Asset.load("sprites/enemy.png"),
|
|
22
|
+
* Asset.load("tiles/grass.png"),
|
|
23
|
+
* ]);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see {@link Sprite} — consumes loaded images for spritesheet slicing
|
|
27
|
+
*/
|
|
28
|
+
export default class Asset {
|
|
29
|
+
/**
|
|
30
|
+
* Internal cache mapping source URLs to their loaded
|
|
31
|
+
* `HTMLImageElement` instances.
|
|
32
|
+
*/
|
|
33
|
+
private static cache;
|
|
34
|
+
/**
|
|
35
|
+
* Loads an image from the given URL.
|
|
36
|
+
*
|
|
37
|
+
* If the image has been loaded before, the cached `HTMLImageElement`
|
|
38
|
+
* is returned immediately (the `Promise` resolves synchronously on
|
|
39
|
+
* the microtask queue).
|
|
40
|
+
*
|
|
41
|
+
* @param src - URL or relative path of the image to load.
|
|
42
|
+
* @returns A `Promise` that resolves with the loaded
|
|
43
|
+
* `HTMLImageElement`.
|
|
44
|
+
*
|
|
45
|
+
* @throws {Error} If the image fails to load (e.g. 404 or network
|
|
46
|
+
* error). The error message includes the failing `src`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* try {
|
|
51
|
+
* const img = await Asset.load("missing.png");
|
|
52
|
+
* } catch (err) {
|
|
53
|
+
* console.error(err); // "Failed to load image: missing.png"
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static load(src: string): Promise<HTMLImageElement>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/core/asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAA4C;IAEhE;;;;;;;;;;;;;;;;;;;;;;OAsBG;WACU,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAkB1D"}
|
package/dist/core/behaviour.d.ts
CHANGED
|
@@ -1,14 +1,132 @@
|
|
|
1
1
|
import type Entity from "../entities/entity";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for all entity behaviours in the GameFoo engine.
|
|
4
|
+
*
|
|
5
|
+
* A **behaviour** is a self-contained unit of logic (input handling,
|
|
6
|
+
* collision response, health tracking, rendering, etc.) that can be
|
|
7
|
+
* attached to any {@link Entity} at runtime via
|
|
8
|
+
* {@link Entity.attachBehaviour}.
|
|
9
|
+
*
|
|
10
|
+
* Subclasses **must** implement:
|
|
11
|
+
* - {@link Behaviour.type | type} — a unique string identifier (e.g. `"control"`, `"healthkit"`).
|
|
12
|
+
* - {@link Behaviour.update | update} — called once per frame with `deltaTime`.
|
|
13
|
+
*
|
|
14
|
+
* Subclasses **may** override:
|
|
15
|
+
* - {@link Behaviour.render | render} — draw debug visuals or overlays.
|
|
16
|
+
* - {@link Behaviour.onAttach | onAttach} — setup hook when added to an entity.
|
|
17
|
+
* - {@link Behaviour.onDetach | onDetach} — teardown hook when removed.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - The entity type this behaviour operates on.
|
|
20
|
+
* Defaults to {@link Entity}; narrow it to {@link DynamicEntity} or
|
|
21
|
+
* {@link Player} when the behaviour needs velocity, speed, etc.
|
|
22
|
+
*
|
|
23
|
+
* @category Behaviours
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*
|
|
26
|
+
* @example Creating a custom behaviour
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Behaviour, type Entity } from "gamefoo";
|
|
29
|
+
*
|
|
30
|
+
* class Gravity extends Behaviour<Entity> {
|
|
31
|
+
* readonly type = "gravity";
|
|
32
|
+
*
|
|
33
|
+
* update(deltaTime: number): void {
|
|
34
|
+
* this.owner.y += 9.8 * 60 * deltaTime;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Attaching to an entity
|
|
40
|
+
* ```ts
|
|
41
|
+
* const entity = new Player("hero", 100, 100, 32, 32);
|
|
42
|
+
* entity.attachBehaviour(new Gravity(entity));
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link Entity.attachBehaviour}
|
|
46
|
+
* @see {@link Entity.detachBehaviour}
|
|
47
|
+
*/
|
|
2
48
|
export declare abstract class Behaviour<T extends Entity = Entity> {
|
|
49
|
+
/**
|
|
50
|
+
* Reference to the entity that owns this behaviour.
|
|
51
|
+
* Available to subclasses for reading and mutating entity state.
|
|
52
|
+
*/
|
|
3
53
|
protected owner: T;
|
|
54
|
+
/**
|
|
55
|
+
* Unique string identifier for this behaviour type.
|
|
56
|
+
*
|
|
57
|
+
* Used as the look-up key in {@link Entity.getBehaviour} and
|
|
58
|
+
* {@link Entity.hasBehaviour}. Must be a compile-time constant
|
|
59
|
+
* (`readonly`).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* class Gravity extends Behaviour {
|
|
64
|
+
* readonly type = "gravity";
|
|
65
|
+
* // ...
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
4
69
|
abstract readonly type: string;
|
|
70
|
+
/**
|
|
71
|
+
* Execution priority — lower numbers run first.
|
|
72
|
+
*
|
|
73
|
+
* When an entity has multiple behaviours, they are sorted by priority
|
|
74
|
+
* before each update/render pass.
|
|
75
|
+
*
|
|
76
|
+
* @defaultValue `1`
|
|
77
|
+
*/
|
|
5
78
|
priority: number;
|
|
79
|
+
/**
|
|
80
|
+
* Whether this behaviour is currently active.
|
|
81
|
+
*
|
|
82
|
+
* Disabled behaviours are skipped during both
|
|
83
|
+
* {@link Entity.updateBehaviours} and {@link Entity.renderBehaviours}.
|
|
84
|
+
*
|
|
85
|
+
* @defaultValue `true`
|
|
86
|
+
*/
|
|
6
87
|
enabled: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Derived look-up key, equal to {@link Behaviour.type} in lowercase.
|
|
90
|
+
*
|
|
91
|
+
* Used internally by the entity's behaviour map so that look-ups are
|
|
92
|
+
* case-insensitive.
|
|
93
|
+
*/
|
|
7
94
|
get key(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new behaviour bound to the given entity.
|
|
97
|
+
*
|
|
98
|
+
* @param owner - The entity this behaviour will operate on.
|
|
99
|
+
*/
|
|
8
100
|
constructor(owner: T);
|
|
101
|
+
/**
|
|
102
|
+
* Called once per frame to advance this behaviour's logic.
|
|
103
|
+
*
|
|
104
|
+
* @param deltaTime - Seconds elapsed since the previous frame.
|
|
105
|
+
*/
|
|
9
106
|
abstract update(deltaTime: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* Optional rendering hook invoked after the entity's own
|
|
109
|
+
* {@link Entity.render} call.
|
|
110
|
+
*
|
|
111
|
+
* Override this to draw debug shapes, health bars, status effects, etc.
|
|
112
|
+
*
|
|
113
|
+
* @param ctx - The canvas 2-D rendering context.
|
|
114
|
+
*/
|
|
10
115
|
render?(ctx: CanvasRenderingContext2D): void;
|
|
116
|
+
/**
|
|
117
|
+
* Lifecycle hook called immediately after the behaviour is attached
|
|
118
|
+
* to an entity via {@link Entity.attachBehaviour}.
|
|
119
|
+
*
|
|
120
|
+
* Use this for one-time setup such as registering with the
|
|
121
|
+
* collision {@link World}.
|
|
122
|
+
*/
|
|
11
123
|
onAttach?(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Lifecycle hook called when the behaviour is removed from an entity
|
|
126
|
+
* via {@link Entity.detachBehaviour}.
|
|
127
|
+
*
|
|
128
|
+
* Use this to unregister from external systems or release resources.
|
|
129
|
+
*/
|
|
12
130
|
onDetach?(): void;
|
|
13
131
|
}
|
|
14
132
|
//# sourceMappingURL=behaviour.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"behaviour.d.ts","sourceRoot":"","sources":["../../core/behaviour.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAE7C,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAEnB,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"behaviour.d.ts","sourceRoot":"","sources":["../../src/core/behaviour.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAE/B;;;;;;;OAOG;IACI,QAAQ,EAAE,MAAM,CAAK;IAE5B;;;;;;;OAOG;IACI,OAAO,EAAE,OAAO,CAAQ;IAE/B;;;;;OAKG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;OAIG;gBACS,KAAK,EAAE,CAAC;IAIpB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAExC;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;IAE5C;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,IAAI;IAEjB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,IAAI;CAClB"}
|
|
@@ -1,32 +1,231 @@
|
|
|
1
|
-
import type DynamicEntity from "../../entities/dynamic_entity";
|
|
2
1
|
import type Entity from "../../entities/entity";
|
|
3
|
-
import type { ColliderShape, CollisionInfo, WorldBounds } from "../../types";
|
|
2
|
+
import type { ColliderShape, CollisionInfo, GameObject, WorldBounds } from "../../types";
|
|
4
3
|
import { Behaviour } from "../behaviour";
|
|
5
4
|
import type World from "../world";
|
|
5
|
+
/**
|
|
6
|
+
* Options for constructing a {@link Collidable} behaviour.
|
|
7
|
+
*
|
|
8
|
+
* Every field except `shape` is optional and has a sensible default.
|
|
9
|
+
*
|
|
10
|
+
* @category Behaviours
|
|
11
|
+
* @since 0.1.0
|
|
12
|
+
*
|
|
13
|
+
* @example Minimal options
|
|
14
|
+
* ```ts
|
|
15
|
+
* const opts: CollidableOptions = {
|
|
16
|
+
* shape: { type: "aabb", width: 32, height: 32 },
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Full options
|
|
21
|
+
* ```ts
|
|
22
|
+
* const opts: CollidableOptions = {
|
|
23
|
+
* shape: { type: "circle", radius: 16 },
|
|
24
|
+
* layer: 0,
|
|
25
|
+
* tags: new Set(["enemy"]),
|
|
26
|
+
* solid: true,
|
|
27
|
+
* fixed: false,
|
|
28
|
+
* collidesWith: new Set(["player", "bullet"]),
|
|
29
|
+
* onCollision: (info) => console.log("hit!", info.other.id),
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
6
33
|
type CollidableOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* The geometric shape used for intersection tests.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link ColliderShape}
|
|
38
|
+
*/
|
|
7
39
|
shape: ColliderShape;
|
|
40
|
+
/**
|
|
41
|
+
* Collision layer index. Only colliders on the **same** layer are
|
|
42
|
+
* tested against each other.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue `0`
|
|
45
|
+
*/
|
|
8
46
|
layer?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Tags that identify *this* collider (e.g. `"player"`, `"bullet"`).
|
|
49
|
+
*
|
|
50
|
+
* @defaultValue empty `Set`
|
|
51
|
+
*/
|
|
9
52
|
tags?: Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Tags this collider is **interested in**. The `onCollision` callback
|
|
55
|
+
* only fires when the other collider has at least one matching tag.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue empty `Set`
|
|
58
|
+
*/
|
|
10
59
|
collidesWith?: Set<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Whether overlap resolution should be applied when this collider
|
|
62
|
+
* intersects another solid collider.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue `false`
|
|
65
|
+
*/
|
|
11
66
|
solid?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* If `true`, this collider is treated as immovable during overlap
|
|
69
|
+
* resolution — the other entity absorbs the full displacement.
|
|
70
|
+
*
|
|
71
|
+
* @defaultValue `false`
|
|
72
|
+
*/
|
|
12
73
|
fixed?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Callback invoked when a collision with a tag-matched collider is
|
|
76
|
+
* detected.
|
|
77
|
+
*
|
|
78
|
+
* @param info - Details about the collision, including both entities
|
|
79
|
+
* and their tag sets.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link CollisionInfo}
|
|
82
|
+
*/
|
|
13
83
|
onCollision?: (info: CollisionInfo) => void;
|
|
14
84
|
};
|
|
15
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Collision behaviour that can be attached to any {@link Entity}.
|
|
87
|
+
*
|
|
88
|
+
* When attached, the `Collidable` automatically registers itself with
|
|
89
|
+
* the engine's {@link World} (via {@link Collidable.onAttach}) and
|
|
90
|
+
* unregisters on detach. Each frame the `World` queries the collider's
|
|
91
|
+
* shape, bounds, and tags to determine intersections.
|
|
92
|
+
*
|
|
93
|
+
* @category Behaviours
|
|
94
|
+
* @since 0.1.0
|
|
95
|
+
*
|
|
96
|
+
* @example Creating and attaching a box collider
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { Collidable, Entity, type CollisionInfo } from "gamefoo";
|
|
99
|
+
*
|
|
100
|
+
* const entity = new Enemy("goblin", 100, 200, 30, 30);
|
|
101
|
+
*
|
|
102
|
+
* entity.attachBehaviour(
|
|
103
|
+
* new Collidable(entity, engine.collisions, {
|
|
104
|
+
* shape: { type: "aabb", width: 30, height: 30 },
|
|
105
|
+
* layer: 0,
|
|
106
|
+
* tags: new Set(["enemy"]),
|
|
107
|
+
* solid: true,
|
|
108
|
+
* collidesWith: new Set(["player"]),
|
|
109
|
+
* onCollision: (info: CollisionInfo) => {
|
|
110
|
+
* console.log(`${info.self.id} hit ${info.other.id}`);
|
|
111
|
+
* },
|
|
112
|
+
* }),
|
|
113
|
+
* );
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example Circle collider for a projectile
|
|
117
|
+
* ```ts
|
|
118
|
+
* entity.attachBehaviour(
|
|
119
|
+
* new Collidable(bullet, engine.collisions, {
|
|
120
|
+
* shape: { type: "circle", radius: 4 },
|
|
121
|
+
* tags: new Set(["bullet"]),
|
|
122
|
+
* collidesWith: new Set(["enemy"]),
|
|
123
|
+
* }),
|
|
124
|
+
* );
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link World} — the collision detection system
|
|
128
|
+
* @see {@link ColliderShape} — supported shape types
|
|
129
|
+
* @see {@link CollisionInfo} — payload delivered to callbacks
|
|
130
|
+
* @see {@link Behaviour} — abstract base class
|
|
131
|
+
*/
|
|
132
|
+
export declare class Collidable extends Behaviour<GameObject> {
|
|
133
|
+
/** @inheritDoc */
|
|
16
134
|
readonly type = "collidable";
|
|
135
|
+
/**
|
|
136
|
+
* Geometric shape used for intersection tests.
|
|
137
|
+
*
|
|
138
|
+
* @see {@link ColliderShape}
|
|
139
|
+
*/
|
|
17
140
|
shape: ColliderShape;
|
|
141
|
+
/**
|
|
142
|
+
* Collision layer. Only colliders sharing the same layer value are
|
|
143
|
+
* tested.
|
|
144
|
+
*
|
|
145
|
+
* @defaultValue `0`
|
|
146
|
+
*/
|
|
18
147
|
layer: number;
|
|
148
|
+
/**
|
|
149
|
+
* Tags identifying this collider (e.g. `"player"`, `"enemy"`).
|
|
150
|
+
*
|
|
151
|
+
* @defaultValue empty `Set`
|
|
152
|
+
*/
|
|
19
153
|
tags: Set<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Tags this collider wants to be notified about.
|
|
156
|
+
*
|
|
157
|
+
* @defaultValue empty `Set`
|
|
158
|
+
*/
|
|
20
159
|
collidesWith: Set<string>;
|
|
160
|
+
/**
|
|
161
|
+
* Whether this collider participates in overlap resolution.
|
|
162
|
+
*
|
|
163
|
+
* @defaultValue `false`
|
|
164
|
+
*/
|
|
21
165
|
solid: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Whether the owning entity is immovable during overlap resolution.
|
|
168
|
+
*
|
|
169
|
+
* @defaultValue `false`
|
|
170
|
+
*/
|
|
22
171
|
fixed: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* User-supplied callback invoked when a tag-matched collision is
|
|
174
|
+
* detected.
|
|
175
|
+
*/
|
|
23
176
|
onCollision: (info: CollisionInfo) => void;
|
|
177
|
+
/** Reference to the {@link World} this collider is registered with. */
|
|
24
178
|
private world;
|
|
25
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Creates a new collidable behaviour.
|
|
181
|
+
*
|
|
182
|
+
* @param owner - The game object entity that owns this collider.
|
|
183
|
+
* @param world - The collision {@link World} to register with.
|
|
184
|
+
* @param options - Configuration for shape, tags, solidity, and
|
|
185
|
+
* callbacks. See {@link CollidableOptions}.
|
|
186
|
+
*/
|
|
187
|
+
constructor(owner: GameObject, world: World, options: CollidableOptions);
|
|
188
|
+
/**
|
|
189
|
+
* No-op — collision logic lives in {@link World.detect}.
|
|
190
|
+
*
|
|
191
|
+
* @param _deltaTime - Unused.
|
|
192
|
+
*/
|
|
26
193
|
update(_deltaTime: number): void;
|
|
194
|
+
/**
|
|
195
|
+
* Lifecycle hook: registers this collider with the {@link World}
|
|
196
|
+
* when the behaviour is attached to an entity.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link Behaviour.onAttach}
|
|
199
|
+
*/
|
|
27
200
|
onAttach(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Lifecycle hook: removes this collider from the {@link World}
|
|
203
|
+
* when the behaviour is detached.
|
|
204
|
+
*
|
|
205
|
+
* @see {@link Behaviour.onDetach}
|
|
206
|
+
*/
|
|
28
207
|
onDetach(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Returns the {@link Entity} that owns this behaviour.
|
|
210
|
+
*
|
|
211
|
+
* Used by the {@link World} to read and mutate entity position
|
|
212
|
+
* during overlap resolution.
|
|
213
|
+
*
|
|
214
|
+
* @returns The owning entity.
|
|
215
|
+
*/
|
|
29
216
|
getOwner(): Entity;
|
|
217
|
+
/**
|
|
218
|
+
* Computes this collider's axis-aligned bounding rectangle in
|
|
219
|
+
* world-space, accounting for the shape's optional offset.
|
|
220
|
+
*
|
|
221
|
+
* @returns A {@link WorldBounds} rectangle.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const bounds = collidable.getWorldBounds();
|
|
226
|
+
* // { x: 100, y: 200, width: 30, height: 30 }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
30
229
|
getWorldBounds(): WorldBounds;
|
|
31
230
|
}
|
|
32
231
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collidable.d.ts","sourceRoot":"","sources":["../../../core/behaviours/collidable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"collidable.d.ts","sourceRoot":"","sources":["../../../src/core/behaviours/collidable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,KAAK,iBAAiB,GAAG;IACvB;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAE3B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,UAAW,SAAQ,SAAS,CAAC,UAAU,CAAC;IACnD,kBAAkB;IAClB,QAAQ,CAAC,IAAI,gBAAgB;IAE7B;;;;OAIG;IACI,KAAK,EAAE,aAAa,CAAC;IAE5B;;;;;OAKG;IACI,KAAK,EAAE,MAAM,CAAK;IAEzB;;;;OAIG;IACI,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAErC;;;;OAIG;IACI,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAE7C;;;;OAIG;IACI,KAAK,EAAE,OAAO,CAAS;IAE9B;;;;OAIG;IACI,KAAK,EAAE,OAAO,CAAS;IAE9B;;;OAGG;IACI,WAAW,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IAElD,uEAAuE;IACvE,OAAO,CAAC,KAAK,CAAQ;IAErB;;;;;;;OAOG;gBACS,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB;IAoBvE;;;;OAIG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAEhC;;;;;OAKG;IACM,QAAQ,IAAI,IAAI;IAIzB;;;;;OAKG;IACM,QAAQ,IAAI,IAAI;IAIzB;;;;;;;OAOG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;;;;;;;;OAWG;IACH,cAAc,IAAI,WAAW;CAqB9B"}
|
|
@@ -1,11 +1,59 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Entity from "../../entities/entity";
|
|
2
2
|
import { Behaviour } from "../behaviour";
|
|
3
3
|
import type Input from "../input";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Keyboard-driven movement behaviour for a {@link Entity}.
|
|
6
|
+
*
|
|
7
|
+
* `Control` reads the current keyboard state from an {@link Input}
|
|
8
|
+
* instance every frame and translates WASD / arrow-key presses into
|
|
9
|
+
* entity position changes. Diagonal movement is normalised so the
|
|
10
|
+
* entity moves at a consistent speed in all directions.
|
|
11
|
+
*
|
|
12
|
+
* @category Behaviours
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*
|
|
15
|
+
* @example Attaching to a player
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Control, Input, Player } from "gamefoo";
|
|
18
|
+
*
|
|
19
|
+
* const input = new Input();
|
|
20
|
+
* const player = new Player("hero", 400, 300, 50, 50);
|
|
21
|
+
*
|
|
22
|
+
* player.attachBehaviour(new Control(player, input));
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @see {@link Input} — the polling input manager consumed by this behaviour
|
|
26
|
+
* @see {@link Behaviour} — abstract base class
|
|
27
|
+
*/
|
|
28
|
+
export declare class Control extends Behaviour<Entity> {
|
|
29
|
+
/** @inheritDoc */
|
|
5
30
|
readonly type = "control";
|
|
31
|
+
/** The input manager to poll each frame. */
|
|
6
32
|
private input;
|
|
33
|
+
/**
|
|
34
|
+
* Movement speed in pixels per second.
|
|
35
|
+
*
|
|
36
|
+
* @defaultValue `500`
|
|
37
|
+
*/
|
|
7
38
|
private speed;
|
|
8
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new keyboard control behaviour.
|
|
41
|
+
*
|
|
42
|
+
* @param owner - The game object entity whose position will be updated.
|
|
43
|
+
* @param input - The {@link Input} instance to read key state from.
|
|
44
|
+
*/
|
|
45
|
+
constructor(owner: Entity, input: Input);
|
|
46
|
+
/**
|
|
47
|
+
* Reads the current key state and moves the owner entity.
|
|
48
|
+
*
|
|
49
|
+
* Supported keys: `W` / `ArrowUp`, `S` / `ArrowDown`,
|
|
50
|
+
* `A` / `ArrowLeft`, `D` / `ArrowRight`.
|
|
51
|
+
*
|
|
52
|
+
* Diagonal input is normalised so the effective speed remains
|
|
53
|
+
* constant regardless of direction.
|
|
54
|
+
*
|
|
55
|
+
* @param deltaTime - Seconds elapsed since the previous frame.
|
|
56
|
+
*/
|
|
9
57
|
update(deltaTime: number): void;
|
|
10
58
|
}
|
|
11
59
|
//# sourceMappingURL=control.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../../core/behaviours/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../../src/core/behaviours/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,OAAQ,SAAQ,SAAS,CAAC,MAAM,CAAC;IAC5C,kBAAkB;IAClB,QAAQ,CAAC,IAAI,aAAa;IAE1B,4CAA4C;IAC5C,OAAO,CAAC,KAAK,CAAQ;IAErB;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAAe;IAE5B;;;;;OAKG;gBACS,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAKvC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAehC"}
|