@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.
- package/dist/core/animate.js +147 -0
- package/dist/core/asset.js +74 -0
- package/dist/core/behaviour.js +88 -0
- package/dist/core/behaviours/collidable.js +186 -0
- package/dist/core/behaviours/control.js +75 -0
- package/dist/core/behaviours/healtkit.js +153 -0
- package/dist/core/behaviours/sprite_render.js +193 -0
- package/dist/core/camera.js +134 -0
- package/dist/core/engine.d.ts +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +527 -0
- package/dist/core/fonts/font_bitmap.js +205 -0
- package/dist/core/fonts/font_bitmap_prebuild.js +137 -0
- package/dist/core/fonts/internal/font_3x5.js +169 -0
- package/dist/core/fonts/internal/font_4x6.js +171 -0
- package/dist/core/fonts/internal/font_5x5.js +129 -0
- package/dist/core/fonts/internal/font_6x8.js +171 -0
- package/dist/core/fonts/internal/font_8x13.js +171 -0
- package/dist/core/fonts/internal/font_8x8.js +171 -0
- package/dist/core/game_object_register.js +134 -0
- package/dist/core/input.js +170 -0
- package/dist/core/sprite.js +222 -0
- package/dist/core/utils/perlin_noise.js +183 -0
- package/dist/core/world.js +304 -0
- package/dist/debug/monitor.js +47 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/log.js +42 -0
- package/dist/entities/dynamic_entity.js +99 -0
- package/dist/entities/entity.js +283 -0
- package/dist/entities/player.js +93 -0
- package/dist/entities/text.js +62 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -29
- package/dist/subsystems/camera_system.d.ts +2 -2
- package/dist/subsystems/camera_system.d.ts.map +1 -1
- package/dist/subsystems/camera_system.js +41 -0
- package/dist/subsystems/collision_system.js +17 -0
- package/dist/subsystems/monitor_system.js +20 -0
- package/dist/subsystems/object_system.d.ts +1 -1
- package/dist/subsystems/object_system.d.ts.map +1 -1
- package/dist/subsystems/object_system.js +29 -0
- package/dist/subsystems/types.d.ts +1 -1
- package/dist/subsystems/types.d.ts.map +1 -1
- package/dist/subsystems/types.js +0 -0
- package/dist/types.js +10 -0
- package/package.json +17 -6
- package/src/core/animate.ts +159 -0
- package/src/core/asset.ts +76 -0
- package/src/core/behaviour.ts +145 -0
- package/src/core/behaviours/collidable.ts +296 -0
- package/src/core/behaviours/control.ts +80 -0
- package/src/core/behaviours/healtkit.ts +166 -0
- package/src/core/behaviours/sprite_render.ts +216 -0
- package/src/core/camera.ts +145 -0
- package/src/core/engine.ts +607 -0
- package/src/core/fonts/font_bitmap.ts +232 -0
- package/src/core/fonts/font_bitmap_prebuild.ts +141 -0
- package/src/core/fonts/internal/font_3x5.ts +178 -0
- package/src/core/fonts/internal/font_4x6.ts +180 -0
- package/src/core/fonts/internal/font_5x5.ts +137 -0
- package/src/core/fonts/internal/font_6x8.ts +180 -0
- package/src/core/fonts/internal/font_8x13.ts +180 -0
- package/src/core/fonts/internal/font_8x8.ts +180 -0
- package/src/core/game_object_register.ts +146 -0
- package/src/core/input.ts +182 -0
- package/src/core/sprite.ts +339 -0
- package/src/core/utils/perlin_noise.ts +196 -0
- package/src/core/world.ts +331 -0
- package/src/debug/monitor.ts +60 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/log.ts +45 -0
- package/src/entities/dynamic_entity.ts +106 -0
- package/src/entities/entity.ts +322 -0
- package/src/entities/player.ts +99 -0
- package/src/entities/text.ts +72 -0
- package/src/index.ts +51 -0
- package/src/subsystems/camera_system.ts +52 -0
- package/src/subsystems/collision_system.ts +21 -0
- package/src/subsystems/monitor_system.ts +26 -0
- package/src/subsystems/object_system.ts +37 -0
- package/src/subsystems/types.ts +46 -0
- package/src/types.ts +178 -0
- package/dist/index.js.map +0 -9
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type Engine from "../core/engine";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SubSystem is a modular component of the game engine that can be added or removed as needed.
|
|
5
|
+
* It provides hooks for initialization, updating, rendering, and destruction.
|
|
6
|
+
* Each subsystem can have its own logic and state, and can interact with the engine and other subsystems.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.2.0
|
|
9
|
+
*
|
|
10
|
+
* @category SubSystems
|
|
11
|
+
*/
|
|
12
|
+
export interface SubSystem {
|
|
13
|
+
/**
|
|
14
|
+
* A unique identifier for the subsystem, used for registration and management within
|
|
15
|
+
* the engine.
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determines the order in which subsystems are updated and rendered. Subsystems
|
|
21
|
+
* with lower order values are processed first.
|
|
22
|
+
*/
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Determines the order in which subsystems are updated and rendered. Subsystems with
|
|
27
|
+
* lower order values are processed first.
|
|
28
|
+
*/
|
|
29
|
+
order?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Called when the subsystem is added to the engine. Use this method to perform any
|
|
33
|
+
* necessary setup or initialization.
|
|
34
|
+
*/
|
|
35
|
+
init?(engine: Engine): void;
|
|
36
|
+
|
|
37
|
+
preUpdate?(deltaTime: number): void;
|
|
38
|
+
update?(deltaTime: number): void;
|
|
39
|
+
postUpdate?(deltaTime: number): void;
|
|
40
|
+
|
|
41
|
+
preRender?(ctx: CanvasRenderingContext2D): void;
|
|
42
|
+
render?(ctx: CanvasRenderingContext2D): void;
|
|
43
|
+
postRender?(ctx: CanvasRenderingContext2D): void;
|
|
44
|
+
|
|
45
|
+
destroy?(): void;
|
|
46
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions used throughout the GameFoo engine.
|
|
3
|
+
*
|
|
4
|
+
* This module contains the foundational interfaces and type aliases that
|
|
5
|
+
* form the contract between the engine core, entities, and behaviours.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
* @module types
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type DynamicEntity from "./entities/dynamic_entity";
|
|
13
|
+
import type Entity from "./entities/entity";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A two-dimensional vector representing a position, direction, or offset.
|
|
17
|
+
*
|
|
18
|
+
* Used pervasively across the engine for entity positions, velocities,
|
|
19
|
+
* camera coordinates, and collider offsets.
|
|
20
|
+
*
|
|
21
|
+
* @category Types
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
*
|
|
24
|
+
* @example Basic position
|
|
25
|
+
* ```ts
|
|
26
|
+
* const position: Vector2 = { x: 100, y: 200 };
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Direction vector
|
|
30
|
+
* ```ts
|
|
31
|
+
* const direction: Vector2 = { x: Math.cos(angle), y: Math.sin(angle) };
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface Vector2 {
|
|
35
|
+
/** Horizontal component (increases rightward). */
|
|
36
|
+
x: number;
|
|
37
|
+
/** Vertical component (increases downward in canvas coordinates). */
|
|
38
|
+
y: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An object representin 2D demensions of anything
|
|
43
|
+
*
|
|
44
|
+
* @category Types
|
|
45
|
+
* @since 0.2.0
|
|
46
|
+
*
|
|
47
|
+
* @example Basic set
|
|
48
|
+
* ```ts
|
|
49
|
+
* const Size: Demension = { width: 32, height: 32 };
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface Demension {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Union of all entity types that can be managed by the engine's
|
|
59
|
+
* {@link GameObjectRegister}.
|
|
60
|
+
*
|
|
61
|
+
* Covers both static entities ({@link Entity}) and physics-capable
|
|
62
|
+
* entities ({@link DynamicEntity}).
|
|
63
|
+
*
|
|
64
|
+
* @category Types
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*
|
|
67
|
+
* @see {@link Entity} — base abstract entity
|
|
68
|
+
* @see {@link DynamicEntity} — entity with velocity and speed
|
|
69
|
+
*/
|
|
70
|
+
export type GameObject = Entity | DynamicEntity;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Discriminated union describing the shape of a collision volume.
|
|
74
|
+
*
|
|
75
|
+
* The `type` field acts as the discriminant:
|
|
76
|
+
*
|
|
77
|
+
* | `type` | Extra fields | Description |
|
|
78
|
+
* | ---------- | -------------------------- | ------------------------------ |
|
|
79
|
+
* | `"aabb"` | `width`, `height`, `offset?` | Axis-aligned bounding box |
|
|
80
|
+
* | `"circle"` | `radius`, `offset?` | Circle centred on the entity |
|
|
81
|
+
*
|
|
82
|
+
* @category Types
|
|
83
|
+
* @since 0.1.0
|
|
84
|
+
*
|
|
85
|
+
* @example AABB collider
|
|
86
|
+
* ```ts
|
|
87
|
+
* const box: ColliderShape = {
|
|
88
|
+
* type: "aabb",
|
|
89
|
+
* width: 32,
|
|
90
|
+
* height: 32,
|
|
91
|
+
* };
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example Circle collider with offset
|
|
95
|
+
* ```ts
|
|
96
|
+
* const circle: ColliderShape = {
|
|
97
|
+
* type: "circle",
|
|
98
|
+
* radius: 16,
|
|
99
|
+
* offset: { x: 0, y: -4 },
|
|
100
|
+
* };
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export type ColliderShape =
|
|
104
|
+
| {
|
|
105
|
+
/** Discriminant for an axis-aligned bounding box. */
|
|
106
|
+
type: "aabb";
|
|
107
|
+
/** Width of the bounding box in pixels. */
|
|
108
|
+
width: number;
|
|
109
|
+
/** Height of the bounding box in pixels. */
|
|
110
|
+
height: number;
|
|
111
|
+
/**
|
|
112
|
+
* Optional positional offset relative to the owning entity's origin.
|
|
113
|
+
* @defaultValue `{ x: 0, y: 0 }`
|
|
114
|
+
*/
|
|
115
|
+
offset?: Vector2;
|
|
116
|
+
}
|
|
117
|
+
| {
|
|
118
|
+
/** Discriminant for a circular collider. */
|
|
119
|
+
type: "circle";
|
|
120
|
+
/** Radius of the circle in pixels. */
|
|
121
|
+
radius: number;
|
|
122
|
+
/**
|
|
123
|
+
* Optional positional offset relative to the owning entity's origin.
|
|
124
|
+
* @defaultValue `{ x: 0, y: 0 }`
|
|
125
|
+
*/
|
|
126
|
+
offset?: Vector2;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Payload delivered to a {@link Collidable.onCollision} callback when two
|
|
131
|
+
* colliders overlap.
|
|
132
|
+
*
|
|
133
|
+
* Provides references to both participating entities and their tag sets
|
|
134
|
+
* so the callback can determine the nature of the collision.
|
|
135
|
+
*
|
|
136
|
+
* @category Types
|
|
137
|
+
* @since 0.1.0
|
|
138
|
+
*
|
|
139
|
+
* @example Handling a collision
|
|
140
|
+
* ```ts
|
|
141
|
+
* function handleHit(info: CollisionInfo) {
|
|
142
|
+
* if (info.otherTags.has("enemy")) {
|
|
143
|
+
* console.log(`${info.self.id} was hit by ${info.other.id}`);
|
|
144
|
+
* }
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export interface CollisionInfo {
|
|
149
|
+
/** The entity that *owns* this collision callback. */
|
|
150
|
+
self: Entity;
|
|
151
|
+
/** The other entity involved in the collision. */
|
|
152
|
+
other: Entity;
|
|
153
|
+
/** Tags belonging to {@link CollisionInfo.self | self}. */
|
|
154
|
+
selfTags: Set<string>;
|
|
155
|
+
/** Tags belonging to {@link CollisionInfo.other | other}. */
|
|
156
|
+
otherTags: Set<string>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Axis-aligned rectangle used internally by the collision detection
|
|
161
|
+
* system ({@link World}) to represent an entity's bounding volume in
|
|
162
|
+
* world-space.
|
|
163
|
+
*
|
|
164
|
+
* @category Types
|
|
165
|
+
* @since 0.1.0
|
|
166
|
+
*
|
|
167
|
+
* @see {@link World} — consumes these bounds during the detection pass
|
|
168
|
+
*/
|
|
169
|
+
export interface WorldBounds {
|
|
170
|
+
/** Left edge X coordinate. */
|
|
171
|
+
x: number;
|
|
172
|
+
/** Top edge Y coordinate. */
|
|
173
|
+
y: number;
|
|
174
|
+
/** Horizontal extent in pixels. */
|
|
175
|
+
width: number;
|
|
176
|
+
/** Vertical extent in pixels. */
|
|
177
|
+
height: number;
|
|
178
|
+
}
|