angry-pixel 1.2.2 → 1.2.4
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/.github/workflows/analyzeCode.yml +25 -0
- package/.github/workflows/buildCode.yml +23 -0
- package/.github/workflows/main.yml +15 -13
- package/.github/workflows/setupNode.yml +40 -0
- package/README.md +170 -3
- package/api-docs/.nojekyll +1 -0
- package/api-docs/assets/highlight.css +92 -0
- package/api-docs/assets/main.js +59 -0
- package/api-docs/assets/navigation.js +1 -0
- package/api-docs/assets/search.js +1 -0
- package/api-docs/assets/style.css +1383 -0
- package/api-docs/classes/Animator.html +128 -0
- package/api-docs/classes/AudioPlayer.html +131 -0
- package/api-docs/classes/BallCollider.html +132 -0
- package/api-docs/classes/BoxCollider.html +136 -0
- package/api-docs/classes/Button.html +125 -0
- package/api-docs/classes/Camera.html +114 -0
- package/api-docs/classes/Component.html +106 -0
- package/api-docs/classes/EdgeCollider.html +134 -0
- package/api-docs/classes/Game.html +24 -0
- package/api-docs/classes/GameCamera.html +163 -0
- package/api-docs/classes/GameObject.html +149 -0
- package/api-docs/classes/GamepadController.html +11 -0
- package/api-docs/classes/GamepadData.html +81 -0
- package/api-docs/classes/KeyboardController.html +43 -0
- package/api-docs/classes/MaskRenderer.html +119 -0
- package/api-docs/classes/MouseController.html +14 -0
- package/api-docs/classes/PhysicsComponent.html +107 -0
- package/api-docs/classes/PolygonCollider.html +134 -0
- package/api-docs/classes/PreRenderComponent.html +107 -0
- package/api-docs/classes/Rectangle.html +30 -0
- package/api-docs/classes/RigidBody.html +123 -0
- package/api-docs/classes/Rotation.html +5 -0
- package/api-docs/classes/Scene.html +73 -0
- package/api-docs/classes/SpacePointer.html +147 -0
- package/api-docs/classes/Sprite.html +20 -0
- package/api-docs/classes/SpriteRenderer.html +134 -0
- package/api-docs/classes/TextRenderer.html +138 -0
- package/api-docs/classes/TiledTilemapRenderer.html +127 -0
- package/api-docs/classes/TilemapCollider.html +124 -0
- package/api-docs/classes/TilemapRenderer.html +126 -0
- package/api-docs/classes/TouchController.html +8 -0
- package/api-docs/classes/Transform.html +124 -0
- package/api-docs/classes/Vector2.html +65 -0
- package/api-docs/classes/VideoRenderer.html +145 -0
- package/api-docs/enums/BroadPhaseMethods.html +3 -0
- package/api-docs/enums/ButtonType.html +3 -0
- package/api-docs/enums/CollisionMethods.html +3 -0
- package/api-docs/enums/RigidBodyType.html +4 -0
- package/api-docs/enums/TextOrientation.html +5 -0
- package/api-docs/enums/TilemapOrientation.html +5 -0
- package/api-docs/functions/between.html +5 -0
- package/api-docs/functions/clamp.html +5 -0
- package/api-docs/functions/fixedRound.html +4 -0
- package/api-docs/functions/randomFloat.html +4 -0
- package/api-docs/functions/randomInt.html +4 -0
- package/api-docs/functions/range.html +5 -0
- package/api-docs/index.html +37 -0
- package/api-docs/interfaces/AnimationConfig.html +10 -0
- package/api-docs/interfaces/AnimatorOptions.html +6 -0
- package/api-docs/interfaces/AudioPlayerOptions.html +8 -0
- package/api-docs/interfaces/BallColliderOptions.html +16 -0
- package/api-docs/interfaces/BoxColliderOptions.html +20 -0
- package/api-docs/interfaces/ButtonOptions.html +16 -0
- package/api-docs/interfaces/ColliderComponent.html +14 -0
- package/api-docs/interfaces/CollisionData.html +10 -0
- package/api-docs/interfaces/EdgeColliderOptions.html +18 -0
- package/api-docs/interfaces/GameConfig.html +28 -0
- package/api-docs/interfaces/IAssetManager.html +40 -0
- package/api-docs/interfaces/ICollider.html +11 -0
- package/api-docs/interfaces/ICollision.html +4 -0
- package/api-docs/interfaces/ICollisionResolution.html +4 -0
- package/api-docs/interfaces/IDomManager.html +6 -0
- package/api-docs/interfaces/IGameObjectManager.html +49 -0
- package/api-docs/interfaces/IInputManager.html +12 -0
- package/api-docs/interfaces/IPhysicsManager.html +8 -0
- package/api-docs/interfaces/IRenderManager.html +7 -0
- package/api-docs/interfaces/ISceneManager.html +18 -0
- package/api-docs/interfaces/ITimeManager.html +16 -0
- package/api-docs/interfaces/MaskRendererOptions.html +18 -0
- package/api-docs/interfaces/PolygonColliderOptions.html +18 -0
- package/api-docs/interfaces/RigidBodyOptions.html +17 -0
- package/api-docs/interfaces/Slice.html +5 -0
- package/api-docs/interfaces/SpriteConfig.html +10 -0
- package/api-docs/interfaces/SpriteRendererOptions.html +32 -0
- package/api-docs/interfaces/TextRendererOptions.html +38 -0
- package/api-docs/interfaces/TiledChunk.html +7 -0
- package/api-docs/interfaces/TiledLayer.html +17 -0
- package/api-docs/interfaces/TiledTilemap.html +9 -0
- package/api-docs/interfaces/TiledTilemapRendererOptions.html +18 -0
- package/api-docs/interfaces/TilemapColliderOptions.html +12 -0
- package/api-docs/interfaces/TilemapRendererOptions.html +22 -0
- package/api-docs/interfaces/Tileset.html +13 -0
- package/api-docs/interfaces/TouchInteraction.html +6 -0
- package/api-docs/interfaces/VideoRendererOptions.html +34 -0
- package/api-docs/modules.html +85 -0
- package/api-docs/types/CollisionMatrix.html +1 -0
- package/lib/component/Animator.d.ts +114 -8
- package/lib/component/AudioPlayer.d.ts +44 -6
- package/lib/component/Button.d.ts +82 -7
- package/lib/component/Camera.d.ts +27 -0
- package/lib/component/RigidBody.d.ts +75 -0
- package/lib/component/Sprite.d.ts +31 -3
- package/lib/component/Transform.d.ts +35 -0
- package/lib/component/collider/BallCollider.d.ts +48 -0
- package/lib/component/collider/BoxCollider.d.ts +57 -0
- package/lib/component/collider/Collider.d.ts +47 -1
- package/lib/component/collider/EdgeCollider.d.ts +52 -0
- package/lib/component/collider/PolygonCollider.d.ts +53 -0
- package/lib/component/collider/TilemapCollider.d.ts +41 -0
- package/lib/component/rendering/MaskRenderer.d.ts +56 -0
- package/lib/component/rendering/Sprite.d.ts +61 -0
- package/lib/component/rendering/SpriteRenderer.d.ts +92 -2
- package/lib/component/rendering/TextRenderer.d.ts +103 -4
- package/lib/component/rendering/TiledTilemapRenderer.d.ts +110 -3
- package/lib/component/rendering/TilemapRenderer.d.ts +120 -5
- package/lib/component/rendering/VideoRenderer.d.ts +91 -1
- package/lib/core/Component.d.ts +118 -0
- package/lib/core/Game.d.ts +47 -2
- package/lib/core/GameActor.d.ts +20 -4
- package/lib/core/GameConfig.d.ts +45 -2
- package/lib/core/GameObject.d.ts +63 -0
- package/lib/core/Scene.d.ts +32 -0
- package/lib/core/ioc/Config.d.ts +2 -1
- package/lib/core/managers/AssetManager.d.ts +68 -6
- package/lib/core/managers/DomManager.d.ts +11 -0
- package/lib/core/managers/GameObjectManager.d.ts +81 -0
- package/lib/core/managers/HeadlessIterationManager.d.ts +1 -0
- package/lib/core/managers/IterationManager.d.ts +4 -0
- package/lib/core/managers/SceneManager.d.ts +29 -1
- package/lib/core/managers/TimeManager.d.ts +37 -2
- package/lib/gameObject/GameCamera.d.ts +22 -0
- package/lib/gameObject/SpacePointer.d.ts +7 -0
- package/lib/index.cjs.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/input/GamepadController.d.ts +176 -2
- package/lib/input/InputManager.d.ts +18 -0
- package/lib/input/KeyboardController.d.ts +70 -1
- package/lib/input/MouseController.d.ts +35 -0
- package/lib/input/TouchController.d.ts +36 -4
- package/lib/utils/Container.d.ts +1 -0
- package/lib/utils/Exception.d.ts +1 -0
- package/package.json +9 -5
- package/typedoc.json +13 -0
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
import { CameraComponent } from "../core/Component";
|
|
2
2
|
import { Rectangle } from "angry-pixel-math";
|
|
3
|
+
/**
|
|
4
|
+
* The Camera component is used to organize the rendering order by layers and to manage the general zooming of these layers.
|
|
5
|
+
* @public
|
|
6
|
+
* @category Components
|
|
7
|
+
* @example
|
|
8
|
+
* ```js
|
|
9
|
+
* const camera = this.addComponent(Camera);
|
|
10
|
+
* camera.zoom = 1;
|
|
11
|
+
* camera.depth = 0;
|
|
12
|
+
* camera.layers = ["Background", "Foreground"];
|
|
13
|
+
* camera.addLayer("UI");
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
3
16
|
export declare class Camera extends CameraComponent {
|
|
17
|
+
/** @private */
|
|
4
18
|
readonly allowMultiple: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Rectangle representing the field of view of the camera from the perspective of the screen
|
|
21
|
+
* @readonly
|
|
22
|
+
*/
|
|
5
23
|
readonly viewportRect: Rectangle;
|
|
24
|
+
/**
|
|
25
|
+
* Rectangle representing the field of view of the camera in the game world
|
|
26
|
+
* @readonly
|
|
27
|
+
*/
|
|
6
28
|
readonly worldSpaceRect: Rectangle;
|
|
29
|
+
/** In case you have more than one camera, the depth value determines which camera is rendered first */
|
|
7
30
|
depth: number;
|
|
31
|
+
/** Layers to be rendered by this camera */
|
|
8
32
|
layers: string[];
|
|
9
33
|
private _zoom;
|
|
10
34
|
private cameraData;
|
|
11
35
|
private canvas;
|
|
36
|
+
/** Camera zoom. Default value is 1 */
|
|
12
37
|
set zoom(zoom: number);
|
|
38
|
+
/** Camera zoom. Default value is 1 */
|
|
13
39
|
get zoom(): number;
|
|
40
|
+
/** Adds a new layer to the end of the stack */
|
|
14
41
|
addLayer(layer: string): void;
|
|
15
42
|
protected init(): void;
|
|
16
43
|
protected update(): void;
|
|
@@ -3,17 +3,92 @@ import { Vector2 } from "angry-pixel-math";
|
|
|
3
3
|
import { InitOptions } from "../core/GameActor";
|
|
4
4
|
import { RigidBodyType } from "angry-pixel-2d-physics";
|
|
5
5
|
export { RigidBodyType } from "angry-pixel-2d-physics";
|
|
6
|
+
/**
|
|
7
|
+
* RigidBody configuration options
|
|
8
|
+
* @public
|
|
9
|
+
* @category Components
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
const body = this.addComponent(RigidBody, {
|
|
13
|
+
rigidBodyType: RigidBodyType.Dynamic,
|
|
14
|
+
gravity: 10
|
|
15
|
+
});
|
|
16
|
+
* ```
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
const body = this.addComponent(RigidBody, {
|
|
20
|
+
rigidBodyType: RigidBodyType.Kinematic,
|
|
21
|
+
});
|
|
22
|
+
* ```
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
const body = this.addComponent(RigidBody, {
|
|
26
|
+
rigidBodyType: RigidBodyType.Static,
|
|
27
|
+
});
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
6
30
|
export interface RigidBodyOptions extends InitOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The type determines how it will respond to physics and collisions.
|
|
33
|
+
- Dynamic = This type of body is affected by gravity, can be velocity-applied and collides with all types of bodies.
|
|
34
|
+
- Kinematic = This body type is not affected by gravity but can have velocity applied to it. Dynamic bodies can collide with it.
|
|
35
|
+
- Static = This type of body is immovable, no velocity can be applied to it and it is not affected by gravity. It is the body type that consumes the least processing resources.
|
|
36
|
+
*/
|
|
7
37
|
rigidBodyType: RigidBodyType;
|
|
38
|
+
/** Gravity expressed in pixels per second squared. Only applies fot Dynamic bodies */
|
|
8
39
|
gravity?: number;
|
|
9
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The RigidBody component puts the object under simulation of the physics engine, where it will interact with other objects that have a RigidBody.
|
|
43
|
+
* The RigidBody component requires the object to have at least one collider.
|
|
44
|
+
*
|
|
45
|
+
* There are three types of bodies:
|
|
46
|
+
* - Dynamic = This type of body is affected by gravity, can be velocity-applied and collides with all types of bodies.
|
|
47
|
+
* - Kinematic = This body type is not affected by gravity but can have velocity applied to it. Dynamic bodies can collide with it.
|
|
48
|
+
* - Static = This type of body is immovable, no velocity can be applied to it and it is not affected by gravity. It is the body type that consumes the least processing resources.
|
|
49
|
+
* @public
|
|
50
|
+
* @category Components
|
|
51
|
+
* @example
|
|
52
|
+
* ```js
|
|
53
|
+
const body = this.addComponent(RigidBody, {
|
|
54
|
+
rigidBodyType: RigidBodyType.Dynamic,
|
|
55
|
+
gravity: 10
|
|
56
|
+
});
|
|
57
|
+
body.velocity = 200;
|
|
58
|
+
* ```
|
|
59
|
+
* @example
|
|
60
|
+
* ```js
|
|
61
|
+
const body = this.addComponent(RigidBody, {
|
|
62
|
+
rigidBodyType: RigidBodyType.Kinematic,
|
|
63
|
+
});
|
|
64
|
+
body.velocity = 200;
|
|
65
|
+
* ```
|
|
66
|
+
* @example
|
|
67
|
+
* ```js
|
|
68
|
+
const body = this.addComponent(RigidBody, {
|
|
69
|
+
rigidBodyType: RigidBodyType.Static,
|
|
70
|
+
});
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
10
73
|
export declare class RigidBody extends EngineComponent {
|
|
74
|
+
/** @private */
|
|
11
75
|
readonly allowMultiple: boolean;
|
|
12
76
|
private rigidBody;
|
|
77
|
+
/** Velocity applied to the x-axis and y-axis expressed in pixels per second. */
|
|
13
78
|
get velocity(): Vector2;
|
|
79
|
+
/** Velocity applied to the x-axis and y-axis expressed in pixels per second. */
|
|
14
80
|
set velocity(velocity: Vector2);
|
|
81
|
+
/** Gravity expressed in pixels per second squared. Only applies fot Dynamic bodies */
|
|
15
82
|
get gravity(): number;
|
|
83
|
+
/** Gravity expressed in pixels per second squared. Only applies fot Dynamic bodies */
|
|
16
84
|
set gravity(gravity: number);
|
|
85
|
+
/**
|
|
86
|
+
* The type determines how it will respond to physics and collisions.
|
|
87
|
+
- Dynamic = This type of body is affected by gravity, can be velocity-applied and collides with all types of bodies.
|
|
88
|
+
- Kinematic = This body type is not affected by gravity but can have velocity applied to it. Dynamic bodies can collide with it.
|
|
89
|
+
- Static = This type of body is immovable, no velocity can be applied to it and it is not affected by gravity. It is the body type that consumes the least processing resources.
|
|
90
|
+
*/
|
|
91
|
+
get rigidBodyType(): RigidBodyType;
|
|
17
92
|
protected init({ rigidBodyType, gravity }: RigidBodyOptions): void;
|
|
18
93
|
protected update(): void;
|
|
19
94
|
private getColliderIds;
|
|
@@ -1,22 +1,50 @@
|
|
|
1
|
-
import { Vector2 } from "angry-pixel-math";
|
|
2
1
|
import { Slice } from "angry-pixel-2d-renderer";
|
|
3
2
|
export { Slice };
|
|
3
|
+
/**
|
|
4
|
+
* Sprite configuration options
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export interface SpriteConfig {
|
|
8
|
+
/** The image element to render */
|
|
5
9
|
image: HTMLImageElement;
|
|
6
|
-
|
|
10
|
+
/** Cut the image based on straight coordinates starting from the top left downward */
|
|
7
11
|
slice?: Slice;
|
|
12
|
+
/** Smoothing pixels (not recommended for pixel art) */
|
|
8
13
|
smooth?: boolean;
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The Sprite is an object that is composed of the Image element and allow to slice it and smooth its pixels.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* const sprite = new Sprite({image: this.assetManager.getImage("image.png")});
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* const sprite = new Sprite({
|
|
27
|
+
* image: this.assetManager.getImage("image.png"),
|
|
28
|
+
* slice: {x: 0, y:0, width: 16, height: 16},
|
|
29
|
+
* smooth: false
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
10
33
|
export declare class Sprite {
|
|
34
|
+
/** The image element to render */
|
|
11
35
|
readonly image: HTMLImageElement;
|
|
36
|
+
/** Cut the image based on straight coordinates starting from the top left downward */
|
|
12
37
|
readonly slice: Slice;
|
|
38
|
+
/** Smoothing pixels (not recommended for pixel art) */
|
|
13
39
|
readonly smooth: boolean;
|
|
14
|
-
scale?: Vector2;
|
|
15
40
|
private _width;
|
|
16
41
|
private _height;
|
|
17
42
|
private _loaded;
|
|
18
43
|
constructor(config: SpriteConfig);
|
|
44
|
+
/** The image width */
|
|
19
45
|
get width(): number;
|
|
46
|
+
/** The image height */
|
|
20
47
|
get height(): number;
|
|
48
|
+
/** TRUE if the image is loaded */
|
|
21
49
|
get loaded(): boolean;
|
|
22
50
|
}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { TransformComponent } from "../core/Component";
|
|
2
2
|
import { Rotation, Vector2 } from "angry-pixel-math";
|
|
3
|
+
/**
|
|
4
|
+
* All GameObject have a Transform natively, so it cannot be added manually.
|
|
5
|
+
* It is used to handle the position, rotation and scale of the object. If the object has a parent,
|
|
6
|
+
* it can be scaled, rotated and translated hierarchically.
|
|
7
|
+
* @public
|
|
8
|
+
* @category Components
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* this.transform.position = new Vector2(0, 0);
|
|
12
|
+
* this.transform.position.set(0, 0);
|
|
13
|
+
*
|
|
14
|
+
* this.transform.scale = new Vector2(0, 0);
|
|
15
|
+
* this.transform.scale.set(0, 0);
|
|
16
|
+
*
|
|
17
|
+
* this.transform.rotation.radians = 0;
|
|
18
|
+
* this.transform.rotation.degrees = 0;
|
|
19
|
+
*
|
|
20
|
+
* // used to set position relative to the parent
|
|
21
|
+
* this.transform.innerPosition = new Vector2(0, 0);
|
|
22
|
+
* this.transform.innerPosition.set(0, 0);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export declare class Transform extends TransformComponent {
|
|
26
|
+
/** @private */
|
|
4
27
|
readonly allowMultiple: boolean;
|
|
28
|
+
/** Apply scale relative to the parent. Default value is TRUE */
|
|
5
29
|
parentScale: boolean;
|
|
30
|
+
/** Apply rotation relative to the parent. Default value is TRUE */
|
|
6
31
|
parentRotation: boolean;
|
|
7
32
|
private _position;
|
|
8
33
|
private _scale;
|
|
@@ -13,15 +38,25 @@ export declare class Transform extends TransformComponent {
|
|
|
13
38
|
private lastParentRadians;
|
|
14
39
|
private lastPosition;
|
|
15
40
|
private scaledInnerPosition;
|
|
41
|
+
/** Position on x-axis and y-axis in pixels */
|
|
16
42
|
get position(): Vector2;
|
|
43
|
+
/** Position on x-axis and y-axis in pixels */
|
|
17
44
|
set position(position: Vector2);
|
|
45
|
+
/** Scale on x-axis and y-axis in pixels */
|
|
18
46
|
get scale(): Vector2;
|
|
47
|
+
/** Scale on x-axis and y-axis in pixels */
|
|
19
48
|
set scale(scale: Vector2);
|
|
49
|
+
/** Rotation expressed in radians or degrees */
|
|
20
50
|
get rotation(): Rotation;
|
|
51
|
+
/** Direction vector based on the Rotation */
|
|
21
52
|
get direction(): Vector2;
|
|
53
|
+
/** Position vector relative to the parent */
|
|
22
54
|
get innerPosition(): Vector2;
|
|
55
|
+
/** Position vector relative to the parent */
|
|
23
56
|
set innerPosition(innerPosition: Vector2);
|
|
57
|
+
/** Parent transform */
|
|
24
58
|
get parent(): Transform | null;
|
|
59
|
+
/** Parent transform */
|
|
25
60
|
set parent(parent: Transform | null);
|
|
26
61
|
protected update(): void;
|
|
27
62
|
private setPositionFromParent;
|
|
@@ -1,17 +1,65 @@
|
|
|
1
1
|
import { BaseCollider } from "./Collider";
|
|
2
2
|
import { InitOptions } from "../../core/GameActor";
|
|
3
|
+
/**
|
|
4
|
+
* BallCollider configuration options
|
|
5
|
+
* @public
|
|
6
|
+
* @category Components
|
|
7
|
+
* @example
|
|
8
|
+
* ```js
|
|
9
|
+
* this.addComponent(BallCollider, {
|
|
10
|
+
* radius: 32,
|
|
11
|
+
* offsetX: 0,
|
|
12
|
+
* offsetY: 0,
|
|
13
|
+
* layer: "PlayerHitbox",
|
|
14
|
+
* debug: false,
|
|
15
|
+
* physics: true,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export interface BallColliderOptions extends InitOptions {
|
|
20
|
+
/** Radius in pixels */
|
|
4
21
|
radius: number;
|
|
22
|
+
/** x-axis offset */
|
|
5
23
|
offsetX?: number;
|
|
24
|
+
/** y-axis offset */
|
|
6
25
|
offsetY?: number;
|
|
26
|
+
/** Collision layer, if it's not setted, it uses the game object layer */
|
|
7
27
|
layer?: string;
|
|
28
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
8
29
|
physics?: boolean;
|
|
30
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
9
31
|
debug?: boolean;
|
|
10
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Circumference shaped collider for 2d collisions.
|
|
35
|
+
* @public
|
|
36
|
+
* @category Components
|
|
37
|
+
* @example
|
|
38
|
+
* ```js
|
|
39
|
+
* this.addComponent(BallCollider, {
|
|
40
|
+
* radius: 32
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* this.addComponent(BallCollider, {
|
|
46
|
+
* radius: 32,
|
|
47
|
+
* offsetX: 0,
|
|
48
|
+
* offsetY: 0,
|
|
49
|
+
* layer: "PlayerHitbox",
|
|
50
|
+
* debug: false,
|
|
51
|
+
* physics: true,
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
11
55
|
export declare class BallCollider extends BaseCollider {
|
|
56
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
12
57
|
debug: boolean;
|
|
58
|
+
/** Radius in pixels */
|
|
13
59
|
radius: number;
|
|
60
|
+
/** x-axis offset */
|
|
14
61
|
offsetX: number;
|
|
62
|
+
/** y-axis offset */
|
|
15
63
|
offsetY: number;
|
|
16
64
|
private realRadius;
|
|
17
65
|
private realOffset;
|
|
@@ -1,22 +1,79 @@
|
|
|
1
1
|
import { BaseCollider } from "./Collider";
|
|
2
2
|
import { InitOptions } from "../../core/GameActor";
|
|
3
3
|
import { Rotation } from "angry-pixel-math";
|
|
4
|
+
/**
|
|
5
|
+
* BoxCollider configuration options
|
|
6
|
+
* @public
|
|
7
|
+
* @category Components
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* this.addComponent(BoxCollider, {
|
|
11
|
+
* width: 32,
|
|
12
|
+
* height: 32,
|
|
13
|
+
* rotation: new Rotation(0),
|
|
14
|
+
* offsetX: 0,
|
|
15
|
+
* offsetY: 0,
|
|
16
|
+
* layer: "PlayerHitbox",
|
|
17
|
+
* debug: false,
|
|
18
|
+
* physics: true,
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
4
22
|
export interface BoxColliderOptions extends InitOptions {
|
|
23
|
+
/** Width of the rectangle in pixels */
|
|
5
24
|
width: number;
|
|
25
|
+
/** Height of the rectangle in pixels */
|
|
6
26
|
height: number;
|
|
27
|
+
/** x-axis offset */
|
|
7
28
|
offsetX?: number;
|
|
29
|
+
/** y-axis offset */
|
|
8
30
|
offsetY?: number;
|
|
31
|
+
/** Rectangle rotation (degrees or radians) */
|
|
9
32
|
rotation?: Rotation;
|
|
33
|
+
/** Collision layer, if it's not setted, it uses the game object layer */
|
|
10
34
|
layer?: string;
|
|
35
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
11
36
|
physics?: boolean;
|
|
37
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
12
38
|
debug?: boolean;
|
|
13
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Rectangle shaped collider for 2d collisions.
|
|
42
|
+
* @public
|
|
43
|
+
* @category Components
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* this.addComponent(BoxCollider, {
|
|
47
|
+
* width: 32,
|
|
48
|
+
* height: 32,
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
* @example
|
|
52
|
+
* ```js
|
|
53
|
+
* this.addComponent(BoxCollider, {
|
|
54
|
+
* width: 32,
|
|
55
|
+
* height: 32,
|
|
56
|
+
* rotation: new Rotation(0),
|
|
57
|
+
* offsetX: 0,
|
|
58
|
+
* offsetY: 0,
|
|
59
|
+
* layer: "PlayerHitbox",
|
|
60
|
+
* debug: false,
|
|
61
|
+
* physics: true,
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
14
65
|
export declare class BoxCollider extends BaseCollider {
|
|
66
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
15
67
|
debug: boolean;
|
|
68
|
+
/** Width of the rectangle in pixels */
|
|
16
69
|
width: number;
|
|
70
|
+
/** Height of the rectangle in pixels */
|
|
17
71
|
height: number;
|
|
72
|
+
/** x-axis offset */
|
|
18
73
|
offsetX: number;
|
|
74
|
+
/** y-axis offset */
|
|
19
75
|
offsetY: number;
|
|
76
|
+
/** Rectangle rotation (degrees or radians) */
|
|
20
77
|
rotation: Rotation;
|
|
21
78
|
private realWidth;
|
|
22
79
|
private realHeight;
|
|
@@ -1,32 +1,78 @@
|
|
|
1
1
|
import { ColliderComponent, RenderComponent } from "../../core/Component";
|
|
2
2
|
import { GameObject } from "../../core/GameObject";
|
|
3
3
|
import { ICollisionResolution, ICollider } from "angry-pixel-2d-physics";
|
|
4
|
+
/**
|
|
5
|
+
* Information about the collision
|
|
6
|
+
* @public
|
|
7
|
+
* @category Components
|
|
8
|
+
*/
|
|
4
9
|
export interface CollisionData {
|
|
10
|
+
/** Contains information about the penetration and direction of the collision. */
|
|
5
11
|
resolution: ICollisionResolution;
|
|
12
|
+
/** The collider on the other side of the collision. */
|
|
6
13
|
collider: ICollider;
|
|
14
|
+
/** The object on the other side of the collision. */
|
|
7
15
|
gameObject: GameObject;
|
|
8
16
|
/**
|
|
9
|
-
* @return The
|
|
17
|
+
* @return The object on the other side of the collision.
|
|
10
18
|
*/
|
|
11
19
|
getGameObject: <T extends GameObject>() => T;
|
|
12
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Every collider component implements this interface.
|
|
23
|
+
* @public
|
|
24
|
+
* @category Components
|
|
25
|
+
*/
|
|
13
26
|
export interface IColliderComponent {
|
|
27
|
+
/**
|
|
28
|
+
* Check if the collider is in contact with any collider of the given layer.
|
|
29
|
+
* @param layer The layer to check
|
|
30
|
+
* @returns TRUE if is colliding, FALSE instead
|
|
31
|
+
*/
|
|
14
32
|
collidesWithLayer(layer: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* If there is a collision with the given layer, it returns information about it, or null if there is none.
|
|
35
|
+
* @param layer The layer to check
|
|
36
|
+
* @returns The collision data object, or NULL instead
|
|
37
|
+
*/
|
|
15
38
|
getCollisionWithLayer(layer: string): CollisionData | null;
|
|
39
|
+
/**
|
|
40
|
+
* If there are collisions with the given layer, it returns information about every collision.
|
|
41
|
+
* @param layer The layer to check
|
|
42
|
+
* @returns The collection of collision data
|
|
43
|
+
*/
|
|
16
44
|
getCollisionsWithLayer(layer: string): CollisionData[];
|
|
17
45
|
}
|
|
46
|
+
/** @private */
|
|
18
47
|
export declare abstract class BaseCollider extends ColliderComponent implements IColliderComponent {
|
|
19
48
|
protected renderer: RenderComponent;
|
|
20
49
|
readonly colliders: ICollider[];
|
|
50
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
21
51
|
layer: string;
|
|
52
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
22
53
|
physics: boolean;
|
|
23
54
|
private activateColliders;
|
|
24
55
|
protected abstract updateRealSize(): void;
|
|
25
56
|
protected abstract updatePosition(): void;
|
|
26
57
|
protected abstract updateColliders(): void;
|
|
27
58
|
protected update(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Check if the collider is in contact with any collider of the given layer.
|
|
61
|
+
* @param layer The layer to check
|
|
62
|
+
* @returns TRUE if is colliding, FALSE instead
|
|
63
|
+
*/
|
|
28
64
|
collidesWithLayer(layer: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* If there is a collision with the given layer, it returns information about it, or null if there is none.
|
|
67
|
+
* @param layer The layer to check
|
|
68
|
+
* @returns The collision data object, or NULL instead
|
|
69
|
+
*/
|
|
29
70
|
getCollisionWithLayer(layer: string): CollisionData | null;
|
|
71
|
+
/**
|
|
72
|
+
* If there are collisions with the given layer, it returns information about every collision.
|
|
73
|
+
* @param layer The layer to check
|
|
74
|
+
* @returns The collection of collision data
|
|
75
|
+
*/
|
|
30
76
|
getCollisionsWithLayer(layer: string): CollisionData[];
|
|
31
77
|
private createCollisionData;
|
|
32
78
|
protected onActiveChange(): void;
|
|
@@ -1,20 +1,72 @@
|
|
|
1
1
|
import { BaseCollider } from "./Collider";
|
|
2
2
|
import { InitOptions } from "../../core/GameActor";
|
|
3
3
|
import { Vector2, Rotation } from "angry-pixel-math";
|
|
4
|
+
/**
|
|
5
|
+
* EdgeCollider configuration options
|
|
6
|
+
* @public
|
|
7
|
+
* @category Components
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* this.addComponent(EdgeCollider, {
|
|
11
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32)],
|
|
12
|
+
* rotation: new Rotation(0),
|
|
13
|
+
* offsetX: 0,
|
|
14
|
+
* offsetY: 0,
|
|
15
|
+
* layer: "Hills",
|
|
16
|
+
* debug: false,
|
|
17
|
+
* physics: true,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
export interface EdgeColliderOptions extends InitOptions {
|
|
22
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
5
23
|
vertexModel: Vector2[];
|
|
24
|
+
/** x-axis offset */
|
|
6
25
|
offsetX?: number;
|
|
26
|
+
/** y-axis offset */
|
|
7
27
|
offsetY?: number;
|
|
28
|
+
/** Edges rotation (degrees or radians) */
|
|
8
29
|
rotation?: Rotation;
|
|
30
|
+
/** Collision layer, if it's not setted, it uses the game object layer */
|
|
9
31
|
layer?: string;
|
|
32
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
10
33
|
physics?: boolean;
|
|
34
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
11
35
|
debug?: boolean;
|
|
12
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Collider composed of lines defined by its vertices, for 2d collisions.
|
|
39
|
+
* @public
|
|
40
|
+
* @category Components
|
|
41
|
+
* @example
|
|
42
|
+
* ```js
|
|
43
|
+
* this.addComponent(EdgeCollider, {
|
|
44
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32)],
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* this.addComponent(EdgeCollider, {
|
|
50
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32)],
|
|
51
|
+
* rotation: new Rotation(0),
|
|
52
|
+
* offsetX: 0,
|
|
53
|
+
* offsetY: 0,
|
|
54
|
+
* layer: "Hills",
|
|
55
|
+
* debug: false,
|
|
56
|
+
* physics: true,
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
13
60
|
export declare class EdgeCollider extends BaseCollider {
|
|
61
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
14
62
|
debug: boolean;
|
|
63
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
15
64
|
vertexModel: Vector2[];
|
|
65
|
+
/** x-axis offset */
|
|
16
66
|
offsetX: number;
|
|
67
|
+
/** y-axis offset */
|
|
17
68
|
offsetY: number;
|
|
69
|
+
/** Rectangle rotation (degrees or radians) */
|
|
18
70
|
rotation: Rotation;
|
|
19
71
|
private scaledVertexModel;
|
|
20
72
|
private scaledOffset;
|
|
@@ -3,20 +3,72 @@ import { RenderComponent } from "../../core/Component";
|
|
|
3
3
|
import { InitOptions } from "../../core/GameActor";
|
|
4
4
|
import { Vector2, Rotation } from "angry-pixel-math";
|
|
5
5
|
import { ICollider } from "angry-pixel-2d-physics";
|
|
6
|
+
/**
|
|
7
|
+
* PolygonCollider configuration options
|
|
8
|
+
* @public
|
|
9
|
+
* @category Components
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
* this.addComponent(PolygonCollider, {
|
|
13
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32), new Vector2(64, 0)],
|
|
14
|
+
* rotation: new Rotation(0),
|
|
15
|
+
* offsetX: 0,
|
|
16
|
+
* offsetY: 0,
|
|
17
|
+
* layer: "Hills",
|
|
18
|
+
* debug: false,
|
|
19
|
+
* physics: true,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
6
23
|
export interface PolygonColliderOptions extends InitOptions {
|
|
24
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
7
25
|
vertexModel: Vector2[];
|
|
26
|
+
/** x-axis offset */
|
|
8
27
|
offsetX?: number;
|
|
28
|
+
/** y-axis offset */
|
|
9
29
|
offsetY?: number;
|
|
30
|
+
/** Edges rotation (degrees or radians) */
|
|
10
31
|
rotation?: Rotation;
|
|
32
|
+
/** Collision layer, if it's not setted, it uses the game object layer */
|
|
11
33
|
layer?: string;
|
|
34
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
12
35
|
physics?: boolean;
|
|
36
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
13
37
|
debug?: boolean;
|
|
14
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Polygon shaped Collider for 2d collisions. Only convex polygons are allowed.
|
|
41
|
+
* @public
|
|
42
|
+
* @category Components
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* this.addComponent(PolygonCollider, {
|
|
46
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32), new Vector2(64, 0)],
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* this.addComponent(PolygonCollider, {
|
|
52
|
+
* vertexModel: [new Vector2(0,0), new Vector2(32, 32), new Vector2(64, 0)],
|
|
53
|
+
* rotation: new Rotation(0),
|
|
54
|
+
* offsetX: 0,
|
|
55
|
+
* offsetY: 0,
|
|
56
|
+
* layer: "Hills",
|
|
57
|
+
* debug: false,
|
|
58
|
+
* physics: true,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
15
62
|
export declare class PolygonCollider extends BaseCollider {
|
|
63
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
16
64
|
debug: boolean;
|
|
65
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
17
66
|
vertexModel: Vector2[];
|
|
67
|
+
/** x-axis offset */
|
|
18
68
|
offsetX: number;
|
|
69
|
+
/** y-axis offset */
|
|
19
70
|
offsetY: number;
|
|
71
|
+
/** Rectangle rotation (degrees or radians) */
|
|
20
72
|
rotation: Rotation;
|
|
21
73
|
private scaledVertexModel;
|
|
22
74
|
private scaledOffset;
|
|
@@ -29,6 +81,7 @@ export declare class PolygonCollider extends BaseCollider {
|
|
|
29
81
|
private translate;
|
|
30
82
|
protected updateColliders(): void;
|
|
31
83
|
}
|
|
84
|
+
/** @private */
|
|
32
85
|
export declare class PolygonColliderRenderer extends RenderComponent {
|
|
33
86
|
private renderData;
|
|
34
87
|
private collider;
|
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
import { ITilemapRenderer } from "../rendering/TilemapRenderer";
|
|
2
2
|
import { BaseCollider } from "./Collider";
|
|
3
3
|
import { InitOptions } from "../../core/GameActor";
|
|
4
|
+
/**
|
|
5
|
+
* TilemapCollider configuration options
|
|
6
|
+
* @public
|
|
7
|
+
* @category Components
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* this.addComponent(TilemapCollider, {
|
|
11
|
+
* tilemapRenderer: this.getComponent(TilemapRenderer),
|
|
12
|
+
* layer: "Foreground",
|
|
13
|
+
* debug: false,
|
|
14
|
+
* composite: true,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
export interface TilemapColliderOptions extends InitOptions {
|
|
19
|
+
/** TilemapRenderer from which the tiles information will be obtained to generate the colliders */
|
|
5
20
|
tilemapRenderer: ITilemapRenderer;
|
|
21
|
+
/** Generate colliders that represent the outer lines of the tile map */
|
|
6
22
|
composite?: boolean;
|
|
23
|
+
/** Collision layer, if it's not setted, it uses the game object layer */
|
|
7
24
|
layer?: string;
|
|
25
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
8
26
|
debug?: boolean;
|
|
9
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Generates rectanble colliders for the map edge tiles (or lines if composite is TRUE).
|
|
30
|
+
* @public
|
|
31
|
+
* @category Components
|
|
32
|
+
* @example
|
|
33
|
+
* ```js
|
|
34
|
+
* this.addComponent(TilemapCollider, {
|
|
35
|
+
* tilemapRenderer: this.getComponent(TilemapRenderer),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
* @example
|
|
39
|
+
* ```js
|
|
40
|
+
* this.addComponent(TilemapCollider, {
|
|
41
|
+
* tilemapRenderer: this.getComponent(TilemapRenderer),
|
|
42
|
+
* layer: "Foreground",
|
|
43
|
+
* debug: false,
|
|
44
|
+
* composite: true,
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
10
48
|
export declare class TilemapCollider extends BaseCollider {
|
|
49
|
+
/** TilemapRenderer from which the tiles information will be obtained to generate the colliders */
|
|
11
50
|
private tilemapRenderer;
|
|
51
|
+
/** If debug mode is enabled, the collider shape is rendered using the object's render layer */
|
|
12
52
|
private debug;
|
|
53
|
+
/** Generate colliders that represent the outer lines of the tile map */
|
|
13
54
|
private composite;
|
|
14
55
|
private scaledWidth;
|
|
15
56
|
private scaledHeight;
|