@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.
Files changed (75) hide show
  1. package/dist/core/animate.d.ts +129 -0
  2. package/dist/core/animate.d.ts.map +1 -0
  3. package/dist/core/asset.d.ts +59 -0
  4. package/dist/core/asset.d.ts.map +1 -0
  5. package/dist/core/behaviour.d.ts +118 -0
  6. package/dist/core/behaviour.d.ts.map +1 -1
  7. package/dist/core/behaviours/collidable.d.ts +203 -4
  8. package/dist/core/behaviours/collidable.d.ts.map +1 -1
  9. package/dist/core/behaviours/control.d.ts +51 -3
  10. package/dist/core/behaviours/control.d.ts.map +1 -1
  11. package/dist/core/behaviours/healtkit.d.ts +120 -3
  12. package/dist/core/behaviours/healtkit.d.ts.map +1 -1
  13. package/dist/core/behaviours/sprite_render.d.ts +141 -0
  14. package/dist/core/behaviours/sprite_render.d.ts.map +1 -0
  15. package/dist/core/camera.d.ts +101 -0
  16. package/dist/core/camera.d.ts.map +1 -1
  17. package/dist/core/engine.d.ts +377 -15
  18. package/dist/core/engine.d.ts.map +1 -1
  19. package/dist/core/fonts/font_bitmap.d.ts +156 -0
  20. package/dist/core/fonts/font_bitmap.d.ts.map +1 -0
  21. package/dist/core/fonts/font_bitmap_prebuild.d.ts +102 -0
  22. package/dist/core/fonts/font_bitmap_prebuild.d.ts.map +1 -0
  23. package/dist/core/fonts/internal/font_3x5.d.ts +76 -0
  24. package/dist/core/fonts/internal/font_3x5.d.ts.map +1 -0
  25. package/dist/core/fonts/internal/font_4x6.d.ts +76 -0
  26. package/dist/core/fonts/internal/font_4x6.d.ts.map +1 -0
  27. package/dist/core/fonts/internal/font_5x5.d.ts +79 -0
  28. package/dist/core/fonts/internal/font_5x5.d.ts.map +1 -0
  29. package/dist/core/fonts/internal/font_6x8.d.ts +76 -0
  30. package/dist/core/fonts/internal/font_6x8.d.ts.map +1 -0
  31. package/dist/core/fonts/internal/font_8x13.d.ts +76 -0
  32. package/dist/core/fonts/internal/font_8x13.d.ts.map +1 -0
  33. package/dist/core/fonts/internal/font_8x8.d.ts +76 -0
  34. package/dist/core/fonts/internal/font_8x8.d.ts.map +1 -0
  35. package/dist/core/game_object_register.d.ts +101 -1
  36. package/dist/core/game_object_register.d.ts.map +1 -1
  37. package/dist/core/input.d.ts +131 -0
  38. package/dist/core/input.d.ts.map +1 -1
  39. package/dist/core/sprite.d.ts +232 -0
  40. package/dist/core/sprite.d.ts.map +1 -0
  41. package/dist/core/utils/perlin_noise.d.ts +136 -0
  42. package/dist/core/utils/perlin_noise.d.ts.map +1 -0
  43. package/dist/core/world.d.ts +147 -0
  44. package/dist/core/world.d.ts.map +1 -1
  45. package/dist/debug/monitor.d.ts +12 -0
  46. package/dist/debug/monitor.d.ts.map +1 -0
  47. package/dist/decorators/index.d.ts +2 -0
  48. package/dist/decorators/index.d.ts.map +1 -0
  49. package/dist/decorators/log.d.ts +33 -0
  50. package/dist/decorators/log.d.ts.map +1 -0
  51. package/dist/entities/dynamic_entity.d.ts +82 -0
  52. package/dist/entities/dynamic_entity.d.ts.map +1 -1
  53. package/dist/entities/entity.d.ts +216 -11
  54. package/dist/entities/entity.d.ts.map +1 -1
  55. package/dist/entities/player.d.ts +76 -0
  56. package/dist/entities/player.d.ts.map +1 -1
  57. package/dist/entities/text.d.ts +52 -0
  58. package/dist/entities/text.d.ts.map +1 -0
  59. package/dist/index.d.ts +29 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +23 -604
  62. package/dist/index.js.map +3 -15
  63. package/dist/subsystems/camera_system.d.ts +25 -0
  64. package/dist/subsystems/camera_system.d.ts.map +1 -0
  65. package/dist/subsystems/collision_system.d.ts +16 -0
  66. package/dist/subsystems/collision_system.d.ts.map +1 -0
  67. package/dist/subsystems/monitor_system.d.ts +17 -0
  68. package/dist/subsystems/monitor_system.d.ts.map +1 -0
  69. package/dist/subsystems/object_system.d.ts +18 -0
  70. package/dist/subsystems/object_system.d.ts.map +1 -0
  71. package/dist/subsystems/types.d.ts +40 -0
  72. package/dist/subsystems/types.d.ts.map +1 -0
  73. package/dist/types.d.ts +140 -0
  74. package/dist/types.d.ts.map +1 -1
  75. package/package.json +25 -11
@@ -0,0 +1,12 @@
1
+ export default class Monitor {
2
+ private fps;
3
+ private timer;
4
+ private frameCount;
5
+ private memory;
6
+ private frames;
7
+ x: number;
8
+ y: number;
9
+ update(delta: number): void;
10
+ render(ctx: CanvasRenderingContext2D): void;
11
+ }
12
+ //# sourceMappingURL=monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../src/debug/monitor.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,MAAM,CAAa;IAE3B,OAAO,CAAC,MAAM,CAAiB;IAExB,CAAC,EAAE,MAAM,CAAK;IACd,CAAC,EAAE,MAAM,CAAK;IAErB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAqB3B,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;CAuB5C"}
@@ -0,0 +1,2 @@
1
+ export * from "./log";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A method decorator that logs the method name, arguments, and return value.
3
+ *
4
+ * Uses the legacy (experimental) decorator protocol for compatibility with
5
+ * Bun's browser bundler.
6
+ *
7
+ * @category Decorators
8
+ * @since 0.2.0
9
+ *
10
+ * @param target - The prototype of the class (instance method) or the constructor (static method).
11
+ * @param propertyKey - The name of the decorated method.
12
+ * @param descriptor - The property descriptor for the method.
13
+ *
14
+ * @returns The modified property descriptor with logging behaviour.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * class Example {
19
+ * @log
20
+ * myMethod(arg1: string, arg2: number) {
21
+ * return `${arg1} - ${arg2}`;
22
+ * }
23
+ * }
24
+ *
25
+ * const example = new Example();
26
+ * example.myMethod('test', 42);
27
+ * Output:
28
+ * ▶ myMethod(["test", 42])
29
+ * ◀ myMethod → "test - 42"
30
+ * ```
31
+ */
32
+ export declare function log(target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor;
33
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/decorators/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,kBAAkB,CAapH"}
@@ -1,11 +1,93 @@
1
1
  import type { Vector2 } from "../types";
2
2
  import Entity from "./entity";
3
+ /**
4
+ * Abstract entity with built-in velocity and speed, suitable for any
5
+ * game object that moves (players, NPCs, projectiles, etc.).
6
+ *
7
+ * `DynamicEntity` extends {@link Entity} with a {@link Vector2}
8
+ * velocity and a scalar speed, plus getter/setter pairs for each.
9
+ * Subclasses are responsible for applying the velocity to position
10
+ * inside their {@link Entity.update | update} implementation.
11
+ *
12
+ * @category Entities
13
+ * @since 0.1.0
14
+ *
15
+ * @example Subclassing
16
+ * ```ts
17
+ * import { DynamicEntity } from "gamefoo";
18
+ *
19
+ * class Bullet extends DynamicEntity {
20
+ * constructor(x: number, y: number) {
21
+ * super("bullet", x, y, 4, 4);
22
+ * this.setSpeed(600);
23
+ * this.setVelocity({ x: 1, y: 0 });
24
+ * }
25
+ *
26
+ * update(dt: number) {
27
+ * this.x += this.velocity.x * this.speed * dt;
28
+ * this.y += this.velocity.y * this.speed * dt;
29
+ * }
30
+ *
31
+ * render(ctx: CanvasRenderingContext2D) {
32
+ * ctx.fillStyle = "#ff0";
33
+ * ctx.fillRect(this.x, this.y, 4, 4);
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @see {@link Entity} — parent class (identity, transform, behaviours)
39
+ * @see {@link Player} — concrete dynamic entity for the player
40
+ */
3
41
  export default abstract class DynamicEntity extends Entity {
42
+ /**
43
+ * Directional velocity vector.
44
+ *
45
+ * Represents the normalised (or raw) direction of movement. Multiply
46
+ * by {@link DynamicEntity.speed | speed} and `deltaTime` to get the
47
+ * per-frame displacement.
48
+ *
49
+ * @defaultValue `{ x: 0, y: 0 }`
50
+ */
4
51
  protected velocity: Vector2;
52
+ /**
53
+ * Scalar movement speed in pixels per second.
54
+ *
55
+ * @defaultValue `0`
56
+ */
5
57
  protected speed: number;
58
+ /**
59
+ * Replaces the current velocity vector.
60
+ *
61
+ * @param velocity - The new velocity.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * entity.setVelocity({ x: -1, y: 0 }); // moving left
66
+ * ```
67
+ */
6
68
  setVelocity(velocity: Vector2): void;
69
+ /**
70
+ * Returns a **copy** of the current velocity vector.
71
+ *
72
+ * @returns A new {@link Vector2}.
73
+ */
7
74
  getVelocity(): Vector2;
75
+ /**
76
+ * Sets the scalar movement speed.
77
+ *
78
+ * @param speed - Speed in pixels per second.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * entity.setSpeed(200);
83
+ * ```
84
+ */
8
85
  setSpeed(speed: number): void;
86
+ /**
87
+ * Returns the current movement speed.
88
+ *
89
+ * @returns Speed in pixels per second.
90
+ */
9
91
  getSpeed(): number;
10
92
  }
11
93
  //# sourceMappingURL=dynamic_entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic_entity.d.ts","sourceRoot":"","sources":["../../entities/dynamic_entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,aAAc,SAAQ,MAAM;IACxD,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAkB;IAC7C,SAAS,CAAC,KAAK,EAAE,MAAM,CAAK;IAE5B,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAIpC,WAAW,IAAI,OAAO;IAItB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"dynamic_entity.d.ts","sourceRoot":"","sources":["../../src/entities/dynamic_entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,aAAc,SAAQ,MAAM;IACxD;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAkB;IAE7C;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,CAAK;IAE5B;;;;;;;;;OASG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAIpC;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B;;;;OAIG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -1,33 +1,238 @@
1
1
  import type { Behaviour } from "../core/behaviour";
2
- import type { Vector2 } from "../types";
2
+ import type { Demension, Vector2 } from "../types";
3
+ /**
4
+ * Abstract base class for every game entity in the GameFoo engine.
5
+ *
6
+ * `Entity` provides:
7
+ *
8
+ * - **Identity** — a unique string {@link Entity.id | id}.
9
+ * - **Transform** — a 2-D {@link Entity.position | position} and
10
+ * {@link Entity.size | size} with convenient `x`/`y` accessors.
11
+ * - **Behaviour system** — attach, detach, query, and bulk-update
12
+ * {@link Behaviour} instances that compose an entity's logic.
13
+ *
14
+ * Subclasses must implement {@link Entity.update} and
15
+ * {@link Entity.render}.
16
+ *
17
+ * @category Entities
18
+ * @since 0.1.0
19
+ *
20
+ * @example Subclassing
21
+ * ```ts
22
+ * import { Entity } from "gamefoo";
23
+ *
24
+ * class Wall extends Entity {
25
+ * constructor(x: number, y: number, w: number, h: number) {
26
+ * super("wall", x, y, w, h);
27
+ * }
28
+ *
29
+ * update(_dt: number) {}
30
+ *
31
+ * render(ctx: CanvasRenderingContext2D) {
32
+ * ctx.fillStyle = "#888";
33
+ * ctx.fillRect(this.x, this.y, this.size.width, this.size.height);
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @example Attaching behaviours
39
+ * ```ts
40
+ * const entity = new Wall(0, 0, 100, 20);
41
+ * entity.attachBehaviour(new Collidable(entity, world, { ... }));
42
+ *
43
+ * if (entity.hasBehaviour("collidable")) {
44
+ * console.log("Wall has collision!");
45
+ * }
46
+ * ```
47
+ *
48
+ * @see {@link DynamicEntity} — extends Entity with velocity / speed
49
+ * @see {@link Player} — concrete player entity
50
+ * @see {@link Behaviour} — composable logic units
51
+ */
3
52
  export default abstract class Entity {
53
+ /**
54
+ * Unique identifier for this entity.
55
+ *
56
+ * Used as the key in {@link GameObjectRegister} and for
57
+ * collision-callback identification.
58
+ */
4
59
  id: string;
5
- protected position: Vector2;
6
- protected size: {
7
- width: number;
8
- height: number;
9
- };
60
+ /**
61
+ * World-space position of the entity's origin (top-left corner).
62
+ */
63
+ protected readonly position: Vector2;
64
+ /**
65
+ * Bounding dimensions of the entity in pixels.
66
+ */
67
+ protected readonly size: Demension;
68
+ /**
69
+ * Internal map from behaviour key (lowercased type) to
70
+ * {@link Behaviour} instance.
71
+ */
10
72
  private behaviorMap;
73
+ /**
74
+ * Priority-sorted cache of behaviours. Invalidated (`null`) whenever
75
+ * a behaviour is attached or detached.
76
+ */
11
77
  private _sortedBehaviors;
78
+ /**
79
+ * Horizontal position of the entity (shorthand for
80
+ * `position.x`).
81
+ */
12
82
  get x(): number;
83
+ /** Sets the horizontal position. */
13
84
  set x(value: number);
85
+ /**
86
+ * Vertical position of the entity (shorthand for
87
+ * `position.y`).
88
+ */
14
89
  get y(): number;
90
+ /** Sets the vertical position. */
15
91
  set y(value: number);
16
- constructor(id: string, x: number, y: number, width: number, height: number);
92
+ /**
93
+ * Creates a new entity.
94
+ *
95
+ * @param id - Unique string identifier.
96
+ * @param x - Initial X position in pixels.
97
+ * @param y - Initial Y position in pixels.
98
+ * @param width - Width of the entity's bounding box in pixels.
99
+ * @param height - Height of the entity's bounding box in pixels.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * class Crate extends Entity {
104
+ * constructor(x: number, y: number) {
105
+ * super("crate", x, y, 32, 32);
106
+ * }
107
+ * // ...
108
+ * }
109
+ * ```
110
+ */
111
+ constructor(id: string, x: number, y: number, width?: number, height?: number);
112
+ /**
113
+ * Advances the entity's state by one frame.
114
+ *
115
+ * @param deltaTime - Seconds elapsed since the previous frame.
116
+ */
17
117
  abstract update(deltaTime: number): void;
118
+ /**
119
+ * Draws the entity to the canvas.
120
+ *
121
+ * @param ctx - The 2-D rendering context.
122
+ */
18
123
  abstract render(ctx: CanvasRenderingContext2D): void;
124
+ /**
125
+ * Returns a **copy** of the entity's current position.
126
+ *
127
+ * @returns A new {@link Vector2} with the entity's `x` and `y`.
128
+ */
19
129
  getPosition(): Vector2;
20
- getSize(): {
21
- width: number;
22
- height: number;
23
- };
130
+ /**
131
+ * Returns a **copy** of the entity's bounding dimensions.
132
+ *
133
+ * @returns An object with `width` and `height`.
134
+ */
135
+ getSize(): Demension;
136
+ /**
137
+ * Set size of the entity
138
+ *
139
+ * @since 0.2.0
140
+ *
141
+ * @return void
142
+ */
143
+ setSize(width: number, height: number): void;
144
+ /**
145
+ * Retrieves a behaviour by its key (case-insensitive).
146
+ *
147
+ * @typeParam T - The expected concrete behaviour type.
148
+ * @param key - The behaviour's {@link Behaviour.type | type} string.
149
+ * @returns The behaviour cast to `T`, or `undefined` if not found.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const ctrl = entity.getBehaviour<Control>("control");
154
+ * if (ctrl) ctrl.enabled = false;
155
+ * ```
156
+ */
24
157
  getBehaviour<T extends Behaviour>(key: string): T | undefined;
158
+ /**
159
+ * Returns all attached behaviours that are instances of the given
160
+ * class.
161
+ *
162
+ * @typeParam T - The behaviour subclass to filter by.
163
+ * @param type - The constructor function to test with `instanceof`.
164
+ * @returns An array of matching behaviours.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const renderers = entity.getBehavioursByType(SpriteRender);
169
+ * ```
170
+ */
25
171
  getBehavioursByType<T extends Behaviour>(type: new (...args: any[]) => T): T[];
172
+ /**
173
+ * Checks whether a behaviour with the given key is attached.
174
+ *
175
+ * @param key - The behaviour's {@link Behaviour.type | type} string
176
+ * (case-insensitive).
177
+ * @returns `true` if the behaviour exists on this entity.
178
+ */
26
179
  hasBehaviour(key: string): boolean;
180
+ /**
181
+ * Attaches a behaviour to this entity.
182
+ *
183
+ * If the behaviour defines an {@link Behaviour.onAttach | onAttach}
184
+ * hook, it is called immediately. The sorted-behaviour cache is
185
+ * invalidated.
186
+ *
187
+ * @typeParam T - The behaviour type being attached.
188
+ * @param behavior - The behaviour instance to add.
189
+ * @returns The same behaviour instance (for chaining).
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * const hk = entity.attachBehaviour(new HealthKit(entity, 100));
194
+ * hk.takeDamage(10);
195
+ * ```
196
+ */
27
197
  attachBehaviour<T extends Behaviour>(behavior: T): T;
198
+ /**
199
+ * Detaches a behaviour by its key and calls
200
+ * {@link Behaviour.onDetach | onDetach} if defined.
201
+ *
202
+ * @param key - The behaviour's {@link Behaviour.type | type} string
203
+ * (case-insensitive).
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * entity.detachBehaviour("collidable");
208
+ * ```
209
+ */
28
210
  detachBehaviour(key: string): void;
211
+ /**
212
+ * Returns all attached behaviours sorted by
213
+ * {@link Behaviour.priority} (ascending). The result is cached and
214
+ * only re-computed when behaviours are added or removed.
215
+ *
216
+ * @internal
217
+ */
29
218
  private get behaviors();
219
+ /**
220
+ * Calls {@link Behaviour.update | update(deltaTime)} on every
221
+ * enabled behaviour, in priority order.
222
+ *
223
+ * Typically called from a subclass's `update` implementation.
224
+ *
225
+ * @param deltaTime - Seconds elapsed since the previous frame.
226
+ */
30
227
  protected updateBehaviours(deltaTime: number): void;
228
+ /**
229
+ * Calls {@link Behaviour.render | render(ctx)} on every enabled
230
+ * behaviour that defines a render method, in priority order.
231
+ *
232
+ * Typically called from a subclass's `render` implementation.
233
+ *
234
+ * @param ctx - The canvas 2-D rendering context.
235
+ */
31
236
  protected renderBehaviours(ctx: CanvasRenderingContext2D): void;
32
237
  }
33
238
  //# sourceMappingURL=entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,MAAM;IAC3B,EAAE,EAAE,MAAM,CAAM;IACvB,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAkB;IAC7C,SAAS,CAAC,IAAI;;;MAA2B;IAEzC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,gBAAgB,CAA4B;IAEpD,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAElB;IAED,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAElB;gBAEW,EAAE,EAAE,MAAM,EA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H,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIlC;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAUpD;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAWlC;;;;;;OAMG;IACH,OAAO,KAAK,SAAS,GAKpB;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAQnD;;;;;;;OAOG;IACH,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;CAOhE"}
@@ -1,10 +1,86 @@
1
1
  import type { Control } from "../core/behaviours/control";
2
2
  import type { HealthKit } from "../core/behaviours/healtkit";
3
3
  import DynamicEntity from "./dynamic_entity";
4
+ /**
5
+ * Default player entity with convenience accessors for common
6
+ * behaviours.
7
+ *
8
+ * `Player` extends {@link DynamicEntity} and automatically delegates
9
+ * its {@link Player.update | update} and {@link Player.render | render}
10
+ * calls to all attached {@link Behaviour | behaviours}. It also
11
+ * provides typed getters for the {@link Control} and
12
+ * {@link HealthKit} behaviours so game code can access them without
13
+ * manual casting.
14
+ *
15
+ * Subclass `Player` to customise rendering, add game-specific logic,
16
+ * or bind additional behaviours.
17
+ *
18
+ * @category Entities
19
+ * @since 0.1.0
20
+ *
21
+ * @example Basic usage
22
+ * ```ts
23
+ * import { Player, Control, HealthKit, Input } from "gamefoo";
24
+ *
25
+ * const player = new Player("hero", 400, 300, 50, 50);
26
+ *
27
+ * player.attachBehaviour(new Control(player, new Input()));
28
+ * player.attachBehaviour(new HealthKit(player, 100));
29
+ *
30
+ * player.control?.enabled; // true
31
+ * player.healthkit?.getHealth(); // 100
32
+ * ```
33
+ *
34
+ * @example Subclassing for custom rendering
35
+ * ```ts
36
+ * class Knight extends Player {
37
+ * constructor(x: number, y: number) {
38
+ * super("knight", x, y, 48, 48);
39
+ * }
40
+ *
41
+ * override render(ctx: CanvasRenderingContext2D) {
42
+ * ctx.fillStyle = "#c0c0c0";
43
+ * ctx.fillRect(this.x, this.y, 48, 48);
44
+ * this.renderBehaviours(ctx);
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * @see {@link DynamicEntity} — parent class (velocity, speed)
50
+ * @see {@link Control} — keyboard movement behaviour
51
+ * @see {@link HealthKit} — health-tracking behaviour
52
+ */
4
53
  export default class Player extends DynamicEntity {
54
+ /**
55
+ * Convenience getter for the attached {@link Control} behaviour.
56
+ *
57
+ * @returns The `Control` instance, or `undefined` if not attached.
58
+ */
5
59
  get control(): Control | undefined;
60
+ /**
61
+ * Convenience getter for the attached {@link HealthKit} behaviour.
62
+ *
63
+ * @returns The `HealthKit` instance, or `undefined` if not attached.
64
+ */
6
65
  get healthkit(): HealthKit | undefined;
66
+ /**
67
+ * Advances all attached behaviours.
68
+ *
69
+ * @inheritDoc
70
+ * @param deltaTime - Seconds elapsed since the previous frame.
71
+ */
7
72
  update(deltaTime: number): void;
73
+ /**
74
+ * Draws a default blue rectangle and then renders all attached
75
+ * behaviours (e.g. sprite overlays, health bars).
76
+ *
77
+ * Override this in a subclass for custom visuals.
78
+ *
79
+ * TODO: write a better default player object
80
+ *
81
+ * @inheritDoc
82
+ * @param ctx - The canvas 2-D rendering context.
83
+ */
8
84
  render(ctx: CanvasRenderingContext2D): void;
9
85
  }
10
86
  //# sourceMappingURL=player.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../entities/player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,aAAa;IAC/C,IAAI,OAAO,IAAI,OAAO,GAAG,SAAS,CAEjC;IAED,IAAI,SAAS,IAAI,SAAS,GAAG,SAAS,CAErC;IAED,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI/B,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;CAK5C"}
1
+ {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../src/entities/player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,aAAa;IAC/C;;;;OAIG;IACH,IAAI,OAAO,IAAI,OAAO,GAAG,SAAS,CAEjC;IAED;;;;OAIG;IACH,IAAI,SAAS,IAAI,SAAS,GAAG,SAAS,CAErC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;CAK5C"}
@@ -0,0 +1,52 @@
1
+ import FontBitmap, { type InternalBitmapFontName } from "../core/fonts/font_bitmap";
2
+ import Entity from "./entity";
3
+ /**
4
+ * Abstract base class for Text and Label alike objects
5
+ *
6
+ * `Text` extends {@link Entity} and could also get all behaviors attach to it but
7
+ * most likely there will be no need for that. Its primary design use case is to
8
+ * keep track of text objects and interact with them
9
+ *
10
+ * @category Entities
11
+ * @since 0.2.0
12
+ *
13
+ * @see {@link Entity} - parent class
14
+ */
15
+ export default abstract class Text extends Entity {
16
+ /** Bitmap font name to load internally */
17
+ protected fontName: string;
18
+ /** BitmapFont instance used to manipulate the font */
19
+ protected font: FontBitmap;
20
+ /** Internal state of the text needed to be update */
21
+ protected text: string;
22
+ /**
23
+ * Create new Text object that could be placed and render on the screen
24
+ *
25
+ * @param fontName - the FontBitmap valid name to load
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const Label = new Text('CustomLabel', '5x5');
30
+ * ```
31
+ */
32
+ constructor(id: string, fontName: InternalBitmapFontName);
33
+ /**
34
+ * Set internal state value
35
+ *
36
+ * @param text - any content that should be render
37
+ *
38
+ * @return void
39
+ */
40
+ setText(text: string): void;
41
+ /**
42
+ * Get the internal state of the object
43
+ *
44
+ * @return string
45
+ */
46
+ getText(): string;
47
+ /**
48
+ * Render the text to the canvas using the BitmapFont instance
49
+ */
50
+ render(ctx: CanvasRenderingContext2D): void;
51
+ }
52
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/entities/text.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,IAAK,SAAQ,MAAM;IAC/C,0CAA0C;IAC1C,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE3B,sDAAsD;IACtD,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC;IAE3B,qDAAqD;IACrD,SAAS,CAAC,IAAI,EAAE,MAAM,CAAM;IAE5B;;;;;;;;;OASG;gBACS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAQxD;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAMpB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACM,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,IAAI;CAGrD"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,42 @@
1
+ /**
2
+ * GameFoo — a lightweight 2-D canvas game engine.
3
+ *
4
+ * This barrel module re-exports every public class, behaviour, utility,
5
+ * and type so consumers can import from a single entry point:
6
+ *
7
+ * ```ts
8
+ * import { Engine, Player, Input, Collidable } from "gamefoo";
9
+ * ```
10
+ *
11
+ * @category Core
12
+ * @module gamefoo
13
+ * @since 0.1.0
14
+ */
15
+ export { log } from "@decorators";
16
+ export { default as Asset } from "./core/asset";
1
17
  export { Behaviour } from "./core/behaviour";
2
18
  export { Collidable } from "./core/behaviours/collidable";
3
19
  export { Control } from "./core/behaviours/control";
4
20
  export { HealthKit } from "./core/behaviours/healtkit";
21
+ export { default as SpriteRender } from "./core/behaviours/sprite_render";
5
22
  export { default as Camera } from "./core/camera";
6
23
  export { default as Engine } from "./core/engine";
24
+ export { default as FontBitmap } from "./core/fonts/font_bitmap";
25
+ export { default as FontBitmapPrebuild } from "./core/fonts/font_bitmap_prebuild";
7
26
  export { default as GameObjectRegister } from "./core/game_object_register";
8
27
  export { default as Input } from "./core/input";
28
+ export { default as Sprite } from "./core/sprite";
29
+ export { PerlinNoise } from "./core/utils/perlin_noise";
9
30
  export { default as World } from "./core/world";
31
+ export { default as Monitor } from "./debug/monitor";
10
32
  export { default as DynamicEntity } from "./entities/dynamic_entity";
11
33
  export { default as Entity } from "./entities/entity";
12
34
  export { default as Player } from "./entities/player";
13
- export type { ColliderShape, CollisionInfo, GameObject, Vector2, } from "./types";
35
+ export { default as Text } from "./entities/text";
36
+ export { CameraSystem } from "./subsystems/camera_system";
37
+ export { CollisionSystem } from "./subsystems/collision_system";
38
+ export { MonitorSystem } from "./subsystems/monitor_system";
39
+ export { ObjectSystem } from "./subsystems/object_system";
40
+ export type { SubSystem } from "./subsystems/types";
41
+ export type { ColliderShape, CollisionInfo, Demension, GameObject, Vector2 } from "./types";
14
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE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