+1
-1
@@ -27,7 +27,7 @@
|
|||||||
data-entry-class="Main"
|
data-entry-class="Main"
|
||||||
data-orientation="auto"
|
data-orientation="auto"
|
||||||
data-scale-mode="fixedWidth"
|
data-scale-mode="fixedWidth"
|
||||||
data-frame-rate="30"
|
data-frame-rate="60"
|
||||||
data-content-width="640"
|
data-content-width="640"
|
||||||
data-content-height="1136"
|
data-content-height="1136"
|
||||||
data-multi-fingered="2"
|
data-multi-fingered="2"
|
||||||
|
|||||||
Vendored
+98
-86
@@ -32,22 +32,22 @@ declare class AStarNode<T> extends PriorityQueueNode {
|
|||||||
data: T;
|
data: T;
|
||||||
constructor(data: T);
|
constructor(data: T);
|
||||||
}
|
}
|
||||||
declare class AstarGridGraph implements IAstarGraph<Point> {
|
declare class AstarGridGraph implements IAstarGraph<Vector2> {
|
||||||
dirs: Point[];
|
dirs: Vector2[];
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
weightedNodes: Point[];
|
weightedNodes: Vector2[];
|
||||||
defaultWeight: number;
|
defaultWeight: number;
|
||||||
weightedNodeWeight: number;
|
weightedNodeWeight: number;
|
||||||
private _width;
|
private _width;
|
||||||
private _height;
|
private _height;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number);
|
constructor(width: number, height: number);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
cost(from: Point, to: Point): number;
|
cost(from: Vector2, to: Vector2): number;
|
||||||
heuristic(node: Point, goal: Point): number;
|
heuristic(node: Vector2, goal: Vector2): number;
|
||||||
}
|
}
|
||||||
interface IAstarGraph<T> {
|
interface IAstarGraph<T> {
|
||||||
getNeighbors(node: T): Array<T>;
|
getNeighbors(node: T): Array<T>;
|
||||||
@@ -84,34 +84,57 @@ declare class UnweightedGraph<T> implements IUnweightedGraph<T> {
|
|||||||
addEdgesForNode(node: T, edges: T[]): this;
|
addEdgesForNode(node: T, edges: T[]): this;
|
||||||
getNeighbors(node: T): T[];
|
getNeighbors(node: T): T[];
|
||||||
}
|
}
|
||||||
declare class Point {
|
declare class Vector2 {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
private static readonly unitYVector;
|
||||||
|
private static readonly unitXVector;
|
||||||
|
private static readonly unitVector2;
|
||||||
|
private static readonly zeroVector2;
|
||||||
|
static readonly zero: Vector2;
|
||||||
|
static readonly one: Vector2;
|
||||||
|
static readonly unitX: Vector2;
|
||||||
|
static readonly unitY: Vector2;
|
||||||
constructor(x?: number, y?: number);
|
constructor(x?: number, y?: number);
|
||||||
|
static add(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static divide(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static multiply(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static subtract(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
normalize(): void;
|
||||||
|
length(): number;
|
||||||
|
round(): Vector2;
|
||||||
|
static normalize(value: Vector2): Vector2;
|
||||||
|
static dot(value1: Vector2, value2: Vector2): number;
|
||||||
|
static distanceSquared(value1: Vector2, value2: Vector2): number;
|
||||||
|
static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
|
||||||
|
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
||||||
|
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
||||||
|
static distance(value1: Vector2, value2: Vector2): number;
|
||||||
|
static negate(value: Vector2): Vector2;
|
||||||
}
|
}
|
||||||
declare class UnweightedGridGraph implements IUnweightedGraph<Point> {
|
declare class UnweightedGridGraph implements IUnweightedGraph<Vector2> {
|
||||||
private static readonly CARDINAL_DIRS;
|
private static readonly CARDINAL_DIRS;
|
||||||
private static readonly COMPASS_DIRS;
|
private static readonly COMPASS_DIRS;
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
private _width;
|
private _width;
|
||||||
private _hegiht;
|
private _hegiht;
|
||||||
private _dirs;
|
private _dirs;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
}
|
}
|
||||||
interface IWeightedGraph<T> {
|
interface IWeightedGraph<T> {
|
||||||
getNeighbors(node: T): T[];
|
getNeighbors(node: T): T[];
|
||||||
cost(from: T, to: T): number;
|
cost(from: T, to: T): number;
|
||||||
}
|
}
|
||||||
declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
declare class WeightedGridGraph implements IWeightedGraph<Vector2> {
|
||||||
static readonly CARDINAL_DIRS: Point[];
|
static readonly CARDINAL_DIRS: Vector2[];
|
||||||
private static readonly COMPASS_DIRS;
|
private static readonly COMPASS_DIRS;
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
weightedNodes: Point[];
|
weightedNodes: Vector2[];
|
||||||
defaultWeight: number;
|
defaultWeight: number;
|
||||||
weightedNodeWeight: number;
|
weightedNodeWeight: number;
|
||||||
private _width;
|
private _width;
|
||||||
@@ -119,11 +142,11 @@ declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
|||||||
private _dirs;
|
private _dirs;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
cost(from: Point, to: Point): number;
|
cost(from: Vector2, to: Vector2): number;
|
||||||
}
|
}
|
||||||
declare class WeightedNode<T> extends PriorityQueueNode {
|
declare class WeightedNode<T> extends PriorityQueueNode {
|
||||||
data: T;
|
data: T;
|
||||||
@@ -145,6 +168,7 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
updateInterval: number;
|
updateInterval: number;
|
||||||
userData: any;
|
userData: any;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
readonly localPosition: Vector2;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
onAddedToEntity(): void;
|
onAddedToEntity(): void;
|
||||||
@@ -153,12 +177,12 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
onDisabled(): void;
|
onDisabled(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
debugRender(): void;
|
debugRender(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
registerComponent(): void;
|
registerComponent(): void;
|
||||||
deregisterComponent(): void;
|
deregisterComponent(): void;
|
||||||
}
|
}
|
||||||
declare class Entity extends egret.DisplayObjectContainer {
|
declare class Entity extends egret.DisplayObjectContainer {
|
||||||
private static _idGenerator;
|
private static _idGenerator;
|
||||||
private _position;
|
|
||||||
name: string;
|
name: string;
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
@@ -171,11 +195,13 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
readonly isDestoryed: boolean;
|
readonly isDestoryed: boolean;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
rotation: number;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
tag: number;
|
tag: number;
|
||||||
readonly stage: egret.Stage;
|
readonly stage: egret.Stage;
|
||||||
constructor(name: string);
|
constructor(name: string);
|
||||||
|
private onAddToStage;
|
||||||
updateOrder: number;
|
updateOrder: number;
|
||||||
roundPosition(): void;
|
roundPosition(): void;
|
||||||
setUpdateOrder(updateOrder: number): this;
|
setUpdateOrder(updateOrder: number): this;
|
||||||
@@ -187,6 +213,7 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
getOrCreateComponent<T extends Component>(type: T): T;
|
getOrCreateComponent<T extends Component>(type: T): T;
|
||||||
getComponent<T extends Component>(type: any): T;
|
getComponent<T extends Component>(type: any): T;
|
||||||
getComponents(typeName: string | any, componentList?: any): any;
|
getComponents(typeName: string | any, componentList?: any): any;
|
||||||
|
private onEntityTransformChanged;
|
||||||
removeComponentForType<T extends Component>(type: any): boolean;
|
removeComponentForType<T extends Component>(type: any): boolean;
|
||||||
removeComponent(component: Component): void;
|
removeComponent(component: Component): void;
|
||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
@@ -195,6 +222,11 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
onRemovedFromScene(): void;
|
onRemovedFromScene(): void;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
declare enum TransformComponent {
|
||||||
|
rotation = 0,
|
||||||
|
scale = 1,
|
||||||
|
position = 2
|
||||||
|
}
|
||||||
declare class Scene extends egret.DisplayObjectContainer {
|
declare class Scene extends egret.DisplayObjectContainer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
readonly entities: EntityList;
|
readonly entities: EntityList;
|
||||||
@@ -244,6 +276,7 @@ declare class Camera extends Component {
|
|||||||
private _origin;
|
private _origin;
|
||||||
private _minimumZoom;
|
private _minimumZoom;
|
||||||
private _maximumZoom;
|
private _maximumZoom;
|
||||||
|
private _position;
|
||||||
followLerp: number;
|
followLerp: number;
|
||||||
deadzone: Rectangle;
|
deadzone: Rectangle;
|
||||||
focusOffset: Vector2;
|
focusOffset: Vector2;
|
||||||
@@ -259,6 +292,8 @@ declare class Camera extends Component {
|
|||||||
maximumZoom: number;
|
maximumZoom: number;
|
||||||
origin: Vector2;
|
origin: Vector2;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
constructor();
|
constructor();
|
||||||
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
setMinimumZoom(minZoom: number): Camera;
|
setMinimumZoom(minZoom: number): Camera;
|
||||||
@@ -325,11 +360,8 @@ declare class SpriteAnimation {
|
|||||||
constructor(sprites: Sprite[], frameRate: number);
|
constructor(sprites: Sprite[], frameRate: number);
|
||||||
}
|
}
|
||||||
declare class SpriteRenderer extends RenderableComponent {
|
declare class SpriteRenderer extends RenderableComponent {
|
||||||
private _origin;
|
|
||||||
private _sprite;
|
private _sprite;
|
||||||
protected bitmap: egret.Bitmap;
|
protected bitmap: egret.Bitmap;
|
||||||
origin: Vector2;
|
|
||||||
setOrigin(origin: Vector2): this;
|
|
||||||
sprite: Sprite;
|
sprite: Sprite;
|
||||||
setSprite(sprite: Sprite): SpriteRenderer;
|
setSprite(sprite: Sprite): SpriteRenderer;
|
||||||
setColor(color: number): SpriteRenderer;
|
setColor(color: number): SpriteRenderer;
|
||||||
@@ -385,7 +417,10 @@ interface ITriggerListener {
|
|||||||
declare class Mover extends Component {
|
declare class Mover extends Component {
|
||||||
private _triggerHelper;
|
private _triggerHelper;
|
||||||
onAddedToEntity(): void;
|
onAddedToEntity(): void;
|
||||||
calculateMovement(motion: Vector2): CollisionResult;
|
calculateMovement(motion: Vector2): {
|
||||||
|
collisionResult: CollisionResult;
|
||||||
|
motion: Vector2;
|
||||||
|
};
|
||||||
applyMovement(motion: Vector2): void;
|
applyMovement(motion: Vector2): void;
|
||||||
move(motion: Vector2): CollisionResult;
|
move(motion: Vector2): CollisionResult;
|
||||||
}
|
}
|
||||||
@@ -394,11 +429,9 @@ declare abstract class Collider extends Component {
|
|||||||
physicsLayer: number;
|
physicsLayer: number;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
registeredPhysicsBounds: Rectangle;
|
registeredPhysicsBounds: Rectangle;
|
||||||
shouldColliderScaleAndRotationWithTransform: boolean;
|
shouldColliderScaleAndRotateWithTransform: boolean;
|
||||||
collidesWithLayers: number;
|
collidesWithLayers: number;
|
||||||
_localOffsetLength: number;
|
_localOffsetLength: number;
|
||||||
_isPositionDirty: boolean;
|
|
||||||
_isRotationDirty: boolean;
|
|
||||||
protected _isParentEntityAddedToScene: any;
|
protected _isParentEntityAddedToScene: any;
|
||||||
protected _colliderRequiresAutoSizing: any;
|
protected _colliderRequiresAutoSizing: any;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
@@ -414,6 +447,8 @@ declare abstract class Collider extends Component {
|
|||||||
onRemovedFromEntity(): void;
|
onRemovedFromEntity(): void;
|
||||||
onEnabled(): void;
|
onEnabled(): void;
|
||||||
onDisabled(): void;
|
onDisabled(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
|
update(): void;
|
||||||
}
|
}
|
||||||
declare class BoxCollider extends Collider {
|
declare class BoxCollider extends Collider {
|
||||||
width: number;
|
width: number;
|
||||||
@@ -489,6 +524,7 @@ declare class ComponentList {
|
|||||||
deregisterAllComponents(): void;
|
deregisterAllComponents(): void;
|
||||||
registerAllComponents(): void;
|
registerAllComponents(): void;
|
||||||
updateLists(): void;
|
updateLists(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
private handleRemove;
|
private handleRemove;
|
||||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||||
getComponents(typeName: string | any, components?: any): any;
|
getComponents(typeName: string | any, components?: any): any;
|
||||||
@@ -668,7 +704,7 @@ declare abstract class SceneTransition {
|
|||||||
onBeginTransition(): Promise<void>;
|
onBeginTransition(): Promise<void>;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadNextScene(): Promise<void>;
|
protected loadNextScene(): Promise<void>;
|
||||||
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
|
||||||
}
|
}
|
||||||
declare class FadeTransition extends SceneTransition {
|
declare class FadeTransition extends SceneTransition {
|
||||||
fadeToColor: number;
|
fadeToColor: number;
|
||||||
@@ -731,66 +767,28 @@ declare class Matrix2D {
|
|||||||
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
|
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
|
||||||
determinant(): number;
|
determinant(): number;
|
||||||
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
|
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
|
||||||
static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D;
|
static createTranslation(xPosition: number, yPosition: number): Matrix2D;
|
||||||
|
static createTranslationVector(position: Vector2): Matrix2D;
|
||||||
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
|
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
|
||||||
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
|
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
|
||||||
toEgretMatrix(): egret.Matrix;
|
toEgretMatrix(): egret.Matrix;
|
||||||
}
|
}
|
||||||
declare class Rectangle {
|
declare class Rectangle extends egret.Rectangle {
|
||||||
x: number;
|
readonly max: Vector2;
|
||||||
y: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
private _tempMat;
|
|
||||||
private _transformMat;
|
|
||||||
readonly left: number;
|
|
||||||
readonly right: number;
|
|
||||||
readonly top: number;
|
|
||||||
readonly bottom: number;
|
|
||||||
readonly center: Vector2;
|
readonly center: Vector2;
|
||||||
location: Vector2;
|
location: Vector2;
|
||||||
size: Vector2;
|
size: Vector2;
|
||||||
constructor(x?: number, y?: number, width?: number, height?: number);
|
intersects(value: egret.Rectangle): boolean;
|
||||||
intersects(value: Rectangle): boolean;
|
|
||||||
contains(value: Vector2): boolean;
|
|
||||||
containsRect(value: Rectangle): boolean;
|
containsRect(value: Rectangle): boolean;
|
||||||
getHalfSize(): Vector2;
|
getHalfSize(): Vector2;
|
||||||
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
|
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
|
||||||
getClosestPointOnRectangleBorderToPoint(point: Point): {
|
getClosestPointOnRectangleBorderToPoint(point: Vector2): {
|
||||||
res: Vector2;
|
res: Vector2;
|
||||||
edgeNormal: Vector2;
|
edgeNormal: Vector2;
|
||||||
};
|
};
|
||||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
getClosestPointOnBoundsToOrigin(): Vector2;
|
||||||
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
||||||
}
|
}
|
||||||
declare class Vector2 {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
private static readonly unitYVector;
|
|
||||||
private static readonly unitXVector;
|
|
||||||
private static readonly unitVector2;
|
|
||||||
private static readonly zeroVector2;
|
|
||||||
static readonly zero: Vector2;
|
|
||||||
static readonly one: Vector2;
|
|
||||||
static readonly unitX: Vector2;
|
|
||||||
static readonly unitY: Vector2;
|
|
||||||
constructor(x?: number, y?: number);
|
|
||||||
static add(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static divide(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static multiply(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static subtract(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
normalize(): void;
|
|
||||||
length(): number;
|
|
||||||
round(): Vector2;
|
|
||||||
static normalize(value: Vector2): Vector2;
|
|
||||||
static dot(value1: Vector2, value2: Vector2): number;
|
|
||||||
static distanceSquared(value1: Vector2, value2: Vector2): number;
|
|
||||||
static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
|
|
||||||
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
|
||||||
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
|
||||||
static distance(value1: Vector2, value2: Vector2): number;
|
|
||||||
static negate(value: Vector2): Vector2;
|
|
||||||
}
|
|
||||||
declare class Vector3 {
|
declare class Vector3 {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -837,8 +835,14 @@ declare class Physics {
|
|||||||
static reset(): void;
|
static reset(): void;
|
||||||
static clear(): void;
|
static clear(): void;
|
||||||
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
|
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
|
||||||
static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[];
|
static boxcastBroadphase(rect: Rectangle, layerMask?: number): {
|
||||||
static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[];
|
colliders: Collider[];
|
||||||
|
rect: Rectangle;
|
||||||
|
};
|
||||||
|
static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): {
|
||||||
|
tempHashSet: Collider[];
|
||||||
|
bounds: Rectangle;
|
||||||
|
};
|
||||||
static addCollider(collider: Collider): void;
|
static addCollider(collider: Collider): void;
|
||||||
static removeCollider(collider: Collider): void;
|
static removeCollider(collider: Collider): void;
|
||||||
static updateCollider(collider: Collider): void;
|
static updateCollider(collider: Collider): void;
|
||||||
@@ -846,7 +850,7 @@ declare class Physics {
|
|||||||
declare abstract class Shape {
|
declare abstract class Shape {
|
||||||
bounds: Rectangle;
|
bounds: Rectangle;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
center: Vector2;
|
abstract center: Vector2;
|
||||||
abstract recalculateBounds(collider: Collider): any;
|
abstract recalculateBounds(collider: Collider): any;
|
||||||
abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||||
abstract overlaps(other: Shape): any;
|
abstract overlaps(other: Shape): any;
|
||||||
@@ -858,6 +862,7 @@ declare class Polygon extends Shape {
|
|||||||
private _polygonCenter;
|
private _polygonCenter;
|
||||||
private _areEdgeNormalsDirty;
|
private _areEdgeNormalsDirty;
|
||||||
protected _originalPoints: Vector2[];
|
protected _originalPoints: Vector2[];
|
||||||
|
center: Vector2;
|
||||||
_edgeNormals: Vector2[];
|
_edgeNormals: Vector2[];
|
||||||
readonly edgeNormals: Vector2[];
|
readonly edgeNormals: Vector2[];
|
||||||
isBox: boolean;
|
isBox: boolean;
|
||||||
@@ -883,12 +888,15 @@ declare class Box extends Polygon {
|
|||||||
height: number;
|
height: number;
|
||||||
constructor(width: number, height: number);
|
constructor(width: number, height: number);
|
||||||
private static buildBox;
|
private static buildBox;
|
||||||
|
overlaps(other: Shape): any;
|
||||||
|
collidesWithShape(other: Shape): any;
|
||||||
updateBox(width: number, height: number): void;
|
updateBox(width: number, height: number): void;
|
||||||
containsPoint(point: Vector2): boolean;
|
containsPoint(point: Vector2): boolean;
|
||||||
}
|
}
|
||||||
declare class Circle extends Shape {
|
declare class Circle extends Shape {
|
||||||
radius: number;
|
radius: number;
|
||||||
private _originalRadius;
|
private _originalRadius;
|
||||||
|
center: Vector2;
|
||||||
constructor(radius: number);
|
constructor(radius: number);
|
||||||
pointCollidesWithShape(point: Vector2): CollisionResult;
|
pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||||
collidesWithShape(other: Shape): CollisionResult;
|
collidesWithShape(other: Shape): CollisionResult;
|
||||||
@@ -915,6 +923,8 @@ declare class ShapeCollisions {
|
|||||||
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
||||||
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
|
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
|
||||||
static circleToCircle(first: Circle, second: Circle): CollisionResult;
|
static circleToCircle(first: Circle, second: Circle): CollisionResult;
|
||||||
|
static boxToBox(first: Box, second: Box): CollisionResult;
|
||||||
|
private static minkowskiDifference;
|
||||||
}
|
}
|
||||||
declare class SpatialHash {
|
declare class SpatialHash {
|
||||||
gridBounds: Rectangle;
|
gridBounds: Rectangle;
|
||||||
@@ -929,7 +939,10 @@ declare class SpatialHash {
|
|||||||
register(collider: Collider): void;
|
register(collider: Collider): void;
|
||||||
clear(): void;
|
clear(): void;
|
||||||
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
|
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
|
||||||
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[];
|
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): {
|
||||||
|
tempHashSet: Collider[];
|
||||||
|
bounds: Rectangle;
|
||||||
|
};
|
||||||
private cellAtPosition;
|
private cellAtPosition;
|
||||||
private cellCoords;
|
private cellCoords;
|
||||||
}
|
}
|
||||||
@@ -1017,8 +1030,7 @@ declare class Pair<T> {
|
|||||||
equals(other: Pair<T>): boolean;
|
equals(other: Pair<T>): boolean;
|
||||||
}
|
}
|
||||||
declare class RectangleExt {
|
declare class RectangleExt {
|
||||||
static union(first: Rectangle, point: Point): Rectangle;
|
static union(first: Rectangle, point: Vector2): Rectangle;
|
||||||
static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
|
|
||||||
}
|
}
|
||||||
declare class Triangulator {
|
declare class Triangulator {
|
||||||
triangleIndices: number[];
|
triangleIndices: number[];
|
||||||
|
|||||||
+354
-302
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+14
-14
@@ -14,14 +14,14 @@ class MainScene extends Scene {
|
|||||||
bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
|
bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
|
||||||
bg.addComponent(new PlayerController());
|
bg.addComponent(new PlayerController());
|
||||||
bg.addComponent(new Mover());
|
bg.addComponent(new Mover());
|
||||||
// bg.addComponent(new BoxCollider());
|
bg.addComponent(new BoxCollider());
|
||||||
bg.position = new Vector2(Math.random() * 200, Math.random() * 200);
|
bg.position = new Vector2(Math.random() * 300, Math.random() * 300);
|
||||||
|
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 20; i++) {
|
||||||
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
|
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
|
||||||
let player2 = this.createEntity("player2");
|
let player2 = this.createEntity("player2");
|
||||||
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
|
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
|
||||||
player2.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i);
|
player2.position = new Vector2(Math.random() * 1000, Math.random() * 1000);
|
||||||
player2.addComponent(new BoxCollider());
|
player2.addComponent(new BoxCollider());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,24 +63,24 @@ class MainScene extends Scene {
|
|||||||
public dijkstraTest() {
|
public dijkstraTest() {
|
||||||
let graph = new WeightedGridGraph(20, 20);
|
let graph = new WeightedGridGraph(20, 20);
|
||||||
|
|
||||||
graph.weightedNodes.push(new Point(3, 3));
|
graph.weightedNodes.push(new Vector2(3, 3));
|
||||||
graph.weightedNodes.push(new Point(3, 4));
|
graph.weightedNodes.push(new Vector2(3, 4));
|
||||||
graph.weightedNodes.push(new Point(4, 3));
|
graph.weightedNodes.push(new Vector2(4, 3));
|
||||||
graph.weightedNodes.push(new Point(4, 4));
|
graph.weightedNodes.push(new Vector2(4, 4));
|
||||||
|
|
||||||
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
|
||||||
console.log(path);
|
console.log(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public astarTest() {
|
public astarTest() {
|
||||||
let graph = new AstarGridGraph(20, 20);
|
let graph = new AstarGridGraph(20, 20);
|
||||||
|
|
||||||
graph.weightedNodes.push(new Point(3, 3));
|
graph.weightedNodes.push(new Vector2(3, 3));
|
||||||
graph.weightedNodes.push(new Point(3, 4));
|
graph.weightedNodes.push(new Vector2(3, 4));
|
||||||
graph.weightedNodes.push(new Point(4, 3));
|
graph.weightedNodes.push(new Vector2(4, 3));
|
||||||
graph.weightedNodes.push(new Point(4, 4));
|
graph.weightedNodes.push(new Vector2(4, 4));
|
||||||
|
|
||||||
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
|
||||||
console.log(path);
|
console.log(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,17 +37,17 @@ class PlayerController extends Component {
|
|||||||
let camera = SceneManager.scene.camera;
|
let camera = SceneManager.scene.camera;
|
||||||
let moveLeft: number = 0;
|
let moveLeft: number = 0;
|
||||||
let moveRight: number = 0;
|
let moveRight: number = 0;
|
||||||
let speed = 200;
|
let speed = 100;
|
||||||
let worldPos = Input.touchPosition;
|
let worldPos = Input.touchPosition;
|
||||||
if (worldPos.x < this.spriteRenderer.x){
|
if (worldPos.x < this.spriteRenderer.localPosition.x){
|
||||||
moveLeft = -1;
|
moveLeft = -1;
|
||||||
} else if(worldPos.x > this.spriteRenderer.x){
|
} else if(worldPos.x > this.spriteRenderer.localPosition.x){
|
||||||
moveLeft = 1;
|
moveLeft = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldPos.y < this.spriteRenderer.y){
|
if (worldPos.y < this.spriteRenderer.localPosition.y){
|
||||||
moveRight = -1;
|
moveRight = -1;
|
||||||
} else if(worldPos.y > this.spriteRenderer.y){
|
} else if(worldPos.y > this.spriteRenderer.localPosition.y){
|
||||||
moveRight = 1;
|
moveRight = 1;
|
||||||
}
|
}
|
||||||
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
|
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ egret_native.egretStart = function () {
|
|||||||
//The following is automatically modified, please do not modify
|
//The following is automatically modified, please do not modify
|
||||||
//----auto option start----
|
//----auto option start----
|
||||||
entryClassName: "Main",
|
entryClassName: "Main",
|
||||||
frameRate: 30,
|
frameRate: 60,
|
||||||
scaleMode: "fixedWidth",
|
scaleMode: "fixedWidth",
|
||||||
contentWidth: 640,
|
contentWidth: 640,
|
||||||
contentHeight: 1136,
|
contentHeight: 1136,
|
||||||
|
|||||||
Vendored
+98
-86
@@ -32,22 +32,22 @@ declare class AStarNode<T> extends PriorityQueueNode {
|
|||||||
data: T;
|
data: T;
|
||||||
constructor(data: T);
|
constructor(data: T);
|
||||||
}
|
}
|
||||||
declare class AstarGridGraph implements IAstarGraph<Point> {
|
declare class AstarGridGraph implements IAstarGraph<Vector2> {
|
||||||
dirs: Point[];
|
dirs: Vector2[];
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
weightedNodes: Point[];
|
weightedNodes: Vector2[];
|
||||||
defaultWeight: number;
|
defaultWeight: number;
|
||||||
weightedNodeWeight: number;
|
weightedNodeWeight: number;
|
||||||
private _width;
|
private _width;
|
||||||
private _height;
|
private _height;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number);
|
constructor(width: number, height: number);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
cost(from: Point, to: Point): number;
|
cost(from: Vector2, to: Vector2): number;
|
||||||
heuristic(node: Point, goal: Point): number;
|
heuristic(node: Vector2, goal: Vector2): number;
|
||||||
}
|
}
|
||||||
interface IAstarGraph<T> {
|
interface IAstarGraph<T> {
|
||||||
getNeighbors(node: T): Array<T>;
|
getNeighbors(node: T): Array<T>;
|
||||||
@@ -84,34 +84,57 @@ declare class UnweightedGraph<T> implements IUnweightedGraph<T> {
|
|||||||
addEdgesForNode(node: T, edges: T[]): this;
|
addEdgesForNode(node: T, edges: T[]): this;
|
||||||
getNeighbors(node: T): T[];
|
getNeighbors(node: T): T[];
|
||||||
}
|
}
|
||||||
declare class Point {
|
declare class Vector2 {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
private static readonly unitYVector;
|
||||||
|
private static readonly unitXVector;
|
||||||
|
private static readonly unitVector2;
|
||||||
|
private static readonly zeroVector2;
|
||||||
|
static readonly zero: Vector2;
|
||||||
|
static readonly one: Vector2;
|
||||||
|
static readonly unitX: Vector2;
|
||||||
|
static readonly unitY: Vector2;
|
||||||
constructor(x?: number, y?: number);
|
constructor(x?: number, y?: number);
|
||||||
|
static add(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static divide(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static multiply(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
static subtract(value1: Vector2, value2: Vector2): Vector2;
|
||||||
|
normalize(): void;
|
||||||
|
length(): number;
|
||||||
|
round(): Vector2;
|
||||||
|
static normalize(value: Vector2): Vector2;
|
||||||
|
static dot(value1: Vector2, value2: Vector2): number;
|
||||||
|
static distanceSquared(value1: Vector2, value2: Vector2): number;
|
||||||
|
static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
|
||||||
|
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
||||||
|
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
||||||
|
static distance(value1: Vector2, value2: Vector2): number;
|
||||||
|
static negate(value: Vector2): Vector2;
|
||||||
}
|
}
|
||||||
declare class UnweightedGridGraph implements IUnweightedGraph<Point> {
|
declare class UnweightedGridGraph implements IUnweightedGraph<Vector2> {
|
||||||
private static readonly CARDINAL_DIRS;
|
private static readonly CARDINAL_DIRS;
|
||||||
private static readonly COMPASS_DIRS;
|
private static readonly COMPASS_DIRS;
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
private _width;
|
private _width;
|
||||||
private _hegiht;
|
private _hegiht;
|
||||||
private _dirs;
|
private _dirs;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
}
|
}
|
||||||
interface IWeightedGraph<T> {
|
interface IWeightedGraph<T> {
|
||||||
getNeighbors(node: T): T[];
|
getNeighbors(node: T): T[];
|
||||||
cost(from: T, to: T): number;
|
cost(from: T, to: T): number;
|
||||||
}
|
}
|
||||||
declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
declare class WeightedGridGraph implements IWeightedGraph<Vector2> {
|
||||||
static readonly CARDINAL_DIRS: Point[];
|
static readonly CARDINAL_DIRS: Vector2[];
|
||||||
private static readonly COMPASS_DIRS;
|
private static readonly COMPASS_DIRS;
|
||||||
walls: Point[];
|
walls: Vector2[];
|
||||||
weightedNodes: Point[];
|
weightedNodes: Vector2[];
|
||||||
defaultWeight: number;
|
defaultWeight: number;
|
||||||
weightedNodeWeight: number;
|
weightedNodeWeight: number;
|
||||||
private _width;
|
private _width;
|
||||||
@@ -119,11 +142,11 @@ declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
|||||||
private _dirs;
|
private _dirs;
|
||||||
private _neighbors;
|
private _neighbors;
|
||||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||||
isNodeInBounds(node: Point): boolean;
|
isNodeInBounds(node: Vector2): boolean;
|
||||||
isNodePassable(node: Point): boolean;
|
isNodePassable(node: Vector2): boolean;
|
||||||
search(start: Point, goal: Point): Point[];
|
search(start: Vector2, goal: Vector2): Vector2[];
|
||||||
getNeighbors(node: Point): Point[];
|
getNeighbors(node: Vector2): Vector2[];
|
||||||
cost(from: Point, to: Point): number;
|
cost(from: Vector2, to: Vector2): number;
|
||||||
}
|
}
|
||||||
declare class WeightedNode<T> extends PriorityQueueNode {
|
declare class WeightedNode<T> extends PriorityQueueNode {
|
||||||
data: T;
|
data: T;
|
||||||
@@ -145,6 +168,7 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
updateInterval: number;
|
updateInterval: number;
|
||||||
userData: any;
|
userData: any;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
readonly localPosition: Vector2;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
onAddedToEntity(): void;
|
onAddedToEntity(): void;
|
||||||
@@ -153,12 +177,12 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
onDisabled(): void;
|
onDisabled(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
debugRender(): void;
|
debugRender(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
registerComponent(): void;
|
registerComponent(): void;
|
||||||
deregisterComponent(): void;
|
deregisterComponent(): void;
|
||||||
}
|
}
|
||||||
declare class Entity extends egret.DisplayObjectContainer {
|
declare class Entity extends egret.DisplayObjectContainer {
|
||||||
private static _idGenerator;
|
private static _idGenerator;
|
||||||
private _position;
|
|
||||||
name: string;
|
name: string;
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
@@ -171,11 +195,13 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
readonly isDestoryed: boolean;
|
readonly isDestoryed: boolean;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
rotation: number;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
tag: number;
|
tag: number;
|
||||||
readonly stage: egret.Stage;
|
readonly stage: egret.Stage;
|
||||||
constructor(name: string);
|
constructor(name: string);
|
||||||
|
private onAddToStage;
|
||||||
updateOrder: number;
|
updateOrder: number;
|
||||||
roundPosition(): void;
|
roundPosition(): void;
|
||||||
setUpdateOrder(updateOrder: number): this;
|
setUpdateOrder(updateOrder: number): this;
|
||||||
@@ -187,6 +213,7 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
getOrCreateComponent<T extends Component>(type: T): T;
|
getOrCreateComponent<T extends Component>(type: T): T;
|
||||||
getComponent<T extends Component>(type: any): T;
|
getComponent<T extends Component>(type: any): T;
|
||||||
getComponents(typeName: string | any, componentList?: any): any;
|
getComponents(typeName: string | any, componentList?: any): any;
|
||||||
|
private onEntityTransformChanged;
|
||||||
removeComponentForType<T extends Component>(type: any): boolean;
|
removeComponentForType<T extends Component>(type: any): boolean;
|
||||||
removeComponent(component: Component): void;
|
removeComponent(component: Component): void;
|
||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
@@ -195,6 +222,11 @@ declare class Entity extends egret.DisplayObjectContainer {
|
|||||||
onRemovedFromScene(): void;
|
onRemovedFromScene(): void;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
declare enum TransformComponent {
|
||||||
|
rotation = 0,
|
||||||
|
scale = 1,
|
||||||
|
position = 2
|
||||||
|
}
|
||||||
declare class Scene extends egret.DisplayObjectContainer {
|
declare class Scene extends egret.DisplayObjectContainer {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
readonly entities: EntityList;
|
readonly entities: EntityList;
|
||||||
@@ -244,6 +276,7 @@ declare class Camera extends Component {
|
|||||||
private _origin;
|
private _origin;
|
||||||
private _minimumZoom;
|
private _minimumZoom;
|
||||||
private _maximumZoom;
|
private _maximumZoom;
|
||||||
|
private _position;
|
||||||
followLerp: number;
|
followLerp: number;
|
||||||
deadzone: Rectangle;
|
deadzone: Rectangle;
|
||||||
focusOffset: Vector2;
|
focusOffset: Vector2;
|
||||||
@@ -259,6 +292,8 @@ declare class Camera extends Component {
|
|||||||
maximumZoom: number;
|
maximumZoom: number;
|
||||||
origin: Vector2;
|
origin: Vector2;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
constructor();
|
constructor();
|
||||||
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
||||||
setMinimumZoom(minZoom: number): Camera;
|
setMinimumZoom(minZoom: number): Camera;
|
||||||
@@ -325,11 +360,8 @@ declare class SpriteAnimation {
|
|||||||
constructor(sprites: Sprite[], frameRate: number);
|
constructor(sprites: Sprite[], frameRate: number);
|
||||||
}
|
}
|
||||||
declare class SpriteRenderer extends RenderableComponent {
|
declare class SpriteRenderer extends RenderableComponent {
|
||||||
private _origin;
|
|
||||||
private _sprite;
|
private _sprite;
|
||||||
protected bitmap: egret.Bitmap;
|
protected bitmap: egret.Bitmap;
|
||||||
origin: Vector2;
|
|
||||||
setOrigin(origin: Vector2): this;
|
|
||||||
sprite: Sprite;
|
sprite: Sprite;
|
||||||
setSprite(sprite: Sprite): SpriteRenderer;
|
setSprite(sprite: Sprite): SpriteRenderer;
|
||||||
setColor(color: number): SpriteRenderer;
|
setColor(color: number): SpriteRenderer;
|
||||||
@@ -385,7 +417,10 @@ interface ITriggerListener {
|
|||||||
declare class Mover extends Component {
|
declare class Mover extends Component {
|
||||||
private _triggerHelper;
|
private _triggerHelper;
|
||||||
onAddedToEntity(): void;
|
onAddedToEntity(): void;
|
||||||
calculateMovement(motion: Vector2): CollisionResult;
|
calculateMovement(motion: Vector2): {
|
||||||
|
collisionResult: CollisionResult;
|
||||||
|
motion: Vector2;
|
||||||
|
};
|
||||||
applyMovement(motion: Vector2): void;
|
applyMovement(motion: Vector2): void;
|
||||||
move(motion: Vector2): CollisionResult;
|
move(motion: Vector2): CollisionResult;
|
||||||
}
|
}
|
||||||
@@ -394,11 +429,9 @@ declare abstract class Collider extends Component {
|
|||||||
physicsLayer: number;
|
physicsLayer: number;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
registeredPhysicsBounds: Rectangle;
|
registeredPhysicsBounds: Rectangle;
|
||||||
shouldColliderScaleAndRotationWithTransform: boolean;
|
shouldColliderScaleAndRotateWithTransform: boolean;
|
||||||
collidesWithLayers: number;
|
collidesWithLayers: number;
|
||||||
_localOffsetLength: number;
|
_localOffsetLength: number;
|
||||||
_isPositionDirty: boolean;
|
|
||||||
_isRotationDirty: boolean;
|
|
||||||
protected _isParentEntityAddedToScene: any;
|
protected _isParentEntityAddedToScene: any;
|
||||||
protected _colliderRequiresAutoSizing: any;
|
protected _colliderRequiresAutoSizing: any;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
@@ -414,6 +447,8 @@ declare abstract class Collider extends Component {
|
|||||||
onRemovedFromEntity(): void;
|
onRemovedFromEntity(): void;
|
||||||
onEnabled(): void;
|
onEnabled(): void;
|
||||||
onDisabled(): void;
|
onDisabled(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
|
update(): void;
|
||||||
}
|
}
|
||||||
declare class BoxCollider extends Collider {
|
declare class BoxCollider extends Collider {
|
||||||
width: number;
|
width: number;
|
||||||
@@ -489,6 +524,7 @@ declare class ComponentList {
|
|||||||
deregisterAllComponents(): void;
|
deregisterAllComponents(): void;
|
||||||
registerAllComponents(): void;
|
registerAllComponents(): void;
|
||||||
updateLists(): void;
|
updateLists(): void;
|
||||||
|
onEntityTransformChanged(comp: TransformComponent): void;
|
||||||
private handleRemove;
|
private handleRemove;
|
||||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||||
getComponents(typeName: string | any, components?: any): any;
|
getComponents(typeName: string | any, components?: any): any;
|
||||||
@@ -668,7 +704,7 @@ declare abstract class SceneTransition {
|
|||||||
onBeginTransition(): Promise<void>;
|
onBeginTransition(): Promise<void>;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadNextScene(): Promise<void>;
|
protected loadNextScene(): Promise<void>;
|
||||||
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
|
||||||
}
|
}
|
||||||
declare class FadeTransition extends SceneTransition {
|
declare class FadeTransition extends SceneTransition {
|
||||||
fadeToColor: number;
|
fadeToColor: number;
|
||||||
@@ -731,66 +767,28 @@ declare class Matrix2D {
|
|||||||
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
|
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
|
||||||
determinant(): number;
|
determinant(): number;
|
||||||
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
|
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
|
||||||
static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D;
|
static createTranslation(xPosition: number, yPosition: number): Matrix2D;
|
||||||
|
static createTranslationVector(position: Vector2): Matrix2D;
|
||||||
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
|
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
|
||||||
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
|
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
|
||||||
toEgretMatrix(): egret.Matrix;
|
toEgretMatrix(): egret.Matrix;
|
||||||
}
|
}
|
||||||
declare class Rectangle {
|
declare class Rectangle extends egret.Rectangle {
|
||||||
x: number;
|
readonly max: Vector2;
|
||||||
y: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
private _tempMat;
|
|
||||||
private _transformMat;
|
|
||||||
readonly left: number;
|
|
||||||
readonly right: number;
|
|
||||||
readonly top: number;
|
|
||||||
readonly bottom: number;
|
|
||||||
readonly center: Vector2;
|
readonly center: Vector2;
|
||||||
location: Vector2;
|
location: Vector2;
|
||||||
size: Vector2;
|
size: Vector2;
|
||||||
constructor(x?: number, y?: number, width?: number, height?: number);
|
intersects(value: egret.Rectangle): boolean;
|
||||||
intersects(value: Rectangle): boolean;
|
|
||||||
contains(value: Vector2): boolean;
|
|
||||||
containsRect(value: Rectangle): boolean;
|
containsRect(value: Rectangle): boolean;
|
||||||
getHalfSize(): Vector2;
|
getHalfSize(): Vector2;
|
||||||
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
|
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
|
||||||
getClosestPointOnRectangleBorderToPoint(point: Point): {
|
getClosestPointOnRectangleBorderToPoint(point: Vector2): {
|
||||||
res: Vector2;
|
res: Vector2;
|
||||||
edgeNormal: Vector2;
|
edgeNormal: Vector2;
|
||||||
};
|
};
|
||||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
getClosestPointOnBoundsToOrigin(): Vector2;
|
||||||
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
||||||
}
|
}
|
||||||
declare class Vector2 {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
private static readonly unitYVector;
|
|
||||||
private static readonly unitXVector;
|
|
||||||
private static readonly unitVector2;
|
|
||||||
private static readonly zeroVector2;
|
|
||||||
static readonly zero: Vector2;
|
|
||||||
static readonly one: Vector2;
|
|
||||||
static readonly unitX: Vector2;
|
|
||||||
static readonly unitY: Vector2;
|
|
||||||
constructor(x?: number, y?: number);
|
|
||||||
static add(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static divide(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static multiply(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
static subtract(value1: Vector2, value2: Vector2): Vector2;
|
|
||||||
normalize(): void;
|
|
||||||
length(): number;
|
|
||||||
round(): Vector2;
|
|
||||||
static normalize(value: Vector2): Vector2;
|
|
||||||
static dot(value1: Vector2, value2: Vector2): number;
|
|
||||||
static distanceSquared(value1: Vector2, value2: Vector2): number;
|
|
||||||
static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
|
|
||||||
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
|
||||||
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
|
||||||
static distance(value1: Vector2, value2: Vector2): number;
|
|
||||||
static negate(value: Vector2): Vector2;
|
|
||||||
}
|
|
||||||
declare class Vector3 {
|
declare class Vector3 {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -837,8 +835,14 @@ declare class Physics {
|
|||||||
static reset(): void;
|
static reset(): void;
|
||||||
static clear(): void;
|
static clear(): void;
|
||||||
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
|
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
|
||||||
static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[];
|
static boxcastBroadphase(rect: Rectangle, layerMask?: number): {
|
||||||
static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[];
|
colliders: Collider[];
|
||||||
|
rect: Rectangle;
|
||||||
|
};
|
||||||
|
static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): {
|
||||||
|
tempHashSet: Collider[];
|
||||||
|
bounds: Rectangle;
|
||||||
|
};
|
||||||
static addCollider(collider: Collider): void;
|
static addCollider(collider: Collider): void;
|
||||||
static removeCollider(collider: Collider): void;
|
static removeCollider(collider: Collider): void;
|
||||||
static updateCollider(collider: Collider): void;
|
static updateCollider(collider: Collider): void;
|
||||||
@@ -846,7 +850,7 @@ declare class Physics {
|
|||||||
declare abstract class Shape {
|
declare abstract class Shape {
|
||||||
bounds: Rectangle;
|
bounds: Rectangle;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
center: Vector2;
|
abstract center: Vector2;
|
||||||
abstract recalculateBounds(collider: Collider): any;
|
abstract recalculateBounds(collider: Collider): any;
|
||||||
abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||||
abstract overlaps(other: Shape): any;
|
abstract overlaps(other: Shape): any;
|
||||||
@@ -858,6 +862,7 @@ declare class Polygon extends Shape {
|
|||||||
private _polygonCenter;
|
private _polygonCenter;
|
||||||
private _areEdgeNormalsDirty;
|
private _areEdgeNormalsDirty;
|
||||||
protected _originalPoints: Vector2[];
|
protected _originalPoints: Vector2[];
|
||||||
|
center: Vector2;
|
||||||
_edgeNormals: Vector2[];
|
_edgeNormals: Vector2[];
|
||||||
readonly edgeNormals: Vector2[];
|
readonly edgeNormals: Vector2[];
|
||||||
isBox: boolean;
|
isBox: boolean;
|
||||||
@@ -883,12 +888,15 @@ declare class Box extends Polygon {
|
|||||||
height: number;
|
height: number;
|
||||||
constructor(width: number, height: number);
|
constructor(width: number, height: number);
|
||||||
private static buildBox;
|
private static buildBox;
|
||||||
|
overlaps(other: Shape): any;
|
||||||
|
collidesWithShape(other: Shape): any;
|
||||||
updateBox(width: number, height: number): void;
|
updateBox(width: number, height: number): void;
|
||||||
containsPoint(point: Vector2): boolean;
|
containsPoint(point: Vector2): boolean;
|
||||||
}
|
}
|
||||||
declare class Circle extends Shape {
|
declare class Circle extends Shape {
|
||||||
radius: number;
|
radius: number;
|
||||||
private _originalRadius;
|
private _originalRadius;
|
||||||
|
center: Vector2;
|
||||||
constructor(radius: number);
|
constructor(radius: number);
|
||||||
pointCollidesWithShape(point: Vector2): CollisionResult;
|
pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||||
collidesWithShape(other: Shape): CollisionResult;
|
collidesWithShape(other: Shape): CollisionResult;
|
||||||
@@ -915,6 +923,8 @@ declare class ShapeCollisions {
|
|||||||
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
||||||
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
|
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
|
||||||
static circleToCircle(first: Circle, second: Circle): CollisionResult;
|
static circleToCircle(first: Circle, second: Circle): CollisionResult;
|
||||||
|
static boxToBox(first: Box, second: Box): CollisionResult;
|
||||||
|
private static minkowskiDifference;
|
||||||
}
|
}
|
||||||
declare class SpatialHash {
|
declare class SpatialHash {
|
||||||
gridBounds: Rectangle;
|
gridBounds: Rectangle;
|
||||||
@@ -929,7 +939,10 @@ declare class SpatialHash {
|
|||||||
register(collider: Collider): void;
|
register(collider: Collider): void;
|
||||||
clear(): void;
|
clear(): void;
|
||||||
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
|
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
|
||||||
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[];
|
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): {
|
||||||
|
tempHashSet: Collider[];
|
||||||
|
bounds: Rectangle;
|
||||||
|
};
|
||||||
private cellAtPosition;
|
private cellAtPosition;
|
||||||
private cellCoords;
|
private cellCoords;
|
||||||
}
|
}
|
||||||
@@ -1017,8 +1030,7 @@ declare class Pair<T> {
|
|||||||
equals(other: Pair<T>): boolean;
|
equals(other: Pair<T>): boolean;
|
||||||
}
|
}
|
||||||
declare class RectangleExt {
|
declare class RectangleExt {
|
||||||
static union(first: Rectangle, point: Point): Rectangle;
|
static union(first: Rectangle, point: Vector2): Rectangle;
|
||||||
static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
|
|
||||||
}
|
}
|
||||||
declare class Triangulator {
|
declare class Triangulator {
|
||||||
triangleIndices: number[];
|
triangleIndices: number[];
|
||||||
|
|||||||
+354
-302
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -2,22 +2,22 @@
|
|||||||
* 基本静态网格图与A*一起使用
|
* 基本静态网格图与A*一起使用
|
||||||
* 将walls添加到walls HashSet,并将加权节点添加到weightedNodes
|
* 将walls添加到walls HashSet,并将加权节点添加到weightedNodes
|
||||||
*/
|
*/
|
||||||
class AstarGridGraph implements IAstarGraph<Point> {
|
class AstarGridGraph implements IAstarGraph<Vector2> {
|
||||||
public dirs: Point[] = [
|
public dirs: Vector2[] = [
|
||||||
new Point(1, 0),
|
new Vector2(1, 0),
|
||||||
new Point(0, -1),
|
new Vector2(0, -1),
|
||||||
new Point(-1, 0),
|
new Vector2(-1, 0),
|
||||||
new Point(0, 1)
|
new Vector2(0, 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
public walls: Point[] = [];
|
public walls: Vector2[] = [];
|
||||||
public weightedNodes: Point[] = [];
|
public weightedNodes: Vector2[] = [];
|
||||||
public defaultWeight: number = 1;
|
public defaultWeight: number = 1;
|
||||||
public weightedNodeWeight = 5;
|
public weightedNodeWeight = 5;
|
||||||
|
|
||||||
private _width;
|
private _width;
|
||||||
private _height;
|
private _height;
|
||||||
private _neighbors: Point[] = new Array(4);
|
private _neighbors: Vector2[] = new Array(4);
|
||||||
|
|
||||||
constructor(width: number, height: number){
|
constructor(width: number, height: number){
|
||||||
this._width = width;
|
this._width = width;
|
||||||
@@ -28,7 +28,7 @@ class AstarGridGraph implements IAstarGraph<Point> {
|
|||||||
* 确保节点在网格图的边界内
|
* 确保节点在网格图的边界内
|
||||||
* @param node
|
* @param node
|
||||||
*/
|
*/
|
||||||
public isNodeInBounds(node: Point): boolean {
|
public isNodeInBounds(node: Vector2): boolean {
|
||||||
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,19 +36,19 @@ class AstarGridGraph implements IAstarGraph<Point> {
|
|||||||
* 检查节点是否可以通过。墙壁是不可逾越的。
|
* 检查节点是否可以通过。墙壁是不可逾越的。
|
||||||
* @param node
|
* @param node
|
||||||
*/
|
*/
|
||||||
public isNodePassable(node: Point): boolean {
|
public isNodePassable(node: Vector2): boolean {
|
||||||
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public search(start: Point, goal: Point){
|
public search(start: Vector2, goal: Vector2){
|
||||||
return AStarPathfinder.search(this, start, goal);
|
return AStarPathfinder.search(this, start, goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNeighbors(node: Point): Point[] {
|
public getNeighbors(node: Vector2): Vector2[] {
|
||||||
this._neighbors.length = 0;
|
this._neighbors.length = 0;
|
||||||
|
|
||||||
this.dirs.forEach(dir => {
|
this.dirs.forEach(dir => {
|
||||||
let next = new Point(node.x + dir.x, node.y + dir.y);
|
let next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||||
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
||||||
this._neighbors.push(next);
|
this._neighbors.push(next);
|
||||||
});
|
});
|
||||||
@@ -56,11 +56,11 @@ class AstarGridGraph implements IAstarGraph<Point> {
|
|||||||
return this._neighbors;
|
return this._neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cost(from: Point, to: Point): number {
|
public cost(from: Vector2, to: Vector2): number {
|
||||||
return this.weightedNodes.find((p)=> JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
return this.weightedNodes.find((p)=> JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public heuristic(node: Point, goal: Point) {
|
public heuristic(node: Vector2, goal: Vector2) {
|
||||||
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
///<reference path="../../../Math/Point.ts" />
|
///<reference path="../../../Math/Vector2.ts" />
|
||||||
/**
|
/**
|
||||||
* 基本的未加权网格图形用于BreadthFirstPathfinder
|
* 基本的未加权网格图形用于BreadthFirstPathfinder
|
||||||
*/
|
*/
|
||||||
class UnweightedGridGraph implements IUnweightedGraph<Point> {
|
class UnweightedGridGraph implements IUnweightedGraph<Vector2> {
|
||||||
private static readonly CARDINAL_DIRS: Point[] = [
|
private static readonly CARDINAL_DIRS: Vector2[] = [
|
||||||
new Point(1, 0),
|
new Vector2(1, 0),
|
||||||
new Point(0, -1),
|
new Vector2(0, -1),
|
||||||
new Point(-1, 0),
|
new Vector2(-1, 0),
|
||||||
new Point(0, -1)
|
new Vector2(0, -1)
|
||||||
];
|
];
|
||||||
|
|
||||||
private static readonly COMPASS_DIRS = [
|
private static readonly COMPASS_DIRS = [
|
||||||
new Point(1, 0),
|
new Vector2(1, 0),
|
||||||
new Point(1, -1),
|
new Vector2(1, -1),
|
||||||
new Point(0, -1),
|
new Vector2(0, -1),
|
||||||
new Point(-1, -1),
|
new Vector2(-1, -1),
|
||||||
new Point(-1, 0),
|
new Vector2(-1, 0),
|
||||||
new Point(-1, 1),
|
new Vector2(-1, 1),
|
||||||
new Point(0, 1),
|
new Vector2(0, 1),
|
||||||
new Point(1, 1),
|
new Vector2(1, 1),
|
||||||
];
|
];
|
||||||
|
|
||||||
public walls: Point[] = [];
|
public walls: Vector2[] = [];
|
||||||
|
|
||||||
private _width: number;
|
private _width: number;
|
||||||
private _hegiht: number;
|
private _hegiht: number;
|
||||||
|
|
||||||
private _dirs: Point[];
|
private _dirs: Vector2[];
|
||||||
private _neighbors: Point[] = new Array(4);
|
private _neighbors: Vector2[] = new Array(4);
|
||||||
|
|
||||||
constructor(width: number, height: number, allowDiagonalSearch: boolean = false) {
|
constructor(width: number, height: number, allowDiagonalSearch: boolean = false) {
|
||||||
this._width = width;
|
this._width = width;
|
||||||
@@ -35,19 +35,19 @@ class UnweightedGridGraph implements IUnweightedGraph<Point> {
|
|||||||
this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS;
|
this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isNodeInBounds(node: Point): boolean {
|
public isNodeInBounds(node: Vector2): boolean {
|
||||||
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht;
|
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isNodePassable(node: Point): boolean {
|
public isNodePassable(node: Vector2): boolean {
|
||||||
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNeighbors(node: Point) {
|
public getNeighbors(node: Vector2) {
|
||||||
this._neighbors.length = 0;
|
this._neighbors.length = 0;
|
||||||
|
|
||||||
this._dirs.forEach(dir => {
|
this._dirs.forEach(dir => {
|
||||||
let next = new Point(node.x + dir.x, node.y + dir.y);
|
let next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||||
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
||||||
this._neighbors.push(next);
|
this._neighbors.push(next);
|
||||||
});
|
});
|
||||||
@@ -55,7 +55,7 @@ class UnweightedGridGraph implements IUnweightedGraph<Point> {
|
|||||||
return this._neighbors;
|
return this._neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public search(start: Point, goal: Point): Point[] {
|
public search(start: Vector2, goal: Vector2): Vector2[] {
|
||||||
return BreadthFirstPathfinder.search(this, start, goal);
|
return BreadthFirstPathfinder.search(this, start, goal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,35 @@
|
|||||||
///<reference path="../../../Math/Point.ts" />
|
///<reference path="../../../Math/Vector2.ts" />
|
||||||
/**
|
/**
|
||||||
* 支持一种加权节点的基本网格图
|
* 支持一种加权节点的基本网格图
|
||||||
*/
|
*/
|
||||||
class WeightedGridGraph implements IWeightedGraph<Point> {
|
class WeightedGridGraph implements IWeightedGraph<Vector2> {
|
||||||
public static readonly CARDINAL_DIRS = [
|
public static readonly CARDINAL_DIRS = [
|
||||||
new Point(1, 0),
|
new Vector2(1, 0),
|
||||||
new Point(0, -1),
|
new Vector2(0, -1),
|
||||||
new Point(-1, 0),
|
new Vector2(-1, 0),
|
||||||
new Point(0, 1)
|
new Vector2(0, 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
private static readonly COMPASS_DIRS = [
|
private static readonly COMPASS_DIRS = [
|
||||||
new Point(1, 0),
|
new Vector2(1, 0),
|
||||||
new Point(1, -1),
|
new Vector2(1, -1),
|
||||||
new Point(0, -1),
|
new Vector2(0, -1),
|
||||||
new Point(-1, -1),
|
new Vector2(-1, -1),
|
||||||
new Point(-1, 0),
|
new Vector2(-1, 0),
|
||||||
new Point(-1, 1),
|
new Vector2(-1, 1),
|
||||||
new Point(0, 1),
|
new Vector2(0, 1),
|
||||||
new Point(1, 1),
|
new Vector2(1, 1),
|
||||||
];
|
];
|
||||||
|
|
||||||
public walls: Point[] = [];
|
public walls: Vector2[] = [];
|
||||||
public weightedNodes: Point[] = [];
|
public weightedNodes: Vector2[] = [];
|
||||||
public defaultWeight = 1;
|
public defaultWeight = 1;
|
||||||
public weightedNodeWeight = 5;
|
public weightedNodeWeight = 5;
|
||||||
|
|
||||||
private _width: number;
|
private _width: number;
|
||||||
private _height: number;
|
private _height: number;
|
||||||
private _dirs: Point[];
|
private _dirs: Vector2[];
|
||||||
private _neighbors: Point[] = new Array(4);
|
private _neighbors: Vector2[] = new Array(4);
|
||||||
|
|
||||||
constructor(width: number, height: number, allowDiagonalSearch: boolean = false){
|
constructor(width: number, height: number, allowDiagonalSearch: boolean = false){
|
||||||
this._width = width;
|
this._width = width;
|
||||||
@@ -37,23 +37,23 @@ class WeightedGridGraph implements IWeightedGraph<Point> {
|
|||||||
this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS;
|
this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isNodeInBounds(node: Point){
|
public isNodeInBounds(node: Vector2){
|
||||||
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isNodePassable(node: Point): boolean {
|
public isNodePassable(node: Vector2): boolean {
|
||||||
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public search(start: Point, goal: Point){
|
public search(start: Vector2, goal: Vector2){
|
||||||
return WeightedPathfinder.search(this, start, goal);
|
return WeightedPathfinder.search(this, start, goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNeighbors(node: Point): Point[]{
|
public getNeighbors(node: Vector2): Vector2[]{
|
||||||
this._neighbors.length = 0;
|
this._neighbors.length = 0;
|
||||||
|
|
||||||
this._dirs.forEach(dir => {
|
this._dirs.forEach(dir => {
|
||||||
let next = new Point(node.x + dir.x, node.y + dir.y);
|
let next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||||
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
if (this.isNodeInBounds(next) && this.isNodePassable(next))
|
||||||
this._neighbors.push(next);
|
this._neighbors.push(next);
|
||||||
});
|
});
|
||||||
@@ -61,7 +61,7 @@ class WeightedGridGraph implements IWeightedGraph<Point> {
|
|||||||
return this._neighbors;
|
return this._neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cost(from: Point, to: Point): number{
|
public cost(from: Vector2, to: Vector2): number{
|
||||||
return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,10 @@ abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
this.setEnabled(value);
|
this.setEnabled(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get localPosition(){
|
||||||
|
return new Vector2(this.entity.x + this.x, this.entity.y + this.y);
|
||||||
|
}
|
||||||
|
|
||||||
public setEnabled(isEnabled: boolean){
|
public setEnabled(isEnabled: boolean){
|
||||||
if (this._enabled != isEnabled){
|
if (this._enabled != isEnabled){
|
||||||
this._enabled = isEnabled;
|
this._enabled = isEnabled;
|
||||||
@@ -28,7 +32,6 @@ abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public initialize(){
|
public initialize(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public onAddedToEntity(){
|
public onAddedToEntity(){
|
||||||
@@ -55,6 +58,14 @@ abstract class Component extends egret.DisplayObjectContainer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。
|
||||||
|
* @param comp
|
||||||
|
*/
|
||||||
|
public onEntityTransformChanged(comp: TransformComponent){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** 内部使用 运行时不应该调用 */
|
/** 内部使用 运行时不应该调用 */
|
||||||
public registerComponent(){
|
public registerComponent(){
|
||||||
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
|
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class Camera extends Component {
|
|||||||
private _minimumZoom = 0.3;
|
private _minimumZoom = 0.3;
|
||||||
private _maximumZoom = 3;
|
private _maximumZoom = 3;
|
||||||
|
|
||||||
|
private _position: Vector2 = Vector2.zero;
|
||||||
/**
|
/**
|
||||||
* 如果相机模式为cameraWindow 则会进行缓动移动
|
* 如果相机模式为cameraWindow 则会进行缓动移动
|
||||||
* 该值为移动速度
|
* 该值为移动速度
|
||||||
@@ -67,11 +68,24 @@ class Camera extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get position(){
|
public get position(){
|
||||||
return this.entity.position;
|
return this._position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set position(value: Vector2){
|
public set position(value: Vector2){
|
||||||
this.entity.position = value;
|
this._position = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get x(){
|
||||||
|
return this._position.x;
|
||||||
|
}
|
||||||
|
public set x(value: number){
|
||||||
|
this._position.x = value;
|
||||||
|
}
|
||||||
|
public get y(){
|
||||||
|
return this._position.y;
|
||||||
|
}
|
||||||
|
public set y(value: number){
|
||||||
|
this._position.y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ class BoxCollider extends Collider {
|
|||||||
this.setWidth(value);
|
this.setWidth(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置BoxCollider的宽度
|
||||||
|
* @param width
|
||||||
|
*/
|
||||||
public setWidth(width: number): BoxCollider{
|
public setWidth(width: number): BoxCollider{
|
||||||
this._colliderRequiresAutoSizing = false;
|
this._colliderRequiresAutoSizing = false;
|
||||||
let box = this.shape as Box;
|
let box = this.shape as Box;
|
||||||
if (width != box.width){
|
if (width != box.width){
|
||||||
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
||||||
box.updateBox(width, box.height);
|
box.updateBox(width, box.height);
|
||||||
this._isPositionDirty = true;
|
|
||||||
if (this.entity && this._isParentEntityAddedToScene)
|
if (this.entity && this._isParentEntityAddedToScene)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
@@ -29,20 +33,28 @@ class BoxCollider extends Collider {
|
|||||||
this.setHeight(value);
|
this.setHeight(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置BoxCollider的高度
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
public setHeight(height: number){
|
public setHeight(height: number){
|
||||||
this._colliderRequiresAutoSizing = false;
|
this._colliderRequiresAutoSizing = false;
|
||||||
let box = this.shape as Box;
|
let box = this.shape as Box;
|
||||||
if (height != box.height){
|
if (height != box.height){
|
||||||
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
||||||
box.updateBox(box.width, height);
|
box.updateBox(box.width, height);
|
||||||
this._isPositionDirty = true;
|
|
||||||
if (this.entity && this._isParentEntityAddedToScene)
|
if (this.entity && this._isParentEntityAddedToScene)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
||||||
|
*/
|
||||||
constructor(){
|
constructor(){
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
||||||
this.shape = new Box(1, 1);
|
this.shape = new Box(1, 1);
|
||||||
this._colliderRequiresAutoSizing = true;
|
this._colliderRequiresAutoSizing = true;
|
||||||
}
|
}
|
||||||
@@ -51,8 +63,8 @@ class BoxCollider extends Collider {
|
|||||||
this._colliderRequiresAutoSizing = false;
|
this._colliderRequiresAutoSizing = false;
|
||||||
let box = this.shape as Box;
|
let box = this.shape as Box;
|
||||||
if (width != box.width || height != box.height){
|
if (width != box.width || height != box.height){
|
||||||
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
||||||
box.updateBox(width, height);
|
box.updateBox(width, height);
|
||||||
this._isPositionDirty = true;
|
|
||||||
if (this.entity && this._isParentEntityAddedToScene)
|
if (this.entity && this._isParentEntityAddedToScene)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1,89 @@
|
|||||||
abstract class Collider extends Component{
|
abstract class Collider extends Component {
|
||||||
|
/** 对撞机的基本形状 */
|
||||||
public shape: Shape;
|
public shape: Shape;
|
||||||
|
/** 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法。 */
|
||||||
public physicsLayer = 1 << 0;
|
public physicsLayer = 1 << 0;
|
||||||
|
/** 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 */
|
||||||
public isTrigger: boolean;
|
public isTrigger: boolean;
|
||||||
public registeredPhysicsBounds: Rectangle;
|
/**
|
||||||
public shouldColliderScaleAndRotationWithTransform = true;
|
* 这个对撞机在物理系统注册时的边界。
|
||||||
|
* 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。
|
||||||
|
*/
|
||||||
|
public registeredPhysicsBounds: Rectangle = new Rectangle();
|
||||||
|
/** 如果为true,碰撞器将根据附加的变换缩放和旋转 */
|
||||||
|
public shouldColliderScaleAndRotateWithTransform = true;
|
||||||
|
/** 默认为所有层。 */
|
||||||
public collidesWithLayers = Physics.allLayers;
|
public collidesWithLayers = Physics.allLayers;
|
||||||
|
|
||||||
public _localOffsetLength: number;
|
public _localOffsetLength: number;
|
||||||
public _isPositionDirty = true;
|
/** 标记来跟踪我们的实体是否被添加到场景中 */
|
||||||
public _isRotationDirty = true;
|
|
||||||
protected _isParentEntityAddedToScene;
|
protected _isParentEntityAddedToScene;
|
||||||
protected _colliderRequiresAutoSizing;
|
protected _colliderRequiresAutoSizing;
|
||||||
protected _localOffset: Vector2 = new Vector2(0, 0);
|
protected _localOffset: Vector2 = new Vector2(0, 0);
|
||||||
|
/** 标记来记录我们是否注册了物理系统 */
|
||||||
protected _isColliderRegistered;
|
protected _isColliderRegistered;
|
||||||
|
|
||||||
public get bounds(): Rectangle {
|
public get bounds(): Rectangle {
|
||||||
if (this._isPositionDirty || this._isRotationDirty){
|
this.shape.recalculateBounds(this);
|
||||||
this.shape.recalculateBounds(this);
|
|
||||||
this._isPositionDirty = this._isRotationDirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.shape.bounds;
|
return this.shape.bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get localOffset(){
|
public get localOffset() {
|
||||||
return this._localOffset;
|
return this._localOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set localOffset(value: Vector2){
|
/**
|
||||||
|
* 将localOffset添加到实体。获取碰撞器的最终位置。这允许您向一个实体添加多个碰撞器并分别定位它们。
|
||||||
|
*/
|
||||||
|
public set localOffset(value: Vector2) {
|
||||||
this.setLocalOffset(value);
|
this.setLocalOffset(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLocalOffset(offset: Vector2){
|
public setLocalOffset(offset: Vector2) {
|
||||||
if (this._localOffset != offset){
|
if (this._localOffset != offset) {
|
||||||
this.unregisterColliderWithPhysicsSystem();
|
this.unregisterColliderWithPhysicsSystem();
|
||||||
this._localOffset = offset;
|
this._localOffset = offset;
|
||||||
this._localOffsetLength = this._localOffset.length();
|
this._localOffsetLength = this._localOffset.length();
|
||||||
this._isPositionDirty = true;
|
|
||||||
this.registerColliderWithPhysicsSystem();
|
this.registerColliderWithPhysicsSystem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerColliderWithPhysicsSystem(){
|
/**
|
||||||
if (this._isParentEntityAddedToScene && !this._isColliderRegistered){
|
* 父实体会在不同的时间调用它(当添加到场景,启用,等等)
|
||||||
|
*/
|
||||||
|
public registerColliderWithPhysicsSystem() {
|
||||||
|
// 如果在将我们添加到实体之前更改了origin等属性,则实体可以为null
|
||||||
|
if (this._isParentEntityAddedToScene && !this._isColliderRegistered) {
|
||||||
Physics.addCollider(this);
|
Physics.addCollider(this);
|
||||||
this._isColliderRegistered = true;
|
this._isColliderRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregisterColliderWithPhysicsSystem(){
|
/**
|
||||||
if (this._isParentEntityAddedToScene && this._isColliderRegistered){
|
* 父实体会在不同的时候调用它(从场景中移除,禁用,等等)
|
||||||
|
*/
|
||||||
|
public unregisterColliderWithPhysicsSystem() {
|
||||||
|
if (this._isParentEntityAddedToScene && this._isColliderRegistered) {
|
||||||
Physics.removeCollider(this);
|
Physics.removeCollider(this);
|
||||||
}
|
}
|
||||||
this._isColliderRegistered = false;
|
this._isColliderRegistered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public overlaps(other: Collider){
|
/**
|
||||||
|
* 检查这个形状是否与物理系统中的其他对撞机重叠
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
public overlaps(other: Collider) {
|
||||||
return this.shape.overlaps(other.shape);
|
return this.shape.overlaps(other.shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public collidesWith(collider: Collider, motion: Vector2){
|
/**
|
||||||
|
* 检查这个与运动应用的碰撞器(移动向量)是否与碰撞器碰撞。如果是这样,将返回true,并且结果将填充碰撞数据。
|
||||||
|
* @param collider
|
||||||
|
* @param motion
|
||||||
|
*/
|
||||||
|
public collidesWith(collider: Collider, motion: Vector2) {
|
||||||
|
// 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
|
||||||
let oldPosition = this.shape.position;
|
let oldPosition = this.shape.position;
|
||||||
this.shape.position = Vector2.add(this.shape.position, motion);
|
this.shape.position = Vector2.add(this.shape.position, motion);
|
||||||
|
|
||||||
@@ -67,31 +91,36 @@ abstract class Collider extends Component{
|
|||||||
if (result)
|
if (result)
|
||||||
result.collider = collider;
|
result.collider = collider;
|
||||||
|
|
||||||
|
// 将图形位置返回到检查前的位置
|
||||||
this.shape.position = oldPosition;
|
this.shape.position = oldPosition;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onAddedToEntity(){
|
public onAddedToEntity() {
|
||||||
if (this._colliderRequiresAutoSizing){
|
if (this._colliderRequiresAutoSizing) {
|
||||||
if (!(this instanceof BoxCollider)){
|
if (!(this instanceof BoxCollider)) {
|
||||||
console.error("Only box and circle colliders can be created automatically");
|
console.error("Only box and circle colliders can be created automatically");
|
||||||
}
|
}
|
||||||
|
|
||||||
let renderable = this.entity.getComponent<RenderableComponent>(RenderableComponent);
|
let renderable = this.entity.getComponent<RenderableComponent>(RenderableComponent);
|
||||||
if (renderable){
|
if (renderable) {
|
||||||
let renderbaleBounds = renderable.bounds;
|
let bounds = renderable.bounds;
|
||||||
|
|
||||||
let width = renderbaleBounds.width / this.entity.scale.x;
|
// 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染
|
||||||
let height = renderbaleBounds.height / this.entity.scale.y;
|
let width = bounds.width / this.entity.scale.x;
|
||||||
|
let height = bounds.height / this.entity.scale.y;
|
||||||
|
|
||||||
if (this instanceof BoxCollider){
|
if (this instanceof BoxCollider) {
|
||||||
let boxCollider = this as BoxCollider;
|
let boxCollider = this as BoxCollider;
|
||||||
boxCollider.width = width;
|
boxCollider.width = width;
|
||||||
boxCollider.height = height;
|
boxCollider.height = height;
|
||||||
|
|
||||||
this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
|
// 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset
|
||||||
|
this.localOffset = bounds.location;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,17 +128,29 @@ abstract class Collider extends Component{
|
|||||||
this.registerColliderWithPhysicsSystem();
|
this.registerColliderWithPhysicsSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onRemovedFromEntity(){
|
public onRemovedFromEntity() {
|
||||||
this.unregisterColliderWithPhysicsSystem();
|
this.unregisterColliderWithPhysicsSystem();
|
||||||
this._isParentEntityAddedToScene = false;
|
this._isParentEntityAddedToScene = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onEnabled(){
|
public onEnabled() {
|
||||||
this.registerColliderWithPhysicsSystem();
|
this.registerColliderWithPhysicsSystem();
|
||||||
this._isPositionDirty = this._isRotationDirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public onDisabled(){
|
public onDisabled() {
|
||||||
this.unregisterColliderWithPhysicsSystem();
|
this.unregisterColliderWithPhysicsSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onEntityTransformChanged(comp: TransformComponent) {
|
||||||
|
if (this._isColliderRegistered)
|
||||||
|
Physics.updateCollider(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(){
|
||||||
|
let renderable = this.entity.getComponent<RenderableComponent>(RenderableComponent);
|
||||||
|
if (renderable){
|
||||||
|
this.$setX(renderable.x + this.localOffset.x);
|
||||||
|
this.$setY(renderable.y + this.localOffset.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* 辅助类说明了一种处理移动的方法,它考虑了包括触发器在内的所有冲突。
|
||||||
|
* ITriggerListener接口用于管理对移动过程中违反的任何触发器的回调。
|
||||||
|
* 一个物体只能通过移动器移动。要正确报告触发器的move方法。
|
||||||
|
*
|
||||||
|
* 请注意,多个移动者相互交互将多次调用ITriggerListener。
|
||||||
|
*/
|
||||||
class Mover extends Component {
|
class Mover extends Component {
|
||||||
private _triggerHelper: ColliderTriggerHelper;
|
private _triggerHelper: ColliderTriggerHelper;
|
||||||
|
|
||||||
@@ -5,6 +12,10 @@ class Mover extends Component {
|
|||||||
this._triggerHelper = new ColliderTriggerHelper(this.entity);
|
this._triggerHelper = new ColliderTriggerHelper(this.entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算修改运动矢量的运动,以考虑移动时可能发生的碰撞
|
||||||
|
* @param motion
|
||||||
|
*/
|
||||||
public calculateMovement(motion: Vector2){
|
public calculateMovement(motion: Vector2){
|
||||||
let collisionResult = new CollisionResult();
|
let collisionResult = new CollisionResult();
|
||||||
|
|
||||||
@@ -16,23 +27,30 @@ class Mover extends Component {
|
|||||||
for (let i = 0; i < colliders.length; i ++){
|
for (let i = 0; i < colliders.length; i ++){
|
||||||
let collider = colliders[i];
|
let collider = colliders[i];
|
||||||
|
|
||||||
|
// 不检测触发器
|
||||||
if (collider.isTrigger)
|
if (collider.isTrigger)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// 获取我们在新位置可能发生碰撞的任何东西
|
||||||
let bounds = collider.bounds;
|
let bounds = collider.bounds;
|
||||||
bounds.x += motion.x;
|
bounds.x += motion.x;
|
||||||
bounds.y += motion.y;
|
bounds.y += motion.y;
|
||||||
let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
|
let boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
|
||||||
|
bounds = boxcastResult.bounds;
|
||||||
|
let neighbors = boxcastResult.tempHashSet;
|
||||||
|
|
||||||
for (let j = 0; j < neighbors.length; j ++){
|
for (let j = 0; j < neighbors.length; j ++){
|
||||||
let neighbor = neighbors[j];
|
let neighbor = neighbors[j];
|
||||||
|
// 不检测触发器
|
||||||
if (neighbor.isTrigger)
|
if (neighbor.isTrigger)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let _internalcollisionResult = collider.collidesWith(neighbor, motion);
|
let _internalcollisionResult = collider.collidesWith(neighbor, motion);
|
||||||
if (_internalcollisionResult){
|
if (_internalcollisionResult){
|
||||||
|
// 如果碰撞 则退回之前的移动量
|
||||||
motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector);
|
motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector);
|
||||||
|
|
||||||
|
// 如果我们碰到多个对象,为了简单起见,只取第一个。
|
||||||
if (_internalcollisionResult.collider){
|
if (_internalcollisionResult.collider){
|
||||||
collisionResult = _internalcollisionResult;
|
collisionResult = _internalcollisionResult;
|
||||||
}
|
}
|
||||||
@@ -42,7 +60,7 @@ class Mover extends Component {
|
|||||||
|
|
||||||
ListPool.free(colliders);
|
ListPool.free(colliders);
|
||||||
|
|
||||||
return collisionResult;
|
return {collisionResult: collisionResult, motion: motion};
|
||||||
}
|
}
|
||||||
|
|
||||||
public applyMovement(motion: Vector2){
|
public applyMovement(motion: Vector2){
|
||||||
@@ -53,7 +71,9 @@ class Mover extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public move(motion: Vector2){
|
public move(motion: Vector2){
|
||||||
let collisionResult = this.calculateMovement(motion);
|
let movementResult = this.calculateMovement(motion);
|
||||||
|
let collisionResult = movementResult.collisionResult;
|
||||||
|
motion = movementResult.motion;
|
||||||
|
|
||||||
this.applyMovement(motion);
|
this.applyMovement(motion);
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,12 @@
|
|||||||
class SpriteRenderer extends RenderableComponent {
|
class SpriteRenderer extends RenderableComponent {
|
||||||
private _origin: Vector2;
|
|
||||||
private _sprite: Sprite;
|
private _sprite: Sprite;
|
||||||
protected bitmap: egret.Bitmap;
|
protected bitmap: egret.Bitmap;
|
||||||
|
|
||||||
public get origin(){
|
/** 应该由这个精灵显示的精灵 */
|
||||||
return this._origin;
|
|
||||||
}
|
|
||||||
public set origin(value: Vector2){
|
|
||||||
this.setOrigin(value);
|
|
||||||
}
|
|
||||||
public setOrigin(origin: Vector2){
|
|
||||||
if (this._origin != origin){
|
|
||||||
this._origin = origin;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
/** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
|
|
||||||
public get sprite(): Sprite{
|
public get sprite(): Sprite{
|
||||||
return this._sprite;
|
return this._sprite;
|
||||||
}
|
}
|
||||||
/** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
|
/** 应该由这个精灵显示的精灵 */
|
||||||
public set sprite(value: Sprite){
|
public set sprite(value: Sprite){
|
||||||
this.setSprite(value);
|
this.setSprite(value);
|
||||||
}
|
}
|
||||||
@@ -27,7 +14,10 @@ class SpriteRenderer extends RenderableComponent {
|
|||||||
public setSprite(sprite: Sprite): SpriteRenderer{
|
public setSprite(sprite: Sprite): SpriteRenderer{
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
this._sprite = sprite;
|
this._sprite = sprite;
|
||||||
if (this._sprite) this._origin = this._sprite.origin;
|
if (this._sprite) {
|
||||||
|
this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width;
|
||||||
|
this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height;
|
||||||
|
}
|
||||||
this.bitmap = new egret.Bitmap(sprite.texture2D);
|
this.bitmap = new egret.Bitmap(sprite.texture2D);
|
||||||
this.addChild(this.bitmap);
|
this.addChild(this.bitmap);
|
||||||
|
|
||||||
@@ -58,8 +48,8 @@ class SpriteRenderer extends RenderableComponent {
|
|||||||
|
|
||||||
/** 渲染处理 在每个模块中处理各自的渲染逻辑 */
|
/** 渲染处理 在每个模块中处理各自的渲染逻辑 */
|
||||||
public render(camera: Camera){
|
public render(camera: Camera){
|
||||||
this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x;
|
this.x = -camera.position.x + camera.origin.x;
|
||||||
this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y;
|
this.y = -camera.position.y + camera.origin.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onRemovedFromEntity(){
|
public onRemovedFromEntity(){
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
class Entity extends egret.DisplayObjectContainer {
|
class Entity extends egret.DisplayObjectContainer {
|
||||||
private static _idGenerator: number;
|
private static _idGenerator: number;
|
||||||
|
|
||||||
private _position: Vector2 = Vector2.zero;
|
|
||||||
public name: string;
|
public name: string;
|
||||||
public readonly id: number;
|
public readonly id: number;
|
||||||
/** 当前实体所属的场景 */
|
/** 当前实体所属的场景 */
|
||||||
@@ -20,11 +19,13 @@ class Entity extends egret.DisplayObjectContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get position(){
|
public get position(){
|
||||||
return this._position;
|
return new Vector2(this.x, this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public set position(value: Vector2){
|
public set position(value: Vector2){
|
||||||
this._position = value;
|
this.$setX(value.x);
|
||||||
|
this.$setY(value.y);
|
||||||
|
this.onEntityTransformChanged(TransformComponent.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get scale(){
|
public get scale(){
|
||||||
@@ -32,8 +33,18 @@ class Entity extends egret.DisplayObjectContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set scale(value: Vector2){
|
public set scale(value: Vector2){
|
||||||
this.scaleX = value.x;
|
this.$setScaleX(value.x);
|
||||||
this.scaleY = value.y;
|
this.$setScaleY(value.y);
|
||||||
|
this.onEntityTransformChanged(TransformComponent.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public set rotation(value: number){
|
||||||
|
this.$setRotation(value);
|
||||||
|
this.onEntityTransformChanged(TransformComponent.rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get rotation(){
|
||||||
|
return this.$getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get enabled(){
|
public get enabled(){
|
||||||
@@ -74,6 +85,11 @@ class Entity extends egret.DisplayObjectContainer {
|
|||||||
this.id = Entity._idGenerator ++;
|
this.id = Entity._idGenerator ++;
|
||||||
|
|
||||||
this.componentBits = new BitSet();
|
this.componentBits = new BitSet();
|
||||||
|
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onAddToStage(){
|
||||||
|
this.onEntityTransformChanged(TransformComponent.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get updateOrder(){
|
public get updateOrder(){
|
||||||
@@ -160,6 +176,10 @@ class Entity extends egret.DisplayObjectContainer {
|
|||||||
return this.components.getComponents(typeName, componentList);
|
return this.components.getComponents(typeName, componentList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onEntityTransformChanged(comp: TransformComponent){
|
||||||
|
this.components.onEntityTransformChanged(comp);
|
||||||
|
}
|
||||||
|
|
||||||
public removeComponentForType<T extends Component>(type){
|
public removeComponentForType<T extends Component>(type){
|
||||||
let comp = this.getComponent<T>(type);
|
let comp = this.getComponent<T>(type);
|
||||||
if (comp){
|
if (comp){
|
||||||
@@ -195,12 +215,23 @@ class Entity extends egret.DisplayObjectContainer {
|
|||||||
|
|
||||||
public destroy(){
|
public destroy(){
|
||||||
this._isDestoryed = true;
|
this._isDestoryed = true;
|
||||||
|
this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
|
||||||
|
|
||||||
this.scene.entities.remove(this);
|
this.scene.entities.remove(this);
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
|
||||||
|
if (this.parent)
|
||||||
|
this.parent.removeChild(this);
|
||||||
|
|
||||||
for (let i = this.numChildren - 1; i >= 0; i --){
|
for (let i = this.numChildren - 1; i >= 0; i --){
|
||||||
let child = this.getChildAt(i);
|
let child = this.getChildAt(i);
|
||||||
(child as Component).entity.destroy();
|
(child as Component).entity.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TransformComponent {
|
||||||
|
rotation,
|
||||||
|
scale,
|
||||||
|
position
|
||||||
|
}
|
||||||
@@ -144,6 +144,9 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
this.entityProcessors.end();
|
this.entityProcessors.end();
|
||||||
|
|
||||||
this.unload();
|
this.unload();
|
||||||
|
|
||||||
|
if (this.parent)
|
||||||
|
this.parent.removeChild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async onStart() {
|
protected async onStart() {
|
||||||
|
|||||||
@@ -101,6 +101,18 @@ class ComponentList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onEntityTransformChanged(comp: TransformComponent){
|
||||||
|
for (let i = 0; i < this._components.length; i ++){
|
||||||
|
if (this._components[i].enabled)
|
||||||
|
this._components[i].onEntityTransformChanged(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this._componentsToAdd.length; i ++){
|
||||||
|
if (this._componentsToAdd[i].enabled)
|
||||||
|
this._componentsToAdd[i].onEntityTransformChanged(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private handleRemove(component: Component){
|
private handleRemove(component: Component){
|
||||||
if (component instanceof RenderableComponent)
|
if (component instanceof RenderableComponent)
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ abstract class SceneTransition {
|
|||||||
this.isNewSceneLoaded = true;
|
this.isNewSceneLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false){
|
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean>{
|
||||||
return new Promise((resolve)=>{
|
return new Promise((resolve)=>{
|
||||||
let start = reverseDirection ? 1 : 0;
|
let start = reverseDirection ? 1 : 0;
|
||||||
let end = reverseDirection ? 0 : 1;
|
let end = reverseDirection ? 0 : 1;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Flags {
|
|||||||
* @param self
|
* @param self
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
public static isFlagSet(self: number, flag: number){
|
public static isFlagSet(self: number, flag: number): boolean{
|
||||||
return (self & flag) != 0;
|
return (self & flag) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class Flags {
|
|||||||
* @param self
|
* @param self
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
public static isUnshiftedFlagSet(self: number, flag: number){
|
public static isUnshiftedFlagSet(self: number, flag: number): boolean{
|
||||||
flag = 1 << flag;
|
flag = 1 << flag;
|
||||||
return (self & flag) != 0;
|
return (self & flag) != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,8 +155,13 @@ class Matrix2D {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D){
|
/**
|
||||||
result = result ? result : new Matrix2D();
|
* 创建一个新的tranlation
|
||||||
|
* @param xPosition
|
||||||
|
* @param yPosition
|
||||||
|
*/
|
||||||
|
public static createTranslation(xPosition: number, yPosition: number){
|
||||||
|
let result = new Matrix2D();
|
||||||
|
|
||||||
result.m11 = 1;
|
result.m11 = 1;
|
||||||
result.m12 = 0;
|
result.m12 = 0;
|
||||||
@@ -170,6 +175,14 @@ class Matrix2D {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据position 创建一个translation
|
||||||
|
* @param position
|
||||||
|
*/
|
||||||
|
public static createTranslationVector(position: Vector2){
|
||||||
|
return this.createTranslation(position.x, position.y);
|
||||||
|
}
|
||||||
|
|
||||||
public static createRotation(radians: number, result?: Matrix2D){
|
public static createRotation(radians: number, result?: Matrix2D){
|
||||||
result = new Matrix2D();
|
result = new Matrix2D();
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
class Point {
|
|
||||||
public x: number;
|
|
||||||
public y: number;
|
|
||||||
|
|
||||||
constructor(x?: number, y?: number){
|
|
||||||
this.x = x ? x : 0;
|
|
||||||
this.y = y ? y : this.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+70
-103
@@ -1,36 +1,21 @@
|
|||||||
class Rectangle {
|
class Rectangle extends egret.Rectangle {
|
||||||
public x: number;
|
/**
|
||||||
public y: number;
|
* 获取矩形的最大点,即右下角
|
||||||
public width: number;
|
*/
|
||||||
public height: number;
|
public get max() {
|
||||||
|
return new Vector2(this.right, this.bottom);
|
||||||
private _tempMat: Matrix2D;
|
|
||||||
private _transformMat: Matrix2D;
|
|
||||||
|
|
||||||
public get left() {
|
|
||||||
return this.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get right() {
|
|
||||||
return this.x + this.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get top() {
|
|
||||||
return this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get bottom() {
|
|
||||||
return this.y + this.height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 中心点坐标 */
|
||||||
public get center() {
|
public get center() {
|
||||||
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
|
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 左上角的坐标 */
|
||||||
public get location() {
|
public get location() {
|
||||||
return new Vector2(this.x, this.y);
|
return new Vector2(this.x, this.y);
|
||||||
}
|
}
|
||||||
|
/** 左上角的坐标 */
|
||||||
public set location(value: Vector2) {
|
public set location(value: Vector2) {
|
||||||
this.x = value.x;
|
this.x = value.x;
|
||||||
this.y = value.y;
|
this.y = value.y;
|
||||||
@@ -45,48 +30,56 @@ class Rectangle {
|
|||||||
this.height = value.y;
|
this.height = value.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(x?: number, y?: number, width?: number, height?: number) {
|
/**
|
||||||
this.x = x ? x : 0;
|
* 是否与另一个矩形相交
|
||||||
this.y = y ? y : 0;
|
* @param value
|
||||||
this.width = width ? width : 0;
|
*/
|
||||||
this.height = height ? height : 0;
|
public intersects(value: egret.Rectangle) {
|
||||||
}
|
|
||||||
|
|
||||||
public intersects(value: Rectangle) {
|
|
||||||
return value.left < this.right &&
|
return value.left < this.right &&
|
||||||
this.left < value.right &&
|
this.left < value.right &&
|
||||||
value.top < this.bottom &&
|
value.top < this.bottom &&
|
||||||
this.top < value.bottom;
|
this.top < value.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public contains(value: Vector2) {
|
/**
|
||||||
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
|
* 获取所提供的矩形是否在此矩形的边界内
|
||||||
(this.y <= value.y)) &&
|
* @param value
|
||||||
(value.y < (this.y + this.height)));
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public containsRect(value: Rectangle) {
|
public containsRect(value: Rectangle) {
|
||||||
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
|
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
|
||||||
(this.y <= value.y)) &&
|
(this.y <= value.y)) &&
|
||||||
(value.y < (this.y + this.height)));
|
(value.y < (this.y + this.height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHalfSize(){
|
public getHalfSize() {
|
||||||
return new Vector2(this.width * 0.5, this.height * 0.5);
|
return new Vector2(this.width * 0.5, this.height * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个矩形的最小/最大点(左上角,右下角的点)
|
||||||
|
* @param minX
|
||||||
|
* @param minY
|
||||||
|
* @param maxX
|
||||||
|
* @param maxY
|
||||||
|
*/
|
||||||
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
|
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
|
||||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getClosestPointOnRectangleBorderToPoint(point: Point): { res: Vector2, edgeNormal: Vector2 } {
|
/**
|
||||||
let edgeNormal = new Vector2(0, 0);
|
* 获取矩形边界上与给定点最近的点
|
||||||
|
* @param point
|
||||||
|
*/
|
||||||
|
public getClosestPointOnRectangleBorderToPoint(point: Vector2): { res: Vector2, edgeNormal: Vector2 } {
|
||||||
|
let edgeNormal = Vector2.zero;
|
||||||
|
|
||||||
let res = new Vector2(0, 0);
|
// 对于每个轴,如果点在盒子外面
|
||||||
|
let res = new Vector2();
|
||||||
res.x = MathHelper.clamp(point.x, this.left, this.right);
|
res.x = MathHelper.clamp(point.x, this.left, this.right);
|
||||||
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
|
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
|
||||||
|
|
||||||
if (this.contains(res)) {
|
// 如果点在矩形内,我们需要推res到边界,因为它将在矩形内
|
||||||
|
if (this.contains(res.x, res.y)) {
|
||||||
let dl = res.x - this.left;
|
let dl = res.x - this.left;
|
||||||
let dr = this.right - res.x;
|
let dr = this.right - res.x;
|
||||||
let dt = res.y - this.top;
|
let dt = res.y - this.top;
|
||||||
@@ -107,61 +100,42 @@ class Rectangle {
|
|||||||
edgeNormal.x = 1;
|
edgeNormal.x = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (res.x == this.left) {
|
if (res.x == this.left) edgeNormal.x = -1;
|
||||||
edgeNormal.x = -1;
|
if (res.x == this.right) edgeNormal.x = 1;
|
||||||
}
|
if (res.y == this.top) edgeNormal.y = -1;
|
||||||
if (res.x == this.right) {
|
if (res.y == this.bottom) edgeNormal.y = 1;
|
||||||
edgeNormal.x = 1;
|
|
||||||
}
|
|
||||||
if (res.y == this.top) {
|
|
||||||
edgeNormal.y = -1;
|
|
||||||
}
|
|
||||||
if (res.y == this.bottom) {
|
|
||||||
edgeNormal.y = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { res: res, edgeNormal: edgeNormal };
|
return { res: res, edgeNormal: edgeNormal };
|
||||||
}
|
}
|
||||||
|
|
||||||
public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2,
|
/**
|
||||||
rotation: number, width: number, height: number) {
|
*
|
||||||
if (rotation == 0) {
|
*/
|
||||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
public getClosestPointOnBoundsToOrigin() {
|
||||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
let max = this.max;
|
||||||
this.width = width * scale.x;
|
let minDist = Math.abs(this.location.x);
|
||||||
this.height = height * scale.y;
|
let boundsPoint = new Vector2(this.location.x, 0);
|
||||||
} else {
|
|
||||||
let worldPosX = parentPosition.x + position.x;
|
|
||||||
let worldPosY = parentPosition.y + position.y;
|
|
||||||
|
|
||||||
this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y);
|
if (Math.abs(max.x) < minDist) {
|
||||||
this._tempMat = Matrix2D.createScale(scale.x, scale.y);
|
minDist = Math.abs(max.x);
|
||||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
boundsPoint.x = max.x;
|
||||||
this._tempMat = Matrix2D.createRotation(rotation);
|
boundsPoint.y = 0;
|
||||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
|
||||||
this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY);
|
|
||||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
|
||||||
|
|
||||||
let topLeft = new Vector2(worldPosX, worldPosY);
|
|
||||||
let topRight = new Vector2(worldPosX + width, worldPosY);
|
|
||||||
let bottomLeft = new Vector2(worldPosX, worldPosY + height);
|
|
||||||
let bottomRight = new Vector2(worldPosX + width, worldPosY + height);
|
|
||||||
|
|
||||||
topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
|
|
||||||
topRight = Vector2Ext.transformR(topRight, this._transformMat);
|
|
||||||
bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
|
|
||||||
bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
|
|
||||||
|
|
||||||
let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
|
||||||
let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
|
|
||||||
let minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
|
||||||
let maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
|
|
||||||
|
|
||||||
this.location = new Vector2(minX, minY);
|
|
||||||
this.width = maxX - minX;
|
|
||||||
this.height = maxY - minY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Math.abs(max.y) < minDist) {
|
||||||
|
minDist = Math.abs(max.y);
|
||||||
|
boundsPoint.x = 0;
|
||||||
|
boundsPoint.y = max.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.abs(this.location.y) < minDist) {
|
||||||
|
minDist = Math.abs(this.location.y);
|
||||||
|
boundsPoint.x = 0;
|
||||||
|
boundsPoint.y = this.location.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return boundsPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,6 +143,7 @@ class Rectangle {
|
|||||||
* @param points
|
* @param points
|
||||||
*/
|
*/
|
||||||
public static rectEncompassingPoints(points: Vector2[]) {
|
public static rectEncompassingPoints(points: Vector2[]) {
|
||||||
|
// 我们需要求出x/y的最小值/最大值
|
||||||
let minX = Number.POSITIVE_INFINITY;
|
let minX = Number.POSITIVE_INFINITY;
|
||||||
let minY = Number.POSITIVE_INFINITY;
|
let minY = Number.POSITIVE_INFINITY;
|
||||||
let maxX = Number.NEGATIVE_INFINITY;
|
let maxX = Number.NEGATIVE_INFINITY;
|
||||||
@@ -177,19 +152,11 @@ class Rectangle {
|
|||||||
for (let i = 0; i < points.length; i++) {
|
for (let i = 0; i < points.length; i++) {
|
||||||
let pt = points[i];
|
let pt = points[i];
|
||||||
|
|
||||||
if (pt.x < minX) {
|
if (pt.x < minX) minX = pt.x;
|
||||||
minX = pt.x;
|
if (pt.x > maxX) maxX = pt.x;
|
||||||
}
|
|
||||||
if (pt.x > maxX) {
|
|
||||||
maxX = pt.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pt.y < minY) {
|
if (pt.y < minY) minY = pt.y;
|
||||||
minY = pt.y;
|
if (pt.y > maxY) maxY = pt.y;
|
||||||
}
|
|
||||||
if (pt.y > maxY) {
|
|
||||||
maxY = pt.y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.fromMinMax(minX, minY, maxX, maxY);
|
return this.fromMinMax(minX, minY, maxX, maxY);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/** 移动器使用的帮助器类,用于管理触发器碰撞器交互并调用itriggerlistener。 */
|
||||||
class ColliderTriggerHelper {
|
class ColliderTriggerHelper {
|
||||||
private _entity: Entity;
|
private _entity: Entity;
|
||||||
/** 存储当前帧中发生的所有活动交集对 */
|
/** 存储当前帧中发生的所有活动交集对 */
|
||||||
@@ -18,7 +19,9 @@ class ColliderTriggerHelper {
|
|||||||
for (let i = 0; i < colliders.length; i++) {
|
for (let i = 0; i < colliders.length; i++) {
|
||||||
let collider = colliders[i];
|
let collider = colliders[i];
|
||||||
|
|
||||||
let neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
|
let boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
|
||||||
|
collider.bounds = boxcastResult.rect;
|
||||||
|
let neighbors = boxcastResult.colliders;
|
||||||
for (let j = 0; j < neighbors.length; j++) {
|
for (let j = 0; j < neighbors.length; j++) {
|
||||||
let neighbor = neighbors[j];
|
let neighbor = neighbors[j];
|
||||||
if (!collider.isTrigger && !neighbor.isTrigger)
|
if (!collider.isTrigger && !neighbor.isTrigger)
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ class Physics {
|
|||||||
private static _spatialHash: SpatialHash;
|
private static _spatialHash: SpatialHash;
|
||||||
/** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */
|
/** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */
|
||||||
public static spatialHashCellSize = 100;
|
public static spatialHashCellSize = 100;
|
||||||
|
/** 接受layerMask的所有方法的默认值 */
|
||||||
public static readonly allLayers: number = -1;
|
public static readonly allLayers: number = -1;
|
||||||
|
|
||||||
public static reset(){
|
public static reset(){
|
||||||
this._spatialHash = new SpatialHash(this.spatialHashCellSize);
|
this._spatialHash = new SpatialHash(this.spatialHashCellSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从SpatialHash中移除所有碰撞器
|
||||||
|
*/
|
||||||
public static clear(){
|
public static clear(){
|
||||||
this._spatialHash.clear();
|
this._spatialHash.clear();
|
||||||
}
|
}
|
||||||
@@ -18,21 +21,34 @@ class Physics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boxcastBroadphase(rect: Rectangle, layerMask: number = this.allLayers){
|
public static boxcastBroadphase(rect: Rectangle, layerMask: number = this.allLayers){
|
||||||
return this._spatialHash.aabbBroadphase(rect, null, layerMask);
|
let boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask);
|
||||||
|
return {colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask = this.allLayers){
|
public static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask = this.allLayers){
|
||||||
return this._spatialHash.aabbBroadphase(rect, collider, layerMask);
|
return this._spatialHash.aabbBroadphase(rect, collider, layerMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对撞机添加到物理系统中
|
||||||
|
* @param collider
|
||||||
|
*/
|
||||||
public static addCollider(collider: Collider){
|
public static addCollider(collider: Collider){
|
||||||
Physics._spatialHash.register(collider);
|
Physics._spatialHash.register(collider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从物理系统中移除对撞机
|
||||||
|
* @param collider
|
||||||
|
*/
|
||||||
public static removeCollider(collider: Collider){
|
public static removeCollider(collider: Collider){
|
||||||
Physics._spatialHash.remove(collider);
|
Physics._spatialHash.remove(collider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新物理系统中对撞机的位置。这实际上只是移除然后重新添加带有新边界的碰撞器
|
||||||
|
* @param collider
|
||||||
|
*/
|
||||||
public static updateCollider(collider: Collider){
|
public static updateCollider(collider: Collider){
|
||||||
this._spatialHash.remove(collider);
|
this._spatialHash.remove(collider);
|
||||||
this._spatialHash.register(collider);
|
this._spatialHash.register(collider);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
///<reference path="./Polygon.ts" />
|
///<reference path="./Polygon.ts" />
|
||||||
|
/**
|
||||||
|
* 多边形的特殊情况。在进行SAT碰撞检查时,我们只需要检查2个轴而不是8个轴
|
||||||
|
*/
|
||||||
class Box extends Polygon {
|
class Box extends Polygon {
|
||||||
public width: number;
|
public width: number;
|
||||||
public height: number;
|
public height: number;
|
||||||
@@ -9,7 +12,13 @@ class Box extends Polygon {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在一个盒子的形状中建立多边形需要的点的帮助方法
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
private static buildBox(width: number, height: number): Vector2[]{
|
private static buildBox(width: number, height: number): Vector2[]{
|
||||||
|
// 我们在(0,0)的中心周围创建点
|
||||||
let halfWidth = width / 2;
|
let halfWidth = width / 2;
|
||||||
let halfHeight = height / 2;
|
let halfHeight = height / 2;
|
||||||
let verts = new Array(4);
|
let verts = new Array(4);
|
||||||
@@ -21,10 +30,40 @@ class Box extends Polygon {
|
|||||||
return verts;
|
return verts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public overlaps(other: Shape){
|
||||||
|
// 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测
|
||||||
|
if (this.isUnrotated){
|
||||||
|
if (other instanceof Box && other.isUnrotated)
|
||||||
|
return this.bounds.intersects(other.bounds);
|
||||||
|
|
||||||
|
if (other instanceof Circle)
|
||||||
|
return Collisions.isRectToCircle(this.bounds, other.position, other.radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.overlaps(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public collidesWithShape(other: Shape){
|
||||||
|
// 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测
|
||||||
|
if (this.isUnrotated && other instanceof Box && other.isUnrotated){
|
||||||
|
return ShapeCollisions.boxToBox(this, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 让 minkowski 运行于 cricleToBox
|
||||||
|
|
||||||
|
return super.collidesWithShape(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新框点,重新计算中心,设置宽度/高度
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
public updateBox(width: number, height: number){
|
public updateBox(width: number, height: number){
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
|
// 我们在(0,0)的中心周围创建点
|
||||||
let halfWidth = width / 2;
|
let halfWidth = width / 2;
|
||||||
let halfHeight = height / 2;
|
let halfHeight = height / 2;
|
||||||
|
|
||||||
@@ -39,7 +78,7 @@ class Box extends Polygon {
|
|||||||
|
|
||||||
public containsPoint(point: Vector2){
|
public containsPoint(point: Vector2){
|
||||||
if (this.isUnrotated)
|
if (this.isUnrotated)
|
||||||
return this.bounds.contains(point);
|
return this.bounds.contains(point.x, point.y);
|
||||||
|
|
||||||
return super.containsPoint(point);
|
return super.containsPoint(point);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
class Circle extends Shape {
|
class Circle extends Shape {
|
||||||
public radius: number;
|
public radius: number;
|
||||||
private _originalRadius: number;
|
private _originalRadius: number;
|
||||||
|
public center = new Vector2();
|
||||||
|
|
||||||
constructor(radius: number) {
|
constructor(radius: number) {
|
||||||
super();
|
super();
|
||||||
@@ -32,7 +33,7 @@ class Circle extends Shape {
|
|||||||
public recalculateBounds(collider: Collider) {
|
public recalculateBounds(collider: Collider) {
|
||||||
this.center = collider.localOffset;
|
this.center = collider.localOffset;
|
||||||
|
|
||||||
if (collider.shouldColliderScaleAndRotationWithTransform) {
|
if (collider.shouldColliderScaleAndRotateWithTransform) {
|
||||||
let scale = collider.entity.scale;
|
let scale = collider.entity.scale;
|
||||||
let hasUnitScale = scale.x == 1 && scale.y == 1;
|
let hasUnitScale = scale.x == 1 && scale.y == 1;
|
||||||
let maxScale = Math.max(scale.x, scale.y);
|
let maxScale = Math.max(scale.x, scale.y);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class CollisionResult {
|
class CollisionResult {
|
||||||
public collider: Collider;
|
public collider: Collider;
|
||||||
public minimumTranslationVector: Vector2;
|
public minimumTranslationVector: Vector2 = Vector2.zero;
|
||||||
public normal: Vector2;
|
public normal: Vector2 = Vector2.zero;
|
||||||
public point: Vector2;
|
public point: Vector2 = Vector2.zero;
|
||||||
|
|
||||||
public invertResult(){
|
public invertResult(){
|
||||||
this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector);
|
this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class Polygon extends Shape {
|
|||||||
private _polygonCenter: Vector2;
|
private _polygonCenter: Vector2;
|
||||||
private _areEdgeNormalsDirty = true;
|
private _areEdgeNormalsDirty = true;
|
||||||
protected _originalPoints: Vector2[];
|
protected _originalPoints: Vector2[];
|
||||||
|
public center = new Vector2();
|
||||||
|
|
||||||
public _edgeNormals: Vector2[];
|
public _edgeNormals: Vector2[];
|
||||||
public get edgeNormals(){
|
public get edgeNormals(){
|
||||||
@@ -103,6 +104,13 @@ class Polygon extends Shape {
|
|||||||
return new Vector2(x / points.length, y / points.length);
|
return new Vector2(x / points.length, y / points.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 迭代多边形的所有边,并得到任意边上离点最近的点。
|
||||||
|
* 通过最近点的平方距离和它所在的边的法线返回。
|
||||||
|
* 点应该在多边形的空间中(点-多边形.位置)
|
||||||
|
* @param points
|
||||||
|
* @param point
|
||||||
|
*/
|
||||||
public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } {
|
public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } {
|
||||||
let distanceSquared = Number.MAX_VALUE;
|
let distanceSquared = Number.MAX_VALUE;
|
||||||
let edgeNormal = new Vector2(0, 0);
|
let edgeNormal = new Vector2(0, 0);
|
||||||
@@ -121,6 +129,7 @@ class Polygon extends Shape {
|
|||||||
distanceSquared = tempDistanceSquared;
|
distanceSquared = tempDistanceSquared;
|
||||||
closestPoint = closest;
|
closestPoint = closest;
|
||||||
|
|
||||||
|
// 求直线的法线
|
||||||
let line = Vector2.subtract(points[j], points[i]);
|
let line = Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal.x = -line.y;
|
edgeNormal.x = -line.y;
|
||||||
edgeNormal.y = line.x;
|
edgeNormal.y = line.x;
|
||||||
@@ -136,7 +145,13 @@ class Polygon extends Shape {
|
|||||||
return ShapeCollisions.pointToPoly(point, this);
|
return ShapeCollisions.pointToPoly(point, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本质上,这个算法所做的就是从一个点发射一条射线。
|
||||||
|
* 如果它与奇数条多边形边相交,我们就知道它在多边形内部。
|
||||||
|
* @param point
|
||||||
|
*/
|
||||||
public containsPoint(point: Vector2) {
|
public containsPoint(point: Vector2) {
|
||||||
|
// 将点归一化到多边形坐标空间中
|
||||||
point = Vector2.subtract(point, this.position);
|
point = Vector2.subtract(point, this.position);
|
||||||
|
|
||||||
let isInside = false;
|
let isInside = false;
|
||||||
@@ -168,9 +183,10 @@ class Polygon extends Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public recalculateBounds(collider: Collider) {
|
public recalculateBounds(collider: Collider) {
|
||||||
this.center = collider.localOffset;
|
// 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始
|
||||||
|
// this.center = collider.localOffset;
|
||||||
if (collider.shouldColliderScaleAndRotationWithTransform){
|
let localOffset = collider.localOffset;
|
||||||
|
if (collider.shouldColliderScaleAndRotateWithTransform){
|
||||||
let hasUnitScale = true;
|
let hasUnitScale = true;
|
||||||
let tempMat: Matrix2D;
|
let tempMat: Matrix2D;
|
||||||
let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
|
let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
|
||||||
@@ -180,31 +196,34 @@ class Polygon extends Shape {
|
|||||||
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
||||||
|
|
||||||
hasUnitScale = false;
|
hasUnitScale = false;
|
||||||
|
|
||||||
|
// 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置
|
||||||
let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale);
|
let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale);
|
||||||
this.center = scaledOffset;
|
localOffset = scaledOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collider.entity.rotation != 0){
|
if (collider.entity.rotation != 0){
|
||||||
tempMat = Matrix2D.createRotation(collider.entity.rotation);
|
tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat);
|
||||||
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
||||||
|
|
||||||
|
// 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动我们的偏移使角度为0
|
||||||
|
// 我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。
|
||||||
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
|
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
|
||||||
let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
|
let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
|
||||||
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle);
|
localOffset = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y);
|
tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y);
|
||||||
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
||||||
|
|
||||||
|
// 最后变换原始点
|
||||||
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
|
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
|
||||||
this.isUnrotated = collider.entity.rotation == 0;
|
this.isUnrotated = collider.entity.rotation == 0;
|
||||||
|
|
||||||
if (collider._isRotationDirty)
|
|
||||||
this._areEdgeNormalsDirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.position = Vector2.add(collider.entity.position, this.center);
|
this.position = Vector2.add(collider.entity.position, localOffset);
|
||||||
this.bounds = Rectangle.rectEncompassingPoints(this.points);
|
this.bounds = Rectangle.rectEncompassingPoints(this.points);
|
||||||
this.bounds.location = Vector2.add(this.bounds.location, this.position);
|
this.bounds.location = Vector2.add(this.bounds.location, this.position);
|
||||||
|
this.center = localOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
abstract class Shape {
|
abstract class Shape {
|
||||||
public bounds: Rectangle;
|
public bounds: Rectangle = new Rectangle();
|
||||||
public position: Vector2;
|
public position: Vector2 = Vector2.zero;
|
||||||
public center: Vector2;
|
public abstract center: Vector2;
|
||||||
|
|
||||||
public abstract recalculateBounds(collider: Collider);
|
public abstract recalculateBounds(collider: Collider);
|
||||||
public abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
public abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||||
|
|||||||
@@ -15,13 +15,17 @@ class ShapeCollisions {
|
|||||||
let polygonOffset = Vector2.subtract(first.position, second.position);
|
let polygonOffset = Vector2.subtract(first.position, second.position);
|
||||||
let axis: Vector2;
|
let axis: Vector2;
|
||||||
|
|
||||||
|
// 循环穿过两个多边形的所有边
|
||||||
for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) {
|
for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) {
|
||||||
|
// 1. 找出当前多边形是否相交
|
||||||
|
// 多边形的归一化轴垂直于缓存给我们的当前边
|
||||||
if (edgeIndex < firstEdges.length) {
|
if (edgeIndex < firstEdges.length) {
|
||||||
axis = firstEdges[edgeIndex];
|
axis = firstEdges[edgeIndex];
|
||||||
} else {
|
} else {
|
||||||
axis = secondEdges[edgeIndex - firstEdges.length];
|
axis = secondEdges[edgeIndex - firstEdges.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 求多边形在当前轴上的投影
|
||||||
let minA = 0;
|
let minA = 0;
|
||||||
let minB = 0;
|
let minB = 0;
|
||||||
let maxA = 0;
|
let maxA = 0;
|
||||||
@@ -34,17 +38,24 @@ class ShapeCollisions {
|
|||||||
minB = tb.min;
|
minB = tb.min;
|
||||||
maxB = tb.max;
|
maxB = tb.max;
|
||||||
|
|
||||||
|
// 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。
|
||||||
let relativeIntervalOffset = Vector2.dot(polygonOffset, axis);
|
let relativeIntervalOffset = Vector2.dot(polygonOffset, axis);
|
||||||
minA += relativeIntervalOffset;
|
minA += relativeIntervalOffset;
|
||||||
maxA += relativeIntervalOffset;
|
maxA += relativeIntervalOffset;
|
||||||
|
|
||||||
|
// 检查多边形投影是否正在相交
|
||||||
intervalDist = this.intervalDistance(minA, maxA, minB, maxB);
|
intervalDist = this.intervalDistance(minA, maxA, minB, maxB);
|
||||||
if (intervalDist > 0)
|
if (intervalDist > 0)
|
||||||
isIntersecting = false;
|
isIntersecting = false;
|
||||||
|
|
||||||
|
// 对于多对多数据类型转换,添加一个Vector2?参数称为deltaMovement。为了提高速度,我们这里不使用它
|
||||||
|
// TODO: 现在找出多边形是否会相交。只要检查速度就行了
|
||||||
|
|
||||||
|
// 如果多边形不相交,也不会相交,退出循环
|
||||||
if (!isIntersecting)
|
if (!isIntersecting)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// 检查当前间隔距离是否为最小值。如果是,则存储间隔距离和当前距离。这将用于计算最小平移向量
|
||||||
intervalDist = Math.abs(intervalDist);
|
intervalDist = Math.abs(intervalDist);
|
||||||
if (intervalDist < minIntervalDistance) {
|
if (intervalDist < minIntervalDistance) {
|
||||||
minIntervalDistance = intervalDist;
|
minIntervalDistance = intervalDist;
|
||||||
@@ -55,8 +66,9 @@ class ShapeCollisions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 利用最小平移向量对多边形进行推入。
|
||||||
result.normal = translationAxis;
|
result.normal = translationAxis;
|
||||||
result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance));
|
result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -252,4 +264,39 @@ class ShapeCollisions {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param first
|
||||||
|
* @param second
|
||||||
|
*/
|
||||||
|
public static boxToBox(first: Box, second: Box){
|
||||||
|
let result = new CollisionResult();
|
||||||
|
|
||||||
|
let minkowskiDiff = this.minkowskiDifference(first, second);
|
||||||
|
if (minkowskiDiff.contains(0, 0)){
|
||||||
|
// 计算MTV。如果它是零,我们就可以称它为非碰撞
|
||||||
|
result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
|
||||||
|
|
||||||
|
if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
|
||||||
|
result.normal.normalize();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static minkowskiDifference(first: Box, second: Box){
|
||||||
|
// 我们需要第一个框的左上角
|
||||||
|
// 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。
|
||||||
|
let positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2))));
|
||||||
|
let topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max);
|
||||||
|
let fullSize = Vector2.add(first.bounds.size, second.bounds.size);
|
||||||
|
|
||||||
|
return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,15 @@ class SpatialHash {
|
|||||||
public gridBounds: Rectangle = new Rectangle();
|
public gridBounds: Rectangle = new Rectangle();
|
||||||
|
|
||||||
private _raycastParser: RaycastResultParser;
|
private _raycastParser: RaycastResultParser;
|
||||||
|
/** 散列中每个单元格的大小 */
|
||||||
private _cellSize: number;
|
private _cellSize: number;
|
||||||
|
/** 1除以单元格大小。缓存结果,因为它被大量使用。 */
|
||||||
private _inverseCellSize: number;
|
private _inverseCellSize: number;
|
||||||
private _overlapTestCircle: Circle;
|
/** 缓存的循环用于重叠检查 */
|
||||||
|
private _overlapTestCircle: Circle = new Circle(0);
|
||||||
|
/** 用于返回冲突信息的共享HashSet */
|
||||||
private _tempHashSet: Collider[] = [];
|
private _tempHashSet: Collider[] = [];
|
||||||
|
/** 保存所有数据的字典 */
|
||||||
private _cellDict: NumberDictionary = new NumberDictionary();
|
private _cellDict: NumberDictionary = new NumberDictionary();
|
||||||
|
|
||||||
constructor(cellSize: number = 100) {
|
constructor(cellSize: number = 100) {
|
||||||
@@ -14,6 +19,10 @@ class SpatialHash {
|
|||||||
this._raycastParser = new RaycastResultParser();
|
this._raycastParser = new RaycastResultParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从SpatialHash中删除对象
|
||||||
|
* @param collider
|
||||||
|
*/
|
||||||
public remove(collider: Collider) {
|
public remove(collider: Collider) {
|
||||||
let bounds = collider.registeredPhysicsBounds;
|
let bounds = collider.registeredPhysicsBounds;
|
||||||
let p1 = this.cellCoords(bounds.x, bounds.y);
|
let p1 = this.cellCoords(bounds.x, bounds.y);
|
||||||
@@ -21,6 +30,7 @@ class SpatialHash {
|
|||||||
|
|
||||||
for (let x = p1.x; x <= p2.x; x++) {
|
for (let x = p1.x; x <= p2.x; x++) {
|
||||||
for (let y = p1.y; y <= p2.y; y++) {
|
for (let y = p1.y; y <= p2.y; y++) {
|
||||||
|
// 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中
|
||||||
let cell = this.cellAtPosition(x, y);
|
let cell = this.cellAtPosition(x, y);
|
||||||
if (!cell)
|
if (!cell)
|
||||||
console.error(`removing Collider [${collider}] from a cell that it is not present in`);
|
console.error(`removing Collider [${collider}] from a cell that it is not present in`);
|
||||||
@@ -30,22 +40,28 @@ class SpatialHash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象添加到SpatialHash
|
||||||
|
* @param collider
|
||||||
|
*/
|
||||||
public register(collider: Collider) {
|
public register(collider: Collider) {
|
||||||
let bounds = collider.bounds;
|
let bounds = collider.bounds;
|
||||||
collider.registeredPhysicsBounds = bounds;
|
collider.registeredPhysicsBounds = bounds;
|
||||||
let p1 = this.cellCoords(bounds.x, bounds.y);
|
let p1 = this.cellCoords(bounds.x, bounds.y);
|
||||||
let p2 = this.cellCoords(bounds.right, bounds.bottom);
|
let p2 = this.cellCoords(bounds.right, bounds.bottom);
|
||||||
|
|
||||||
if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) {
|
// 更新边界以跟踪网格大小
|
||||||
|
if (!this.gridBounds.contains(p1.x, p1.y)) {
|
||||||
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
|
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) {
|
if (!this.gridBounds.contains(p2.x, p2.y)) {
|
||||||
this.gridBounds = RectangleExt.union(this.gridBounds, p2);
|
this.gridBounds = RectangleExt.union(this.gridBounds, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let x = p1.x; x <= p2.x; x++) {
|
for (let x = p1.x; x <= p2.x; x++) {
|
||||||
for (let y = p1.y; y <= p2.y; y++) {
|
for (let y = p1.y; y <= p2.y; y++) {
|
||||||
|
// 如果没有单元格,我们需要创建它
|
||||||
let c = this.cellAtPosition(x, y, true);
|
let c = this.cellAtPosition(x, y, true);
|
||||||
c.push(collider);
|
c.push(collider);
|
||||||
}
|
}
|
||||||
@@ -56,6 +72,13 @@ class SpatialHash {
|
|||||||
this._cellDict.clear();
|
this._cellDict.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取位于指定圆内的所有碰撞器
|
||||||
|
* @param circleCenter
|
||||||
|
* @param radius
|
||||||
|
* @param results
|
||||||
|
* @param layerMask
|
||||||
|
*/
|
||||||
public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) {
|
public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) {
|
||||||
let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
|
let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
|
||||||
|
|
||||||
@@ -63,7 +86,9 @@ class SpatialHash {
|
|||||||
this._overlapTestCircle.position = circleCenter;
|
this._overlapTestCircle.position = circleCenter;
|
||||||
|
|
||||||
let resultCounter = 0;
|
let resultCounter = 0;
|
||||||
let potentials = this.aabbBroadphase(bounds, null, layerMask);
|
let aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask);
|
||||||
|
bounds = aabbBroadphaseResult.bounds;
|
||||||
|
let potentials = aabbBroadphaseResult.tempHashSet;
|
||||||
for (let i = 0; i < potentials.length; i++) {
|
for (let i = 0; i < potentials.length; i++) {
|
||||||
let collider = potentials[i];
|
let collider = potentials[i];
|
||||||
if (collider instanceof BoxCollider) {
|
if (collider instanceof BoxCollider) {
|
||||||
@@ -80,6 +105,12 @@ class SpatialHash {
|
|||||||
return resultCounter;
|
return resultCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回边框与单元格相交的所有对象
|
||||||
|
* @param bounds
|
||||||
|
* @param excludeCollider
|
||||||
|
* @param layerMask
|
||||||
|
*/
|
||||||
public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) {
|
public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) {
|
||||||
this._tempHashSet.length = 0;
|
this._tempHashSet.length = 0;
|
||||||
|
|
||||||
@@ -92,9 +123,11 @@ class SpatialHash {
|
|||||||
if (!cell)
|
if (!cell)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// 当cell不为空。循环并取回所有碰撞器
|
||||||
for (let i = 0; i < cell.length; i++) {
|
for (let i = 0; i < cell.length; i++) {
|
||||||
let collider = cell[i];
|
let collider = cell[i];
|
||||||
|
|
||||||
|
// 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器
|
||||||
if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
|
if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -106,9 +139,16 @@ class SpatialHash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._tempHashSet;
|
return {tempHashSet: this._tempHashSet, bounds: bounds};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取世界空间x,y值的单元格。
|
||||||
|
* 如果单元格为空且createCellIfEmpty为true,则会创建一个新的单元格
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param createCellIfEmpty
|
||||||
|
*/
|
||||||
private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) {
|
private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) {
|
||||||
let cell: Collider[] = this._cellDict.tryGetValue(x, y);
|
let cell: Collider[] = this._cellDict.tryGetValue(x, y);
|
||||||
if (!cell) {
|
if (!cell) {
|
||||||
@@ -120,8 +160,13 @@ class SpatialHash {
|
|||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
private cellCoords(x: number, y: number): Point {
|
/**
|
||||||
return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
|
* 获取单元格的x,y值作为世界空间的x,y值
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
*/
|
||||||
|
private cellCoords(x: number, y: number): Vector2 {
|
||||||
|
return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +174,10 @@ class RaycastResultParser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包装一个Unit32,列表碰撞器字典
|
||||||
|
* 它的主要目的是将int、int x、y坐标散列到单个Uint32键中,使用O(1)查找。
|
||||||
|
*/
|
||||||
class NumberDictionary {
|
class NumberDictionary {
|
||||||
private _store: Map<number, Collider[]> = new Map<number, Collider[]>();
|
private _store: Map<number, Collider[]> = new Map<number, Collider[]>();
|
||||||
|
|
||||||
@@ -141,6 +190,10 @@ class NumberDictionary {
|
|||||||
return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString();
|
return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
private intToUint(i) {
|
private intToUint(i) {
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
return i;
|
return i;
|
||||||
@@ -152,6 +205,10 @@ class NumberDictionary {
|
|||||||
this._store.set(this.getKey(x, y), list);
|
this._store.set(this.getKey(x, y), list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用蛮力方法从字典存储列表中移除碰撞器
|
||||||
|
* @param obj
|
||||||
|
*/
|
||||||
public remove(obj: Collider) {
|
public remove(obj: Collider) {
|
||||||
this._store.forEach(list => {
|
this._store.forEach(list => {
|
||||||
if (list.contains(obj))
|
if (list.contains(obj))
|
||||||
@@ -163,6 +220,9 @@ class NumberDictionary {
|
|||||||
return this._store.get(this.getKey(x, y));
|
return this._store.get(this.getKey(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除字典数据
|
||||||
|
*/
|
||||||
public clear() {
|
public clear() {
|
||||||
this._store.clear();
|
this._store.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
class RectangleExt {
|
class RectangleExt {
|
||||||
public static union(first: Rectangle, point: Point){
|
public static union(first: Rectangle, point: Vector2){
|
||||||
let rect = new Rectangle(point.x, point.y, 0, 0);
|
let rect = new Rectangle(point.x, point.y, 0, 0);
|
||||||
return this.unionR(first, rect);
|
let rectResult = first.union(rect);
|
||||||
}
|
return new Rectangle(rectResult.x, rectResult.y, rectResult.width, rectResult.height);
|
||||||
|
|
||||||
public static unionR(value1: Rectangle, value2: Rectangle){
|
|
||||||
let result = new Rectangle();
|
|
||||||
result.x = Math.min(value1.x, value2.x);
|
|
||||||
result.y = Math.min(value1.y, value2.y);
|
|
||||||
result.width = Math.max(value1.right, value2.right) - result.x;
|
|
||||||
result.height = Math.max(value1.bottom, value2.bottom) - result.y;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,15 @@ class Vector2Ext {
|
|||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过指定的矩阵对Vector2的数组中的向量应用变换,并将结果放置在另一个数组中。
|
||||||
|
* @param sourceArray
|
||||||
|
* @param sourceIndex
|
||||||
|
* @param matrix
|
||||||
|
* @param destinationArray
|
||||||
|
* @param destinationIndex
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
public static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D,
|
public static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D,
|
||||||
destinationArray: Vector2[], destinationIndex: number, length: number) {
|
destinationArray: Vector2[], destinationIndex: number, length: number) {
|
||||||
for (let i = 0; i < length; i ++){
|
for (let i = 0; i < length; i ++){
|
||||||
@@ -60,6 +69,12 @@ class Vector2Ext {
|
|||||||
return new Vector2(x, y);
|
return new Vector2(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过指定的矩阵对Vector2的数组中的所有向量应用变换,并将结果放到另一个数组中。
|
||||||
|
* @param sourceArray
|
||||||
|
* @param matrix
|
||||||
|
* @param destinationArray
|
||||||
|
*/
|
||||||
public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) {
|
public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) {
|
||||||
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
|
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
"module": "system",
|
"module": "system",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user