@dryanovski/gamefoo 0.2.1 → 0.2.5

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 (84) hide show
  1. package/dist/core/animate.js +147 -0
  2. package/dist/core/asset.js +74 -0
  3. package/dist/core/behaviour.js +88 -0
  4. package/dist/core/behaviours/collidable.js +186 -0
  5. package/dist/core/behaviours/control.js +75 -0
  6. package/dist/core/behaviours/healtkit.js +153 -0
  7. package/dist/core/behaviours/sprite_render.js +193 -0
  8. package/dist/core/camera.js +134 -0
  9. package/dist/core/engine.d.ts +1 -1
  10. package/dist/core/engine.d.ts.map +1 -1
  11. package/dist/core/engine.js +527 -0
  12. package/dist/core/fonts/font_bitmap.js +205 -0
  13. package/dist/core/fonts/font_bitmap_prebuild.js +137 -0
  14. package/dist/core/fonts/internal/font_3x5.js +169 -0
  15. package/dist/core/fonts/internal/font_4x6.js +171 -0
  16. package/dist/core/fonts/internal/font_5x5.js +129 -0
  17. package/dist/core/fonts/internal/font_6x8.js +171 -0
  18. package/dist/core/fonts/internal/font_8x13.js +171 -0
  19. package/dist/core/fonts/internal/font_8x8.js +171 -0
  20. package/dist/core/game_object_register.js +134 -0
  21. package/dist/core/input.js +170 -0
  22. package/dist/core/sprite.js +222 -0
  23. package/dist/core/utils/perlin_noise.js +183 -0
  24. package/dist/core/world.js +304 -0
  25. package/dist/debug/monitor.js +47 -0
  26. package/dist/decorators/index.js +1 -0
  27. package/dist/decorators/log.js +42 -0
  28. package/dist/entities/dynamic_entity.js +99 -0
  29. package/dist/entities/entity.js +283 -0
  30. package/dist/entities/player.js +93 -0
  31. package/dist/entities/text.js +62 -0
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +47 -29
  35. package/dist/subsystems/camera_system.d.ts +2 -2
  36. package/dist/subsystems/camera_system.d.ts.map +1 -1
  37. package/dist/subsystems/camera_system.js +41 -0
  38. package/dist/subsystems/collision_system.js +17 -0
  39. package/dist/subsystems/monitor_system.js +20 -0
  40. package/dist/subsystems/object_system.d.ts +1 -1
  41. package/dist/subsystems/object_system.d.ts.map +1 -1
  42. package/dist/subsystems/object_system.js +29 -0
  43. package/dist/subsystems/types.d.ts +1 -1
  44. package/dist/subsystems/types.d.ts.map +1 -1
  45. package/dist/subsystems/types.js +0 -0
  46. package/dist/types.js +10 -0
  47. package/package.json +17 -6
  48. package/src/core/animate.ts +159 -0
  49. package/src/core/asset.ts +76 -0
  50. package/src/core/behaviour.ts +145 -0
  51. package/src/core/behaviours/collidable.ts +296 -0
  52. package/src/core/behaviours/control.ts +80 -0
  53. package/src/core/behaviours/healtkit.ts +166 -0
  54. package/src/core/behaviours/sprite_render.ts +216 -0
  55. package/src/core/camera.ts +145 -0
  56. package/src/core/engine.ts +607 -0
  57. package/src/core/fonts/font_bitmap.ts +232 -0
  58. package/src/core/fonts/font_bitmap_prebuild.ts +141 -0
  59. package/src/core/fonts/internal/font_3x5.ts +178 -0
  60. package/src/core/fonts/internal/font_4x6.ts +180 -0
  61. package/src/core/fonts/internal/font_5x5.ts +137 -0
  62. package/src/core/fonts/internal/font_6x8.ts +180 -0
  63. package/src/core/fonts/internal/font_8x13.ts +180 -0
  64. package/src/core/fonts/internal/font_8x8.ts +180 -0
  65. package/src/core/game_object_register.ts +146 -0
  66. package/src/core/input.ts +182 -0
  67. package/src/core/sprite.ts +339 -0
  68. package/src/core/utils/perlin_noise.ts +196 -0
  69. package/src/core/world.ts +331 -0
  70. package/src/debug/monitor.ts +60 -0
  71. package/src/decorators/index.ts +1 -0
  72. package/src/decorators/log.ts +45 -0
  73. package/src/entities/dynamic_entity.ts +106 -0
  74. package/src/entities/entity.ts +322 -0
  75. package/src/entities/player.ts +99 -0
  76. package/src/entities/text.ts +72 -0
  77. package/src/index.ts +51 -0
  78. package/src/subsystems/camera_system.ts +52 -0
  79. package/src/subsystems/collision_system.ts +21 -0
  80. package/src/subsystems/monitor_system.ts +26 -0
  81. package/src/subsystems/object_system.ts +37 -0
  82. package/src/subsystems/types.ts +46 -0
  83. package/src/types.ts +178 -0
  84. package/dist/index.js.map +0 -9
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Abstract base class for every game entity in the GameFoo engine.
3
+ *
4
+ * `Entity` provides:
5
+ *
6
+ * - **Identity** — a unique string {@link Entity.id | id}.
7
+ * - **Transform** — a 2-D {@link Entity.position | position} and
8
+ * {@link Entity.size | size} with convenient `x`/`y` accessors.
9
+ * - **Behaviour system** — attach, detach, query, and bulk-update
10
+ * {@link Behaviour} instances that compose an entity's logic.
11
+ *
12
+ * Subclasses must implement {@link Entity.update} and
13
+ * {@link Entity.render}.
14
+ *
15
+ * @category Entities
16
+ * @since 0.1.0
17
+ *
18
+ * @example Subclassing
19
+ * ```ts
20
+ * import { Entity } from "gamefoo";
21
+ *
22
+ * class Wall extends Entity {
23
+ * constructor(x: number, y: number, w: number, h: number) {
24
+ * super("wall", x, y, w, h);
25
+ * }
26
+ *
27
+ * update(_dt: number) {}
28
+ *
29
+ * render(ctx: CanvasRenderingContext2D) {
30
+ * ctx.fillStyle = "#888";
31
+ * ctx.fillRect(this.x, this.y, this.size.width, this.size.height);
32
+ * }
33
+ * }
34
+ * ```
35
+ *
36
+ * @example Attaching behaviours
37
+ * ```ts
38
+ * const entity = new Wall(0, 0, 100, 20);
39
+ * entity.attachBehaviour(new Collidable(entity, world, { ... }));
40
+ *
41
+ * if (entity.hasBehaviour("collidable")) {
42
+ * console.log("Wall has collision!");
43
+ * }
44
+ * ```
45
+ *
46
+ * @see {@link DynamicEntity} — extends Entity with velocity / speed
47
+ * @see {@link Player} — concrete player entity
48
+ * @see {@link Behaviour} — composable logic units
49
+ */
50
+ export default class Entity {
51
+ /**
52
+ * Unique identifier for this entity.
53
+ *
54
+ * Used as the key in {@link GameObjectRegister} and for
55
+ * collision-callback identification.
56
+ */
57
+ id = "";
58
+ /**
59
+ * World-space position of the entity's origin (top-left corner).
60
+ */
61
+ position = { x: 0, y: 0 };
62
+ /**
63
+ * Bounding dimensions of the entity in pixels.
64
+ */
65
+ size = { width: 0, height: 0 };
66
+ /**
67
+ * Internal map from behaviour key (lowercased type) to
68
+ * {@link Behaviour} instance.
69
+ */
70
+ behaviorMap = new Map();
71
+ /**
72
+ * Priority-sorted cache of behaviours. Invalidated (`null`) whenever
73
+ * a behaviour is attached or detached.
74
+ */
75
+ _sortedBehaviors = null;
76
+ /**
77
+ * Horizontal position of the entity (shorthand for
78
+ * `position.x`).
79
+ */
80
+ get x() {
81
+ return this.position.x;
82
+ }
83
+ /** Sets the horizontal position. */
84
+ set x(value) {
85
+ this.position.x = value;
86
+ }
87
+ /**
88
+ * Vertical position of the entity (shorthand for
89
+ * `position.y`).
90
+ */
91
+ get y() {
92
+ return this.position.y;
93
+ }
94
+ /** Sets the vertical position. */
95
+ set y(value) {
96
+ this.position.y = value;
97
+ }
98
+ /**
99
+ * Creates a new entity.
100
+ *
101
+ * @param id - Unique string identifier.
102
+ * @param x - Initial X position in pixels.
103
+ * @param y - Initial Y position in pixels.
104
+ * @param width - Width of the entity's bounding box in pixels.
105
+ * @param height - Height of the entity's bounding box in pixels.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * class Crate extends Entity {
110
+ * constructor(x: number, y: number) {
111
+ * super("crate", x, y, 32, 32);
112
+ * }
113
+ * // ...
114
+ * }
115
+ * ```
116
+ */
117
+ constructor(id, x, y, width, height) {
118
+ this.id = id;
119
+ this.position = { x, y };
120
+ if (width && height) {
121
+ this.size = { width, height };
122
+ }
123
+ }
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
+ */
129
+ getPosition() {
130
+ return this.position;
131
+ }
132
+ /**
133
+ * Returns a **copy** of the entity's bounding dimensions.
134
+ *
135
+ * @returns An object with `width` and `height`.
136
+ */
137
+ getSize() {
138
+ return this.size;
139
+ }
140
+ /**
141
+ * Set size of the entity
142
+ *
143
+ * @since 0.2.0
144
+ *
145
+ * @return void
146
+ */
147
+ setSize(width, height) {
148
+ this.size.width = width;
149
+ this.size.height = height;
150
+ }
151
+ /**
152
+ * Retrieves a behaviour by its key (case-insensitive).
153
+ *
154
+ * @typeParam T - The expected concrete behaviour type.
155
+ * @param key - The behaviour's {@link Behaviour.type | type} string.
156
+ * @returns The behaviour cast to `T`, or `undefined` if not found.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * const ctrl = entity.getBehaviour<Control>("control");
161
+ * if (ctrl) ctrl.enabled = false;
162
+ * ```
163
+ */
164
+ getBehaviour(key) {
165
+ return this.behaviorMap.get(key.toLowerCase());
166
+ }
167
+ /**
168
+ * Returns all attached behaviours that are instances of the given
169
+ * class.
170
+ *
171
+ * @typeParam T - The behaviour subclass to filter by.
172
+ * @param type - The constructor function to test with `instanceof`.
173
+ * @returns An array of matching behaviours.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const renderers = entity.getBehavioursByType(SpriteRender);
178
+ * ```
179
+ */
180
+ getBehavioursByType(type) {
181
+ return this.behaviors.filter((b) => b instanceof type);
182
+ }
183
+ /**
184
+ * Checks whether a behaviour with the given key is attached.
185
+ *
186
+ * @param key - The behaviour's {@link Behaviour.type | type} string
187
+ * (case-insensitive).
188
+ * @returns `true` if the behaviour exists on this entity.
189
+ */
190
+ hasBehaviour(key) {
191
+ return this.behaviorMap.has(key.toLowerCase());
192
+ }
193
+ /**
194
+ * Attaches a behaviour to this entity.
195
+ *
196
+ * If the behaviour defines an {@link Behaviour.onAttach | onAttach}
197
+ * hook, it is called immediately. The sorted-behaviour cache is
198
+ * invalidated.
199
+ *
200
+ * @typeParam T - The behaviour type being attached.
201
+ * @param behavior - The behaviour instance to add.
202
+ * @returns The same behaviour instance (for chaining).
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const hk = entity.attachBehaviour(new HealthKit(entity, 100));
207
+ * hk.takeDamage(10);
208
+ * ```
209
+ */
210
+ attachBehaviour(behavior) {
211
+ this.behaviorMap.set(behavior.key, behavior);
212
+ this._sortedBehaviors = null;
213
+ if (behavior.onAttach) {
214
+ behavior.onAttach();
215
+ }
216
+ return behavior;
217
+ }
218
+ /**
219
+ * Detaches a behaviour by its key and calls
220
+ * {@link Behaviour.onDetach | onDetach} if defined.
221
+ *
222
+ * @param key - The behaviour's {@link Behaviour.type | type} string
223
+ * (case-insensitive).
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * entity.detachBehaviour("collidable");
228
+ * ```
229
+ */
230
+ detachBehaviour(key) {
231
+ const behavior = this.behaviorMap.get(key.toLowerCase());
232
+ if (!behavior)
233
+ return;
234
+ if (behavior.onDetach) {
235
+ behavior.onDetach();
236
+ }
237
+ this.behaviorMap.delete(key.toLowerCase());
238
+ this._sortedBehaviors = null;
239
+ }
240
+ /**
241
+ * Returns all attached behaviours sorted by
242
+ * {@link Behaviour.priority} (ascending). The result is cached and
243
+ * only re-computed when behaviours are added or removed.
244
+ *
245
+ * @internal
246
+ */
247
+ get behaviors() {
248
+ if (!this._sortedBehaviors) {
249
+ this._sortedBehaviors = Array.from(this.behaviorMap.values()).sort((a, b) => a.priority - b.priority);
250
+ }
251
+ return this._sortedBehaviors;
252
+ }
253
+ /**
254
+ * Calls {@link Behaviour.update | update(deltaTime)} on every
255
+ * enabled behaviour, in priority order.
256
+ *
257
+ * Typically called from a subclass's `update` implementation.
258
+ *
259
+ * @param deltaTime - Seconds elapsed since the previous frame.
260
+ */
261
+ updateBehaviours(deltaTime) {
262
+ for (const behavior of this.behaviors) {
263
+ if (behavior.enabled) {
264
+ behavior.update(deltaTime);
265
+ }
266
+ }
267
+ }
268
+ /**
269
+ * Calls {@link Behaviour.render | render(ctx)} on every enabled
270
+ * behaviour that defines a render method, in priority order.
271
+ *
272
+ * Typically called from a subclass's `render` implementation.
273
+ *
274
+ * @param ctx - The canvas 2-D rendering context.
275
+ */
276
+ renderBehaviours(ctx) {
277
+ for (const behavior of this.behaviors) {
278
+ if (behavior.enabled && behavior.render) {
279
+ behavior.render(ctx);
280
+ }
281
+ }
282
+ }
283
+ }
@@ -0,0 +1,93 @@
1
+ import DynamicEntity from "./dynamic_entity";
2
+ /**
3
+ * Default player entity with convenience accessors for common
4
+ * behaviours.
5
+ *
6
+ * `Player` extends {@link DynamicEntity} and automatically delegates
7
+ * its {@link Player.update | update} and {@link Player.render | render}
8
+ * calls to all attached {@link Behaviour | behaviours}. It also
9
+ * provides typed getters for the {@link Control} and
10
+ * {@link HealthKit} behaviours so game code can access them without
11
+ * manual casting.
12
+ *
13
+ * Subclass `Player` to customise rendering, add game-specific logic,
14
+ * or bind additional behaviours.
15
+ *
16
+ * @category Entities
17
+ * @since 0.1.0
18
+ *
19
+ * @example Basic usage
20
+ * ```ts
21
+ * import { Player, Control, HealthKit, Input } from "gamefoo";
22
+ *
23
+ * const player = new Player("hero", 400, 300, 50, 50);
24
+ *
25
+ * player.attachBehaviour(new Control(player, new Input()));
26
+ * player.attachBehaviour(new HealthKit(player, 100));
27
+ *
28
+ * player.control?.enabled; // true
29
+ * player.healthkit?.getHealth(); // 100
30
+ * ```
31
+ *
32
+ * @example Subclassing for custom rendering
33
+ * ```ts
34
+ * class Knight extends Player {
35
+ * constructor(x: number, y: number) {
36
+ * super("knight", x, y, 48, 48);
37
+ * }
38
+ *
39
+ * override render(ctx: CanvasRenderingContext2D) {
40
+ * ctx.fillStyle = "#c0c0c0";
41
+ * ctx.fillRect(this.x, this.y, 48, 48);
42
+ * this.renderBehaviours(ctx);
43
+ * }
44
+ * }
45
+ * ```
46
+ *
47
+ * @see {@link DynamicEntity} — parent class (velocity, speed)
48
+ * @see {@link Control} — keyboard movement behaviour
49
+ * @see {@link HealthKit} — health-tracking behaviour
50
+ */
51
+ export default class Player extends DynamicEntity {
52
+ /**
53
+ * Convenience getter for the attached {@link Control} behaviour.
54
+ *
55
+ * @returns The `Control` instance, or `undefined` if not attached.
56
+ */
57
+ get control() {
58
+ return this.getBehaviour("control");
59
+ }
60
+ /**
61
+ * Convenience getter for the attached {@link HealthKit} behaviour.
62
+ *
63
+ * @returns The `HealthKit` instance, or `undefined` if not attached.
64
+ */
65
+ get healthkit() {
66
+ return this.getBehaviour("healthkit");
67
+ }
68
+ /**
69
+ * Advances all attached behaviours.
70
+ *
71
+ * @inheritDoc
72
+ * @param deltaTime - Seconds elapsed since the previous frame.
73
+ */
74
+ update(deltaTime) {
75
+ this.updateBehaviours(deltaTime);
76
+ }
77
+ /**
78
+ * Draws a default blue rectangle and then renders all attached
79
+ * behaviours (e.g. sprite overlays, health bars).
80
+ *
81
+ * Override this in a subclass for custom visuals.
82
+ *
83
+ * TODO: write a better default player object
84
+ *
85
+ * @inheritDoc
86
+ * @param ctx - The canvas 2-D rendering context.
87
+ */
88
+ render(ctx) {
89
+ ctx.fillStyle = "blue";
90
+ ctx.fillRect(this.x, this.y, this.size.width, this.size.height);
91
+ this.renderBehaviours(ctx);
92
+ }
93
+ }
@@ -0,0 +1,62 @@
1
+ import FontBitmap, {} 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 class Text extends Entity {
16
+ /** Bitmap font name to load internally */
17
+ fontName;
18
+ /** BitmapFont instance used to manipulate the font */
19
+ font;
20
+ /** Internal state of the text needed to be update */
21
+ text = "";
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, fontName) {
33
+ super(id, 0, 0);
34
+ this.fontName = fontName;
35
+ this.font = new FontBitmap(fontName);
36
+ }
37
+ /**
38
+ * Set internal state value
39
+ *
40
+ * @param text - any content that should be render
41
+ *
42
+ * @return void
43
+ */
44
+ setText(text) {
45
+ this.text = text;
46
+ this.setSize(this.font.width * this.text.length, this.font.height);
47
+ }
48
+ /**
49
+ * Get the internal state of the object
50
+ *
51
+ * @return string
52
+ */
53
+ getText() {
54
+ return this.text;
55
+ }
56
+ /**
57
+ * Render the text to the canvas using the BitmapFont instance
58
+ */
59
+ render(ctx) {
60
+ this.font.renderText(this.getText(), this.x, this.y, ctx);
61
+ }
62
+ }
package/dist/index.d.ts CHANGED
@@ -12,7 +12,6 @@
12
12
  * @module gamefoo
13
13
  * @since 0.1.0
14
14
  */
15
- export { log } from "@decorators";
16
15
  export { default as Asset } from "./core/asset";
17
16
  export { Behaviour } from "./core/behaviour";
18
17
  export { Collidable } from "./core/behaviours/collidable";
@@ -29,6 +28,7 @@ export { default as Sprite } from "./core/sprite";
29
28
  export { PerlinNoise } from "./core/utils/perlin_noise";
30
29
  export { default as World } from "./core/world";
31
30
  export { default as Monitor } from "./debug/monitor";
31
+ export { log } from "./decorators/index";
32
32
  export { default as DynamicEntity } from "./entities/dynamic_entity";
33
33
  export { default as Entity } from "./entities/entity";
34
34
  export { default as Player } from "./entities/player";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC1E,O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BAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,29 +1,47 @@
1
- export {
2
- log,
3
- default11 as World,
4
- default16 as Text,
5
- default3 as SpriteRender,
6
- default10 as Sprite,
7
- default15 as Player,
8
- PerlinNoise,
9
- ObjectSystem,
10
- MonitorSystem,
11
- default12 as Monitor,
12
- default9 as Input,
13
- HealthKit,
14
- default8 as GameObjectRegister,
15
- default7 as FontBitmapPrebuild,
16
- default6 as FontBitmap,
17
- default14 as Entity,
18
- default5 as Engine,
19
- default13 as DynamicEntity,
20
- Control,
21
- CollisionSystem,
22
- Collidable,
23
- CameraSystem,
24
- default4 as Camera,
25
- Behaviour,
26
- default2 as Asset
27
- };
28
-
29
- //# debugId=B36FB65262DD014964756E2164756E21
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
+ // --- Assets / Rendering ───────────────────────────────────────────────
16
+ export { default as Asset } from "./core/asset";
17
+ // ── Core ────────────────────────────────────────────────────────────
18
+ export { Behaviour } from "./core/behaviour";
19
+ export { Collidable } from "./core/behaviours/collidable";
20
+ export { Control } from "./core/behaviours/control";
21
+ export { HealthKit } from "./core/behaviours/healtkit";
22
+ export { default as SpriteRender } from "./core/behaviours/sprite_render";
23
+ export { default as Camera } from "./core/camera";
24
+ export { default as Engine } from "./core/engine";
25
+ export { default as FontBitmap } from "./core/fonts/font_bitmap";
26
+ export { default as FontBitmapPrebuild } from "./core/fonts/font_bitmap_prebuild";
27
+ export { default as GameObjectRegister } from "./core/game_object_register";
28
+ export { default as Input } from "./core/input";
29
+ export { default as Sprite } from "./core/sprite";
30
+ // ── Utilities ───────────────────────────────────────────────────────
31
+ export { PerlinNoise } from "./core/utils/perlin_noise";
32
+ // ── World / Physics ─────────────────────────────────────────────────
33
+ export { default as World } from "./core/world";
34
+ // -- Debug -----
35
+ export { default as Monitor } from "./debug/monitor";
36
+ // ── Decorators ───────────────────────────────────────────────────────
37
+ export { log } from "./decorators/index";
38
+ // ── Entities ────────────────────────────────────────────────────────
39
+ export { default as DynamicEntity } from "./entities/dynamic_entity";
40
+ export { default as Entity } from "./entities/entity";
41
+ export { default as Player } from "./entities/player";
42
+ export { default as Text } from "./entities/text";
43
+ export { CameraSystem } from "./subsystems/camera_system";
44
+ // ── Subsystems ───────────────────────────────────────────────────
45
+ export { CollisionSystem } from "./subsystems/collision_system";
46
+ export { MonitorSystem } from "./subsystems/monitor_system";
47
+ export { ObjectSystem } from "./subsystems/object_system";
@@ -1,5 +1,5 @@
1
- import Camera from "@/core/camera";
2
- import type { Vector2 } from "@/types";
1
+ import Camera from "../core/camera";
2
+ import type { Vector2 } from "../types";
3
3
  import type { SubSystem } from "./types";
4
4
  /**
5
5
  * CameraSystem is responsible for managing the camera's position and view.
@@ -1 +1 @@
1
- {"version":3,"file":"camera_system.d.ts","sourceRoot":"","sources":["../../src/subsystems/camera_system.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;GAOG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C;;OAEG;IACH,EAAE,SAAY;IACd,KAAK,SAAM;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,MAAM,CAAoC;gBAEtC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,GAAG,IAAI;IAQvE,MAAM;IAWN,SAAS,CAAC,GAAG,EAAE,wBAAwB;IAMvC,UAAU,CAAC,GAAG,EAAE,wBAAwB;CAGzC"}
1
+ {"version":3,"file":"camera_system.d.ts","sourceRoot":"","sources":["../../src/subsystems/camera_system.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;GAOG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C;;OAEG;IACH,EAAE,SAAY;IACd,KAAK,SAAM;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,MAAM,CAAoC;gBAEtC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,GAAG,IAAI;IAQvE,MAAM;IAWN,SAAS,CAAC,GAAG,EAAE,wBAAwB;IAMvC,UAAU,CAAC,GAAG,EAAE,wBAAwB;CAGzC"}
@@ -0,0 +1,41 @@
1
+ import Camera from "../core/camera";
2
+ /**
3
+ * CameraSystem is responsible for managing the camera's position and view.
4
+ * It can follow a target (like a player) and adjust the view accordingly.
5
+ *
6
+ * @since 0.2.0
7
+ *
8
+ * @category SubSystems
9
+ */
10
+ export class CameraSystem {
11
+ /**
12
+ * The unique identifier for this subsystem.
13
+ */
14
+ id = "camera";
15
+ order = 10;
16
+ camera;
17
+ target = () => null;
18
+ constructor(width, height, target) {
19
+ this.camera = new Camera(width, height);
20
+ if (target) {
21
+ this.target = target;
22
+ }
23
+ }
24
+ update() {
25
+ let v = null;
26
+ if (this.target) {
27
+ v = this.target();
28
+ }
29
+ if (v !== null) {
30
+ this.camera.follow(v);
31
+ }
32
+ }
33
+ preRender(ctx) {
34
+ const v = this.camera.getViewRect();
35
+ ctx.save();
36
+ ctx.translate(-v.x, -v.y);
37
+ }
38
+ postRender(ctx) {
39
+ ctx.restore();
40
+ }
41
+ }
@@ -0,0 +1,17 @@
1
+ import World from "../core/world";
2
+ /**
3
+ * CollisionSystem is responsible for detecting collisions between game objects.
4
+ * It uses the World class to manage and detect collisions based on registered collidable objects.
5
+ *
6
+ * @since 0.2.0
7
+ *
8
+ * @category SubSystems
9
+ */
10
+ export class CollisionSystem {
11
+ id = "collision";
12
+ order = 30;
13
+ world = new World();
14
+ update() {
15
+ this.world.detect();
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ import Monitor from "../debug/monitor";
2
+ /**
3
+ * MonitorSystem is responsible for displaying debug information on the screen.
4
+ * It uses the Monitor class to track and render various performance metrics,
5
+ *
6
+ * @since 0.2.0
7
+ *
8
+ * @category SubSystems
9
+ */
10
+ export class MonitorSystem {
11
+ id = "monitor";
12
+ order = 100;
13
+ monitor = new Monitor();
14
+ update(deltaTime) {
15
+ this.monitor.update(deltaTime);
16
+ }
17
+ render(ctx) {
18
+ this.monitor.render(ctx);
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- import type { GameObject } from "@/types";
1
+ import type { GameObject } from "../types";
2
2
  import type { SubSystem } from "./types";
3
3
  /**
4
4
  * ObjectSystem is responsible for managing all non-player game objects within the engine.
@@ -1 +1 @@
1
- {"version":3,"file":"object_system.d.ts","sourceRoot":"","sources":["../../src/subsystems/object_system.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C,EAAE,SAAa;IAEf,KAAK,SAAM;IAEX,OAAO,CAAC,OAAO,CAAgD;gBAEnD,OAAO,GAAE,UAAU,EAAO;IAMtC,MAAM,CAAC,SAAS,EAAE,MAAM;IAOxB,MAAM,CAAC,GAAG,EAAE,wBAAwB;CAKrC"}
1
+ {"version":3,"file":"object_system.d.ts","sourceRoot":"","sources":["../../src/subsystems/object_system.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C,EAAE,SAAa;IAEf,KAAK,SAAM;IAEX,OAAO,CAAC,OAAO,CAAgD;gBAEnD,OAAO,GAAE,UAAU,EAAO;IAMtC,MAAM,CAAC,SAAS,EAAE,MAAM;IAOxB,MAAM,CAAC,GAAG,EAAE,wBAAwB;CAKrC"}
@@ -0,0 +1,29 @@
1
+ import GameObjectRegister from "../core/game_object_register";
2
+ /**
3
+ * ObjectSystem is responsible for managing all non-player game objects within the engine.
4
+ * It maintains a central registry of game objects and delegates per-frame update and render calls to them.
5
+ *
6
+ * @since 0.2.0
7
+ * @category SubSystems
8
+ */
9
+ export class ObjectSystem {
10
+ id = "objects";
11
+ order = 20;
12
+ objects = new GameObjectRegister();
13
+ constructor(objects = []) {
14
+ for (const obj of objects) {
15
+ this.objects.register(obj);
16
+ }
17
+ }
18
+ update(deltaTime) {
19
+ if (this.objects) {
20
+ console.time("ObjectSystem Update");
21
+ this.objects.updateAll(deltaTime);
22
+ }
23
+ }
24
+ render(ctx) {
25
+ if (this.objects) {
26
+ this.objects.renderAll(ctx);
27
+ }
28
+ }
29
+ }