the-world-engine
Version:
three.js based, unity like game engine for browser
169 lines (168 loc) • 5.26 kB
TypeScript
import { Vector2 } from "three/src/Three";
import type { IEventContainer } from "../../collection/EventContainer";
import type { ReadonlyVector2 } from "../../math/ReadonlyVector2";
import type { IGridCollidable } from "../grid_physics2d/IGridCollidable";
import { Directable } from "../helper/Directable";
import type { IGridPositionable } from "../helper/IGridPositionable";
import type { GridPointer } from "../input/GridPointer";
/**
* make gameobject moves on grid coordinates
*
* supports keyboard wasd and arrow keys input
*
* supports pathfinding as optional feature
*
* disallow multiple component
*/
export declare class PlayerGridMovementController extends Directable implements IGridPositionable {
readonly disallowMultipleComponent: boolean;
private _speed;
private _gridCellHeight;
private _gridCellWidth;
private readonly _collideMaps;
private readonly _collideSize;
private readonly _gridCenter;
private readonly _currentPosition;
private readonly _targetPosition;
private readonly _initPosition;
private readonly _onMoveToTargetEvent;
private readonly _onMovedToTargetEvent;
private _gridPointer;
private _pathfinder;
private _movingByPathfinder;
private _foundedPath;
private _currentPathIndex;
private _pathfindStartFunction;
private readonly _cachedParentWorldPosition;
private _receiveKeyboardInput;
private readonly _tempVector2;
private readonly _temp2Vector2;
start(): void;
update(): void;
private processInput;
private noncheckProcessInput;
private invokeOnMoveToTarget;
private invokeOnMovedToTarget;
private tryCancelPathfinder;
private processPathfinderInput;
private processMovement;
/**
*
* @param x local position x
* @param y local position y
* @returns
*/
private checkCollision;
private _lastPointerDownTime;
private readonly _lastPointerDownPosition;
private readonly _doubleClickTime;
private readonly onPointerDown;
private onDoubleClick;
/**
* try to move to target grid position
* @param targetGridPosition
* @returns if object already moving by pathfinder return false,
*
* if object can't move to target grid position return false,
*
* if object can move to target grid position return true
*/
tryStartPathfind(targetGridPosition: ReadonlyVector2): boolean;
/**
* cancel moving by pathfinder
*/
cancelPathfind(): void;
/**
* on move to target event position is grid position (integer)
*/
get onMoveToTarget(): IEventContainer<(x: number, y: number) => void>;
/**
* on moved to target event position is grid position (integer)
*/
get onMovedToTarget(): IEventContainer<(x: number, y: number) => void>;
/**
* teleport to target grid position
* @param positionInGrid position in grid coordinates
*/
teleport(positionInGrid: ReadonlyVector2): void;
/**
* move speed (default: 8)
*/
get speed(): number;
/**
* move speed (default: 8)
*/
set speed(value: number);
/**
* grid center position (default: (0, 0))
*/
get gridCenter(): ReadonlyVector2;
/**
* grid center position (default: (0, 0))
*/
set gridCenter(value: ReadonlyVector2);
/**
* grid cell height (default: 1)
*/
get gridCellHeight(): number;
/**
* grid cell height (default: 1)
*/
set gridCellHeight(value: number);
/**
* grid cell width (default: 1)
*/
get gridCellWidth(): number;
/**
* grid cell width (default: 1)
*/
set gridCellWidth(value: number);
/**
* initial grid position (default: (0, 0))
*
* this option is valid only when evaluated before PlayerGridMovementController.start()
*/
set initPosition(value: ReadonlyVector2);
/**
* grid pointer for pathfinding (default: null)
*/
set gridPointer(value: GridPointer | null);
/**
* grid pointer for pathfinding (default: null)
*/
get gridPointer(): GridPointer | null;
/**
* add collide map for collision detection
* @param collideMap
*/
addCollideMap(collideMap: IGridCollidable): void;
/**
* remove collide map for collision detection
*/
removeCollideMap(collideMap: IGridCollidable): void;
/**
* remove all collide maps for collision detection
*/
removeAllCollideMaps(): void;
/**
* set grid cell size and grid center position from grid collide map
* @param collideMap
*/
setGridInfoFromCollideMap(collideMap: IGridCollidable): void;
/**
* position in grid coordinate(integer value)
*/
get positionInGrid(): Vector2;
/**
* receive keyboard input (default: true)
*
* if set true, this object will receive keyboard w, a, s, d, arrow up, arrow down, arrow left, arrow right input
*/
get receiveKeyboardInput(): boolean;
/**
* receive keyboard input (default: true)
*
* if set true, this object will receive keyboard w, a, s, d, arrow up, arrow down, arrow left, arrow right input
*/
set receiveKeyboardInput(value: boolean);
}