duckengine
Version:
A 2D Game Engine for the web.
240 lines (239 loc) • 7.59 kB
TypeScript
import { Duck } from '../../..';
import Game from '../../game';
import Group from '../../group/group';
import Vector2 from '../../math/vector2';
import Scene from '../../scene';
import PhysicsBody from '../physicsBody';
/**
* @class Hitbox
* @classdesc Creates a DuckEngine Hitbox
* @description The Hitbox Class. A AABB Hitbox used for Colliders
* @since 2.0.0
*/
export default class Hitbox implements Duck.Types.Renderable {
/**
* @memberof Hitbox
* @description The unique identifier for a Hitbox
* @type string
* @since 2.0.0
*/
readonly id: string;
/**
* @memberof Hitbox
* @description The Position of the Hitbox
* @type Vector2
* @since 2.0.0
*/
position: Vector2;
/**
* @memberof Hitbox
* @description The Offset Position of the hitbox
* @type Vector2
* @since 2.0.0
*/
offset: Vector2;
/**
* @memberof Hitbox
* @description The Width of the Hitbox
* @type number
* @since 2.0.0
*/
w: number;
/**
* @memberof Hitbox
* @description The Height of the Hitbox
* @type number
* @since 2.0.0
*/
h: number;
/**
* @memberof Hitbox
* @description Game instance
* @type Game
* @since 2.0.0
*/
game: Game;
/**
* @memberof Hitbox
* @description Scene instance
* @type Scene
* @since 2.0.0
*/
scene: Scene;
/**
* @memberof Hitbox
* @description PhysicsBody that the Hitbox is attached to
* @type PhysicsBody<Duck.Types.Texture.Type>
* @since 2.0.0
*/
physicsObject: PhysicsBody<Duck.Types.Texture.Type>;
/**
* @memberof Hitbox
* @description The debug color of the Hitbox, determines if the visibility of the hitbox
* @type string | undefined
* @since
*/
debugColor: string | undefined;
/**
* @memberof Hitbox
* @description Determines if the Hitbox will be drawn on the screen as a debug aid
* @type boolean
* @since 2.0.0
*/
visible: boolean;
/**
* @memberof Hitbox
* @description The zIndex of the Hitbox, effects how the Hitbox is layered if it is drawn on the screen as a debug aid
* @type number
* @since 2.0.0
*/
zIndex: number;
/**
* @memberof Hitbox
* @description Determines if the Hitbox should be visible by the current scene's current camera
* @type boolean
* @since 2.1.0
*/
culled: boolean;
/**
* @memberof Hitbox
* @description A string determining the state of the current collision
* @type Duck.Types.Collider.CollisionResponseType
* @since 2.0.0
*/
collisionState: Duck.Types.Collider.CollisionResponseType;
/**
* @constructor Hitbox
* @param {number} id The PhysicsBody ID
* @param {Vector2} position The position of the Hitbox
* @param {number} w The width of the Hitbox
* @param {number} h The height of the Hitbox
* @param {Vector2} offset The offset position of the Hitbox
* @param {PhysicsBody<Duck.Types.Texture.Type>} physicsObject The PhysicsBody that the Hitbox is attached to
* @param {Game} game Game instance
* @param {Scene} scene Scene instance
* @param {string|undefined} [debugColor=undefined] The debugColor of the Hitbox
*/
constructor(position: Vector2, w: number, h: number, offset: Vector2, physicsObject: PhysicsBody<Duck.Types.Texture.Type>, game: Game, scene: Scene, debugColor?: string);
/**
* @memberof Hitbox
* @description Draws the hitbox if a debugColor is passed in the constructor.
*
* DO NOT CALL MANUALLY, CALLED IN GAME LOOP USING SCENE.displayList
*
* @since 2.0.0
*/
_draw(): void;
/**
* @memberof Hitbox
* @description Sets the Hitboxes position to the PhysicsBodies position plus the passed offset if one was set
*
* DO NOT CALL MANUALLY, CALLED IN SCENE.__tick
*
* @since 2.0.0
*/
_update(physicsObject: PhysicsBody<Duck.Types.Texture.Type>): void;
/**
* @memberof Hitbox
* @description Sets the debugColor and visibility of the Hitbox as a debug aid
* @param {string} debugColor Color
* @param {boolean} [visible=true] What to set the visible property as, optional -> defaults: true
* @since 2.0.0
*/
setDebugColor(debugColor: string, visible?: boolean): void;
/**
* @memberof Hitbox
* @description Sets the width and height of the Hitbox
* @param {Vector2} scale The new scale of the Hitbox
* @since 2.0.0
*/
scale(scale: Vector2): void;
/**
* @memberof Hitbox
* @description Sets position of the Hitbox
* @param {Vector2} newPosition The new position of the Hitbox
* @param {Vector2} [offset] The new offset position of the Hitbox, optional -> defaults: Hitbox.offset
* @since 2.0.0
*/
setPosition(newPosition: Vector2, offset?: Vector2): void;
/**
* @memberof Hitbox
* @description Auto scales, positions, and offsets the Hitbox based on the shape of the PhysicsBody
* @param {Vector2} [offset] The new offset position of the Hitbox, optional
* @since 2.0.0
*/
auto(offset?: Vector2): void;
/**
* @memberof Hitbox
* @description Checks if the Hitbox is intersecting with another Hitbox
* @param {Hitbox} Hitbox Hitbox to use to test the intersection
* @returns {boolean}
* @since 2.0.0
*/
intersectsWith(hitbox: Hitbox): boolean;
/**
* @memberof Hitbox
* @description Checks if the Hitbox is intersecting with another Hitbox and returns the face that is colliding
* @param {Hitbox} hitbox Hitbox to use to test the intersection
* @returns {Duck.Types.Collider.CollisionResponseType}
* @since 2.0.0
*/
intersectsFaceWith(hitbox: Hitbox): Duck.Types.Collider.CollisionResponseType;
/**
* @memberof Hitbox
* @description Checks if the Hitbox is intersecting with other Hitboxes and returns the face that is colliding
* @param {Group<Hitbox> | Hitbox[]} hitboxes Hitboxes to use to test the intersection
* @returns {Duck.Types.Collider.CollisionResponseType[]}
* @since 2.0.0
*/
groupIntersectsFaceWith(hitboxes: Group<Hitbox> | Hitbox[]): Duck.Types.Collider.CollisionResponseType[];
/**
* @memberof Hitbox
* @description Gets the top most coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getTop(): number;
/**
* @memberof Hitbox
* @description Gets the bottom most coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getBottom(): number;
/**
* @memberof Hitbox
* @description Gets the left most coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getLeft(): number;
/**
* @memberof Hitbox
* @description Gets the right most coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getRight(): number;
/**
* @memberof Hitbox
* @description Gets the center coordinates of the Hitbox
* @returns {Vector2}
* @since 2.0.0
*/
getCenter(): Vector2;
/**
* @memberof Hitbox
* @description Gets the centerY coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getCenterY(): number;
/**
* @memberof Hitbox
* @description Gets the centerX coordinate of the Hitbox
* @returns {number}
* @since 2.0.0
*/
getCenterX(): number;
}