diff --git a/.gitignore b/.gitignore index b29a32a4..c2e3f7d7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ res.json *.mp3 tests *.res.js -*.txt \ No newline at end of file +*.txt +animations \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d0530b47..24b6b370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,5 +5,11 @@ - Added a changelog. - Fixed path behaviour where agent doesn't advance to the next path. - - Manager is now created though createManager(). - - Entity.Default() has been moved to createEntity() \ No newline at end of file + - Manager is now created though `createManager()`. + - `Entity.Default()` has been moved to `createEntity()` + +### v0.5.1 + + - Added signals to the events through `Sigbal()` class. + - Renamed `Vec2()` to `Vector2()` + - Fixed `Overlap.AABBvsSphere()` to return the correct value. \ No newline at end of file diff --git a/README.md b/README.md index f621e43f..2223d454 100644 --- a/README.md +++ b/README.md @@ -158,17 +158,17 @@ game.add(ground) ## **** FUTURE WORK **** - - Add a webgl renderer(dont have a direct plan for this yet)🟠 - - Stabilize the collision response to work well with large forces such as (gravity = 10000) - - Stabilize rotational stacking in the physics engine - - Add game state class for managing the game - - Add an animation system. - - Add tutorials to this game engine - - Add appropriate demos to the project and get a website running for them 🟠 - - Add some error handling mechanisms 🟠 - - Add Serialization/Deserialization of objects(on the way) 🟠 - - Kinematic bodies. - - Collision masking using bits(bit masking) - - More AI behaviors. - - Add indexedDB to Storage API. - - An audio tag fallback to Web audio (if necessary ) \ No newline at end of file + [] Add a webgl renderer(~~dont have a direct plan for this yet~~ Now i do :) ) + []Stabilize the collision response to work well with large forces such as (gravity = 10000) + []Stabilize rotational stacking in the physics engine + []~~Add game state class for managing the game~~ + []Add an animation system. + []Add tutorials to this game engine + []Add appropriate demos to the project and get a website running for them + []Add some error handling mechanisms + [x]Add Serialization/Deserialization of objects(on the way) + []Kinematic bodies. + []Collision masking using bits(bit masking) + []More AI behaviors. + []Add indexedDB to Storage API. + []An audio tag fallback to Web audio (if necessary ) \ No newline at end of file diff --git a/demos/bridge.js b/demos/bridge.js index 6b12ad14..87f76ce5 100644 --- a/demos/bridge.js +++ b/demos/bridge.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, Box, DistanceConstraint, Entity, @@ -41,8 +41,8 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { for (var i = 1; i < number; i++) { let chain = new Box(w, h) - let an1 = prev.setAnchor(new Vec2(w/2,0)) - let an2 = prev.setAnchor(new Vec2(w/2,0)) + let an1 = prev.setAnchor(new Vector2(w/2,0)) + let an2 = prev.setAnchor(new Vector2(w/2,0)) let constraint = new DistanceConstraint(prev, chain, prev.getAnchor(an1),chain.getAnchor(an2)) bodies.push( @@ -55,15 +55,15 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { prev = chain } if (pin1) { - let an1 = pin1.get("body").setAnchor(new Vec2(0,0)) - let an2 = bodies[0].get("body").setAnchor(new Vec2(-w/2,0)) + let an1 = pin1.get("body").setAnchor(new Vector2(0,0)) + let an2 = bodies[0].get("body").setAnchor(new Vector2(-w/2,0)) let constraint = new DistanceConstraint(pin1.get("body"), bodies[0].get("body"), pin1.get("body").getAnchor(an1), bodies[0].get("body").getAnchor(an2)) constraints.push(constraint) pin1.get("body").mask.group = 1 } if (pin2) { - let an1 = pin2.get("body").setAnchor(new Vec2(0,0)) - let an2 = bodies[bodies.length - 1].get("body").setAnchor(new Vec2(w/2,0)) + let an1 = pin2.get("body").setAnchor(new Vector2(0,0)) + let an2 = bodies[bodies.length - 1].get("body").setAnchor(new Vector2(w/2,0)) let constraint = new DistanceConstraint(pin2.get("body"), bodies[bodies.length - 1].get("body"), pin2.get("body").getAnchor(an1), bodies[bodies.length - 1].get("body").getAnchor(an2)) constraints.push(constraint) pin2.get("body").mask.group = 1 diff --git a/demos/car.js b/demos/car.js index 8f9b680a..82602b10 100644 --- a/demos/car.js +++ b/demos/car.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, DistanceConstraint, Entity, Box, @@ -27,8 +27,8 @@ function createCar(x, y, tireSize = 20, maskgroup = 1, manager) { let tirebody1 = new Ball(tireSize) let tirebody2 = new Ball(tireSize) let carbody = new Box(100, 50) - let an1 = carbody.setAnchor(new Vec2(30,25)) - let an2 = carbody.setAnchor(new Vec2(-30,25)) + let an1 = carbody.setAnchor(new Vector2(30,25)) + let an2 = carbody.setAnchor(new Vector2(-30,25)) let constraint1 = new DistanceConstraint(carbody, tirebody1,carbody.getAnchor(an1)) let constraint2 = new DistanceConstraint(carbody, tirebody2,carbody.getAnchor(an2)) let carCompositeBody = new Composite() diff --git a/demos/constraints.js b/demos/constraints.js index d43b194e..01a3e997 100644 --- a/demos/constraints.js +++ b/demos/constraints.js @@ -1,5 +1,5 @@ import { - Vec2, + Vector2, Entity, Box, BodySprite, @@ -20,8 +20,8 @@ export function constraint(manager) { box2.attach("body", body2) .attach("sprite", new BodySprite()) - let an1 = body1.setAnchor(new Vec2(25,-25)) - let an2 = body2.setAnchor(new Vec2(-25,-25)) + let an1 = body1.setAnchor(new Vector2(25,-25)) + let an2 = body2.setAnchor(new Vector2(-25,-25)) let constraint1 = new DistanceConstraint(body1,body2,body1.getAnchor(an1),body2.getAnchor(an2)) diff --git a/demos/marterial.js b/demos/marterial.js index b1d6a3ca..acbabcd0 100644 --- a/demos/marterial.js +++ b/demos/marterial.js @@ -4,7 +4,7 @@ import { BasicMaterial, StaticImageMaterial, SpriteMaterial, - Vec2, + Vector2, Entity } from "/src/index.js" const assets = { @@ -15,10 +15,10 @@ const assets = { export function materials(manager) { manager.clear() let geometry = new BufferGeometry([ - new Vec2(-50, -50), - new Vec2(-50, 50), - new Vec2(50, 50), - new Vec2(50, -50) + new Vector2(-50, -50), + new Vector2(-50, 50), + new Vector2(50, 50), + new Vector2(50, -50) ]) //Basic material diff --git a/demos/pathfollower.js b/demos/pathfollower.js index 2eb6e0c3..e9be3b53 100644 --- a/demos/pathfollower.js +++ b/demos/pathfollower.js @@ -7,7 +7,7 @@ import { PathFollowing, WanderBehaviour, Path, - Vec2 + Vector2 } from "/src/index.js" export function pathfollower(manager) { @@ -30,11 +30,11 @@ export function pathfollower(manager) { manager.add(a) - p.add(new Vec2(100,50)) - p.add(new Vec2(300,100)) - p.add(new Vec2(300,400)) - p.add(new Vec2(200,400)) - p.add(new Vec2(100,350)) + p.add(new Vector2(100,50)) + p.add(new Vector2(300,100)) + p.add(new Vector2(300,400)) + p.add(new Vector2(200,400)) + p.add(new Vector2(100,350)) p.loop = true } \ No newline at end of file diff --git a/demos/seeker.js b/demos/seeker.js index 950efa22..fc616ea9 100644 --- a/demos/seeker.js +++ b/demos/seeker.js @@ -4,7 +4,7 @@ import { AgentSprite, SeekBehaviour, EvadeBehaviour, - Vec2, + Vector2, Box, rand } from "/src/index.js" diff --git a/demos/wanderer.js b/demos/wanderer.js index fdb6dfd3..92d6ae42 100644 --- a/demos/wanderer.js +++ b/demos/wanderer.js @@ -4,7 +4,7 @@ import { BodySprite, AgentSprite, WanderBehaviour, - Vec2, + Vector2, Box, rand } from "/src/index.js" diff --git a/dist/chaos.module.d.ts b/dist/chaos.module.d.ts index 9810791d..f2036ae2 100644 --- a/dist/chaos.module.d.ts +++ b/dist/chaos.module.d.ts @@ -14,13 +14,13 @@ export type Manifold = { stmp: number; impulse: number; persistent: boolean; - ca1: Vec2; - ca2: Vec2; + ca1: Vector2; + ca2: Vector2; restitution: number; staticFriction: number; kineticFriction: number; - velA: Vec2; - velB: Vec2; + velA: Vector2; + velB: Vector2; rotA: number; rotB: number; }; @@ -28,9 +28,9 @@ export type ContactManifold = { lastOverlap: number; overlap: number; done: boolean; - axis: Vec2; - verticesA: Vec2[]; - verticesB: Vec2[]; + axis: Vector2; + verticesA: Vector2[]; + verticesB: Vector2[]; vertShapeA: Shape; vertShapeB: Shape; contactNo: number; @@ -42,9 +42,9 @@ export type Vector_like = { y: number; }; export class Agent implements Component { - position: Vec2; - velocity: Vec2; - acceleration: Vec2; + position: Vector2; + velocity: Vector2; + acceleration: Vector2; orientation: Angle; rotation: Angle; maxSpeed: number; @@ -86,9 +86,9 @@ export class Angle { }; } export class ArriveBehaviour extends Behaviour { - constructor(target: Vec2); + constructor(target: Vector2); radius: number; - target: Vec2; + target: Vector2; } export class AudioHandler { private ctx; @@ -121,13 +121,13 @@ export class BasicMaterial implements Material { render(ctx: CanvasRenderingContext2D, dt: number, path: Path2D): void; } export class Behaviour { - position: Vec2; - velocity: Vec2; + position: Vector2; + velocity: Vector2; maxSpeed: number; maxForce: number; active: boolean; init(agent: Agent): void; - calc(target: Vec2, inv_dt: number): void; + calc(target: Vector2, inv_dt: number): void; draw(renderer: Renderer): void; } export class Body implements Component { @@ -147,7 +147,7 @@ export class Body implements Component { private _type; private _localanchors; private anchors; - lastPosition: Vec2; + lastPosition: Vector2; inv_mass: number; inv_inertia: number; restitution: number; @@ -177,18 +177,18 @@ export class Body implements Component { get physicsType(): number; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; - set acceleration(arg: Vec2); - get acceleration(): Vec2; - set velocity(arg: Vec2); - get velocity(): Vec2; + set acceleration(arg: Vector2); + get acceleration(): Vector2; + set velocity(arg: Vector2); + get velocity(): Vector2; set rotation(arg: Angle); get rotation(): Angle; set angle(arg: number); get angle(): number; set density(arg: number); get density(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: Angle); get orientation(): Angle; set angularVelocity(arg: number); @@ -197,10 +197,10 @@ export class Body implements Component { get torque(): number; set angularAcceleration(arg: number); get angularAcceleration(): number; - setAnchor(v: Vec2): number; - getAnchor(index: number): Vec2; - getLocalAnchor(index: number, target?: Vec2): Vec2; - applyForce(force: Vec2, arm?: Vec2): void; + setAnchor(v: Vector2): number; + getAnchor(index: number): Vector2; + getLocalAnchor(index: number, target?: Vector2): Vector2; + applyForce(force: Vector2, arm?: Vector2): void; init(entity: Entity | null, composited?: boolean): void; update(): void; toJson(): { @@ -274,7 +274,7 @@ export class BoundingBox extends Component { min: Vector_like; intersects(bound: BoundingCircle | BoundingBox): boolean; calculateBounds(body: Body, padding?: number): void; - update(pos: Vec2): void; + update(pos: Vector2): void; clone(): BoundingBox; copy(bounds: BoundingBox): void; toJson(): { @@ -305,18 +305,18 @@ export class Box extends Body { constructor(w: number, h: number); } export class BufferGeometry { - constructor(vertices: Vec2[]); - readonly vertices: Vec2[]; + constructor(vertices: Vector2[]); + readonly vertices: Vector2[]; drawable: Path2D | WebGLVertexArrayObject; init(ctx: CanvasRenderingContext2D): void; } export class CamController { constructor(camera: Camera); - readonly offset: Vec2; + readonly offset: Vector2; transform: Transform; targetPosition: any; targetOrientation: Angle; - follow(position: Vec2, orientation?: Angle): void; + follow(position: Vector2, orientation?: Angle): void; followEntity(entity: Entity): void; setOffset(x: number, y: number): void; init(): void; @@ -324,20 +324,20 @@ export class CamController { } export class Camera { readonly transform: Transform; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; update(): void; } export class Circle extends Shape { static calcInertia(mass: number, radius: number): number; - constructor(radius: number, offset: Vec2, offsetAngle: number); + constructor(radius: number, offset: Vector2, offsetAngle: number); radius: number; - vertices: Vec2$1[]; + vertices: Vector2$1[]; type: number; - get position(): Vec2$1; + get position(): Vector2$1; toJson(): { radius: number; - offset: Vec2; + offset: Vector2; offAngle: number; shapeType: number; type: string; @@ -359,15 +359,15 @@ export class Clock { export class Component { static fromJson(): void; static toJson(): void; - entity: Entity | null; + static implement(component: any): void; destroy(): void; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; init(entity: Entity): void; update(dt: number): void; - get(n: string): any; + get(entity: any, n: string): any; requires(...names: string[]): void; - query(bound: CircleBounding | BoxBounding, target?: Entity): Entity[]; + query(entity: any, bound: CircleBounding | BoxBounding, target?: Entity): any; } export class Composite { entity: Entity | null; @@ -377,10 +377,10 @@ export class Composite { init(entity: Entity | null): void; add(object: Constraint | Body): number; update(): void; - set acceleration(arg: Vec2); - get acceleration(): Vec2; - set velocity(arg: Vec2); - get velocity(): Vec2; + set acceleration(arg: Vector2); + get acceleration(): Vector2; + set velocity(arg: Vector2); + get velocity(): Vector2; set angle(arg: number); get angle(): number; set mass(arg: number); @@ -389,15 +389,15 @@ export class Composite { get type(): number; set density(arg: number); get density(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: number); get orientation(): number; set angularVelocity(arg: number); get angularVelocity(): number; } export class Constraint { - constructor(body1: Body, body2: Body, localA: Vec2, localB: Vec2); + constructor(body1: Body, body2: Body, localA: Vector2, localB: Vector2); body1: Body; body2: Body; localA: any; @@ -569,7 +569,7 @@ export class Entity { type: string; }; } -declare namespace Err$1 { +export namespace Err { export function warn(message: string): void; function _throw(message: string): never; export { _throw as throw }; @@ -577,11 +577,12 @@ declare namespace Err$1 { export function log(message: string): void; export function warnOnce(message: string): void; export function assert(test: boolean, errfunc: Function, message: string): boolean; + export function deprecate(message: string): void; } export class EvadeBehaviour extends Behaviour { - constructor(pursuer: Vec2); + constructor(pursuer: Vector2); radius: number; - pursuer: Vec2; + pursuer: Vector2; } export class EventDispatcher { private handlers; @@ -606,15 +607,15 @@ export class Flock extends Behaviour { neighbours: Agent[]; } export class Geometry { - constructor(vertices: Vec2[]); - vertices: Vec2[]; - normals: Vec2[]; - _dynNormals: Vec2[]; + constructor(vertices: Vector2[]); + vertices: Vector2[]; + normals: Vector2[]; + _dynNormals: Vector2[]; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; - getNormals(rad: number, target: Vec2[]): Vec2[]; + getNormals(rad: number, target: Vector2[]): Vector2[]; private calcFaceNormals; - transform(vertices: Vec2[], pos: Vec2, rad: any, n: number): void; + transform(vertices: Vector2[], pos: Vector2, rad: any, n: number): void; toJson(): { vertices: any[]; }; @@ -629,7 +630,7 @@ export class Group extends Sprite { remove(sprite: Sprite | Group, recursive?: boolean, index?: number): boolean; render(ctx: CanvasRenderingContext2D, dt: number): void; } -export class Input { +declare class Input$1 { constructor(eventHandler: DOMEventHandler); DOMEventHandler: DOMEventHandler; mouse: Mouse; @@ -656,7 +657,7 @@ export class Keyboard { private _onUp; } export class Line extends Shape { - constructor(length: number, offset: Vec2, offsetAngle: any); + constructor(length: number, offset: Vector2, offsetAngle: any); length: number; } export class Loader { @@ -680,7 +681,7 @@ export class Loader { _getType(url: any): "audio" | "image" | "json"; loadAll(files?: {}): void; } -export class Manager { +declare class Manager$1 { static DefaultSystem(name: string): System; constructor(options?: { autoPlay?: boolean; @@ -726,9 +727,9 @@ export class Manager { unregisterSystem(n: string): void; setComponentList(n: string, arr?: Component[]): void; getComponentList(n: string): Component[]; - getEntityByComponents(comps: Array): Entity; + getEntityByComponents(comps: Array, entities?: Entity[]): Entity; getEntitiesByComponents(comps: Array, entities?: Entity[], target?: Entity[]): Entity[]; - getEntityByTags(tags: Array): Entity; + getEntityByTags(tags: Array, entities?: Entity[]): Entity; getEntitiesByTags(tags: string[], entities?: Entity[], target?: Entity[]): Entity[]; private infertype; private clone; @@ -752,7 +753,7 @@ export class Matrix2 { rotate(radians: number): this; translate(x: number, y: number): this; scale(x: number, y: number): this; - transform(v: Vec2): Vec2; + transform(v: Vector2): Vector2; invert(): this; copy(m: Matrix2): this; clone(): Matrix2; @@ -781,16 +782,16 @@ export class Mouse { export class Movable extends Component implements Component { constructor(x: number, y: number, a: number); entity: any; - velocity: Vec2$1; + velocity: Vector2$1; rotation: Angle; - acceleration: Vec2$1; + acceleration: Vector2$1; toJson(): { - velocity: Vec2$1; + velocity: Vector2$1; rotation: { deg: number; type: string | number; }; - acceleration: Vec2$1; + acceleration: Vector2$1; }; fromJson(obj: any): void; } @@ -808,9 +809,9 @@ export namespace Overlaps { function AABBvsSphere(a: BoundingBox, b: BoundingCircle): boolean; } export class Particle { - constructor(pos: Vec2, radius: number, lifespan?: number); - readonly position: Vec2; - readonly velocity: Vec2; + constructor(pos: Vector2, radius: number, lifespan?: number); + readonly position: Vector2; + readonly velocity: Vector2; active: boolean; radius: number; color: { @@ -847,29 +848,36 @@ export class Path { private _finished; private _lerpedPoint; loop: boolean; - add(point: Vec2): this; + add(point: Vector2): this; clear(): this; advance(): boolean; - update(lerpdist?: number): Vec2$1; + update(lerpdist?: number): Vector2$1; current(): any[]; - point(): Vec2$1; + point(): Vector2$1; get path(): any[]; draw(ctx: CanvasRenderingContext2D): void; } export class PathFollowing extends Behaviour { constructor(path: Path); path: Path; - calc(target: Vec2, inv_dt: number): Vec2; + calc(target: Vector2, inv_dt: number): Vector2; clear(): void; - add(point: Vec2): void; + add(point: Vector2): void; set loop(arg: boolean); get loop(): boolean; setPath(path: Path): void; draw(ctx: any): void; } +export class Perf { + _start: number; + _time: number; + start(): void; + end(): number; + fps(): number; +} export class Pursuit extends Behaviour { init(): void; - calc(target: Vec2): void; + calc(target: Vector2): void; } declare class Tree extends Broadphase { constructor(bounds: Bounds, maxdepth?: number); @@ -885,7 +893,7 @@ declare class Tree extends Broadphase { } export class Rectangle extends Shape { static calcInertia(mass: number, width: number, height: number): number; - constructor(width: number, height: number, offset: Vec2, offsetAngle: number); + constructor(width: number, height: number, offset: Vector2, offsetAngle: number); height: number; width: number; } @@ -929,9 +937,9 @@ export class SATNarrowPhase extends NarrowPhase { getCollisionPairs(contactList: CollisionPair[], clmds?: Manifold[]): Manifold[]; } export class SeekBehaviour extends Behaviour { - constructor(target: Vec2); + constructor(target: Vector2); radius: number; - target: Vec2; + target: Vector2; } export namespace Session { function set(k: string, v: any): void; @@ -965,19 +973,19 @@ export class Shape { static calcInertia(): number; static CIRCLE: number; static POLYGON: number; - constructor(vertices: Vec2[], offset?: Vec2, offsetAngle?: number); + constructor(vertices: Vector2[], offset?: Vector2, offsetAngle?: number); readonly type: number; offAngle: number; - offPosition: Vec2; - vertices: Vec2[]; + offPosition: Vector2; + vertices: Vector2[]; geometry: Geometry; get CHOAS_CLASSNAME(): string; get CHAOS_OBJ_TYPE(): string; get area(): number; - getNormals(shape: Shape, target?: Vec2[]): Vec2[]; - update(position: Vec2, angle: number, scale: number): void; + getNormals(shape: Shape, target?: Vector2[]): Vector2[]; + update(position: Vector2, angle: number, scale: number): void; angle: number; - getVertices(axis: Vec2, target: Vec2[]): Vec2[]; + getVertices(axis: Vector2, target: Vector2[]): Vector2[]; toJson(): { type: string; geometry: { @@ -989,9 +997,19 @@ export class Shape { }; fromJson(obj: any): void; } +export class Signal { + constructor(value: any); + _listeners: any[]; + _value: any; + set value(arg: any); + get value(): any; + addListener(listener: any, callOnce?: boolean): void; + removeListener(listener: any): void; + _detach(bindingIndex: any): void; +} export class SpringConstraint extends Constraint { - localA: Vec2$1; - localB: Vec2$1; + localA: Vector2$1; + localB: Vector2$1; fixed: boolean; maxDistance: number; } @@ -1005,8 +1023,8 @@ export class Sprite implements Component { parent: Group | null; set angle(arg: number); get angle(): number; - set position(arg: Vec2); - get position(): Vec2; + set position(arg: Vector2); + get position(): Vector2; set orientation(arg: Angle); get orientation(): Angle; render(ctx: any, dt: any): void; @@ -1053,6 +1071,11 @@ export namespace Storage { function clear(): void; } export class System { + static implement(system: any): void; + init(): void; + update(): void; + add(component: any): void; + remove(component: any): void; } export class Touch { constructor(eh: DOMEventHandler); @@ -1068,11 +1091,11 @@ export class Touch { export class Transform implements Component { constructor(x: number, y: number, a: number); entity: any; - position: Vec2$1; + position: Vector2$1; orientation: Angle; init(): void; toJson(): { - position: Vec2$1; + position: Vector2$1; orientation: { deg: number; type: string | number; @@ -1082,7 +1105,7 @@ export class Transform implements Component { } export class Triangle extends Shape { static calcInertia(mass: any, base: any, height: any, angle: any): number; - constructor(base: number, height: number, angle: number, offset: Vec2, offsetAngle: number); + constructor(base: number, height: number, angle: number, offset: Vector2, offsetAngle: number); } export class Trigon extends Body { constructor(base: number, height: number, angle?: number); @@ -1097,20 +1120,25 @@ declare namespace Utils$1 { function removeElement(arr: T[], index: number): T; function generateID(): number; function inheritComponent(component: Function, overrideInit?: boolean, overrideUpdate?: boolean): void; - function inheritSystem(system: Function): void; -} -declare class Vec2$1 { - static getAbsDegBtwn(v1: Vec2, v2: Vec2): number; - static getAbsRadBtwn(v1: Vec2, v2: Vec2): number; - static getRadBtwn(v1: Vec2, v2: Vec2): number; - static getDegBtwn(v1: Vec2, v2: Vec2): number; - static fromRad(radian: number, target?: Vec2): Vec2; - static fromDeg(degree: number, target?: Vec2): Vec2; - static random(target?: Vec2): Vec2; - static lerp(v1: Vec2, v2: Vec2, t: number, target?: Vec2): Vec2; - static toDeg(v: Vec2): number; - static toRad(v: Vec2): number; - static readonly ZERO: Vec2; +} +export class Vec2 extends Vector2$1 { + constructor(x: any, y: any); +} +export class Vector extends Vector2$1 { + constructor(x: any, y: any); +} +declare class Vector2$1 { + static getAbsDegBtwn(v1: Vector2, v2: Vector2): number; + static getAbsRadBtwn(v1: Vector2, v2: Vector2): number; + static getRadBtwn(v1: Vector2, v2: Vector2): number; + static getDegBtwn(v1: Vector2, v2: Vector2): number; + static fromRad(radian: number, target?: Vector2): Vector2; + static fromDeg(degree: number, target?: Vector2): Vector2; + static random(target?: Vector2): Vector2; + static lerp(v1: Vector2, v2: Vector2, t: number, target?: Vector2): Vector2; + static toDeg(v: Vector2): number; + static toRad(v: Vector2): number; + static readonly ZERO: Vector2; constructor(x: number, y: number); x: number; y: number; @@ -1119,29 +1147,29 @@ declare class Vec2$1 { magnitude(): number; setMagnitude(length: number): void; magnitudeSquared(): number; - distanceTo(v: Vec2): number; - distanceToSquared(v: Vec2): number; - add(v: Vec2): this; + distanceTo(v: Vector2): number; + distanceToSquared(v: Vector2): number; + add(v: Vector2): this; addScalar(n: number): this; - sub(v: Vec2): this; + sub(v: Vector2): this; subScalar(n: number): this; - dot(v: Vec2): number; - cross(v: Vec2): number; + dot(v: Vector2): number; + cross(v: Vector2): number; multiply(n: number): this; divide(n: number): this; normalize(): this; - equals(v: Vec2): boolean; + equals(v: Vector2): boolean; equalsZero(): boolean; - normal(l?: number, target?: Vec2): Vec2; - normalFast(target?: Vec2): Vec2; + normal(l?: number, target?: Vector2): Vector2; + normalFast(target?: Vector2): Vector2; rotate(rad: number): this; toArray(target?: number[], offset?: number): number[]; - clone(): Vec2$1; - copy(v: Vec2): this; + clone(): Vector2$1; + copy(v: Vector2): this; set(x: number, y: number): this; draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; reverse(): this; - reflect(normal: number, target?: Vec2): Vec2; + reflect(normal: number, target?: Vector2): Vector2; clamp(min?: number, max?: number): this; toJson(): this; fromJson(obj: any): void; @@ -1168,7 +1196,7 @@ export class World { velocitySolverIterations: number; CLMDs: Manifold[]; contactList: CollisionPair[]; - gravitationalAcceleration: Vec2; + gravitationalAcceleration: Vector2; fixedFrameRate: number; perf: { lastTimestamp: number; @@ -1176,8 +1204,9 @@ export class World { }; broadphase: Broadphase; narrowphase: NarrowPhase; - set gravity(arg: Vec2); - get gravity(): Vec2; + intergrator: Intergrator; + set gravity(arg: Vector2); + get gravity(): Vector2; private narrowPhase; broadPhase(): void; private collisionDetection; @@ -1201,6 +1230,14 @@ export class World { export function arc(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, start: number, end: number): void; export function circle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void; export function clamp(value: number, min: number, max: number): number; +export function createEntity(x: number, y: number, a: number): Entity; +export function createManager(options?: { + autoPlay?: boolean; + files?: any; + physics?: boolean; + renderer?: boolean; + input?: boolean; +}): any; export function defaultCollisionHandler(clmds: CollisionPair[]): void; export function defaultPrecollisionHandler(clmds: Manifold[]): void; export function degToRad(deg: number): number; @@ -1211,6 +1248,7 @@ export function fillText(ctx: CanvasRenderingContext2D, text: string, x: number, export function lerp(a: number, b: number, t: number): number; export function line(ctx: CanvasRenderingContext2D, x1: number, y1: number, x2: number, y2: number): void; export function map(v: number, x1: number, y1: number, x2: number, y2: number): number; +export function mixin(from: any, to: any, props?: any[]): void; export function naturalizePair(a: number, b: number): number; export function radToDeg(rad: number): number; export function rand(min?: number, max?: number): number; @@ -1219,7 +1257,7 @@ export function round(number: number, precision?: number): number; export function sq(x: number): number; export function sqrt(x: number): number; export function stroke(ctx: CanvasRenderingContext2D, color?: string, width?: number): void; -export function vertices(ctx: CanvasRenderingContext2D, vertices: Vec2[], close?: boolean): void; +export function vertices(ctx: CanvasRenderingContext2D, vertices: Vector2[], close?: boolean): void; export function wrapAngle(x: any): any; declare class Node { constructor(bounds: { @@ -1265,5 +1303,5 @@ declare class Broadphase { getCollisionPairs(target: CollisionPair[]): CollisionPair[]; query(bounds: Bounds, target: Body[]): Body[]; } -declare let r: Vec2$1; -export { Err$1 as Err, Matrix2 as Matrix, Tree as QuadTreeBroadphase, Utils$1 as Utils, Vec2$1 as Vec2 }; +declare let r: Vector2$1; +export { Input$1 as Input, Manager$1 as Manager, Matrix2 as Matrix, Tree as QuadTreeBroadphase, Utils$1 as Utils, Vector2$1 as Vector2 }; diff --git a/dist/chaos.module.js b/dist/chaos.module.js index 1b428d30..060650e1 100644 --- a/dist/chaos.module.js +++ b/dist/chaos.module.js @@ -1,10 +1,10 @@ -/* - * @author Wayne Mwashuma - * {@link https://github.com/waynemwashuma/chaos-engine.git} - * @copyright 2023-2023 Wayne Mwashuma - * @license MIT - * - * +/* + * @author Wayne Mwashuma + * {@link https://github.com/waynemwashuma/chaos-engine.git} + * @copyright 2023-2023 Wayne Mwashuma + * @license MIT + * + * * MIT License Copyright (c) 2023 Wayne Mwashuma @@ -26,8 +26,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - */ + + */ /** * This module is used to check if bounds of a body overlap */ @@ -70,17 +70,17 @@ const Overlaps = { (x - b.pos.x) * (x - b.pos.x) + (y - b.pos.y) * (y - b.pos.y); - return distance < b.r; + return distance < b.r * b.r; } -}; - +}; + let marker = `🚀Chaos Engine Says::::\n`; let mess = []; /** * A set of functions to streamline logging of items to the console */ -const Err$1 = {}; +const Err = {}; /** * Logs out a warning to the console. @@ -88,7 +88,7 @@ const Err$1 = {}; * @memberof Err * @param {string} message */ -Err$1.warn = function(message) { +Err.warn = function(message) { console.warn(marker + message); }; @@ -98,7 +98,7 @@ Err$1.warn = function(message) { * @memberof Err * @param {string} message */ -Err$1.throw = function(message) { +Err.throw = function(message) { throw new Error(marker + message) }; @@ -108,7 +108,7 @@ Err$1.throw = function(message) { * @memberof Err * @param {string} message */ -Err$1.error = function(message) { +Err.error = function(message) { console.error(marker + message); }; @@ -118,7 +118,7 @@ Err$1.error = function(message) { * @memberof Err * @param {string} message */ -Err$1.log = function(message) { +Err.log = function(message) { console.log(marker + message); }; /** @@ -127,10 +127,10 @@ Err$1.log = function(message) { * @memberof Err * @param {string} message */ -Err$1.warnOnce = function(message) { +Err.warnOnce = function warnOnce(message) { if (mess.includes(message)) return mess.push(message); - Err$1.warn(message); + Err.warn(message); }; /** * Logs out a message,warning or error to the console according to the supplied log function. @@ -140,11 +140,21 @@ Err$1.warnOnce = function(message) { * @param {string} message * @param {Function} errfunc */ -Err$1.assert = function(test, errfunc, message) { +Err.assert = function(test, errfunc, message) { if (!test) errfunc(message); return test }; +/** + * Logs out a warning to the console. + * + * @memberof Err + * @param {string} message + */ +Err.deprecate = function deprecate(message) { + Err.warnOnce(message); +}; + /** * Contains a subset of useful functionality. * @@ -253,7 +263,7 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda } if (!proto.update && overrideUpdate) { proto.update = function() { - Err$1.warnOnce("Please override the update function in the component " + proto.constructor.name); + Err.warnOnce("Please override the update function in the component " + proto.constructor.name); }; } @@ -263,7 +273,7 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda proto.requires = function(...names) { for (var i = 0; i < names.length; i++) if (!this.entity.has(names[i])) - Err$1.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); + Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); }; proto.query = function(bound, target = []) { @@ -291,39 +301,27 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda }); }; /** - * Mixes the functions required by a system into a class. + * Mixes the functions required by an object into another object. * * @memberof Utils - * @param {Function} system the class constructor function to add methods to. + * @param {Object} from the object constructor function to add methods from. + * @param {Object} to the object constructor function to add methods to. */ -Utils$1.inheritSystem = function(system) { - if (system == void 0 || typeof system !== "function") return - let proto = system.prototype; - if (!proto.init) { - proto.init = function() { - Err$1.warnOnce("Please override the init method in the system " + proto.constructor.name); - }; - } - if (!proto.update) { - proto.update = function() { - Err$1.warnOnce("Please override the update method in the system " + proto.constructor.name); - - }; - } - if (!proto.add) { - proto.add = function(component) { - this.objects.push(component); - }; - } - - if (!proto.remove) { - proto.remove = function(component) { - let index = this.objects.indexOf(component); - Utils$1.removeElement(this.objects, index); - }; +function mixin(from, to,props = []) { + let proto = from.prototype; + let proto2 = to.prototype; + console.log(proto2); + Object.assign(proto,from); + for (let name of props) { + props[name]; + //if(!(methodName in proto))continue + //if (methodName in proto2) continue + + proto2[name] = proto[name]; } -}; - + //console.log(new to()); +} + /** * Handles time management for the game. */ @@ -359,27 +357,36 @@ class Clock { return this.dt/1000 } -} - +} + +class Perf{ + _start = 0 + _time = 0 + start(){ + this._start = Performance.now(); + } + end(){ + this._time = Performance.now() - this._start; + return this._time + } + fps(){ + return 1000/this._time + } +} + /** * A helper class. * Since there are no interfaces in JavaScript, * you might have to extend this to create a component, but there is another solution. - * Use instead Utils.inheritComponent() if you have your own hierarchy of classes. + * Use instead `Component.implement()` if you have your own hierarchy of classes. * In typescript,this would be an interface. * * @interface * */ class Component { - /** - * @type Entity | null - */ - entity = null - destroy() { - this.entity = null; - } + destroy() {} /** * @type string */ @@ -393,25 +400,20 @@ class Component { return "component" } /** - * @param {Entity} entity - */ - init(entity) { - this.entity = entity; - } + init(entity) {} /** * @param {number} dt */ update(dt) { Err.warnOnce("Please override the update function in the component " + proto.constructor.name); - } /** * @param {string} n */ - get(n) { - return this.entity.getComponent(n); + get(entity,n) { + return entity.getComponent(n); } /** * @param {...string} names @@ -425,8 +427,8 @@ class Component { * @param {CircleBounding | BoxBounding} bound * @param {Entity} [target=[]] */ - query(bound, target = []) { - return this.entity.query(bound, target) + query(entity,bound, target = []) { + return entity.query(bound, target) } static fromJson() { throw "Implement static method fromJson() in your component " + this.CHOAS_CLASSNAME @@ -434,37 +436,11 @@ class Component { static toJson() { throw "Implement static method toJson() in your component " + this.CHOAS_CLASSNAME } -} -Utils$1.inheritComponent(Component); -/** - * Destroys the component. - * - * @function - * @name Component#destroy - */ -/** - * Initializes a component. - * - * @function - * @name Component#init - * @param {Entity} entity - */ -/** - * Updates a component.Called by the system which manages its type. - * - * @function - * @name Component#update - * @param {number} dt - */ -/** - * Gets a component in the entity containing this entity. - * - * @function - * @name Component#requires - * @param {string} ...names - * @throws Qhen a named component isnt in the parent entity - */ - + static implement(component) { + Utils$1.inheritComponent(component); + } +} + /** * A rectangular bound that is used to contain a body so that broadphase can be used for quick collision detection. */ @@ -570,7 +546,7 @@ class BoundingBox extends Component { /** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x; @@ -639,8 +615,8 @@ class BoundingBox extends Component { target.min.y = bound1.min.y < bound2.min.y ? bound1.min.y : bound2.min.y; return target } -} - +} + /** * A circular bound that is used to contain a body so that broadphase can be used for quick collision detection. */ @@ -727,8 +703,8 @@ class BoundingCircle { this.pos.y = obj.posY; this.r = obj.r; } -} - +} + const RHI = Math.PI / 180, RHI_INV = 1 / RHI; @@ -854,8 +830,8 @@ function degToRad(deg) { */ function radToDeg(rad) { return rad * RHI_INV -} - +} + let obj$1 = { x: 0, y: 0 @@ -867,7 +843,7 @@ let TWO_PI = Math.PI * 2; * @author Wayne Mwashuma * @license MIT */ -class Vec2$1 { +class Vector2$1 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -913,28 +889,28 @@ class Vec2$1 { } /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Math.sqrt( Vec2$1.prototype.magnitudeSquared.call(obj$1)) + return Math.sqrt( Vector2$1.prototype.magnitudeSquared.call(obj$1)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Vec2$1.prototype.magnitudeSquared.call(obj$1) + return Vector2$1.prototype.magnitudeSquared.call(obj$1) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -957,7 +933,7 @@ class Vec2$1 { /** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -979,7 +955,7 @@ class Vec2$1 { /** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -988,7 +964,7 @@ class Vec2$1 { /** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -1032,7 +1008,7 @@ class Vec2$1 { * Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -1050,21 +1026,21 @@ class Vec2$1 { * Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2$1(); + target = target || new Vector2$1(); target.copy(this).normalize(); return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2$1()) { + normalFast(target = new Vector2$1()) { return target.set(-this.y, this.x) } /** @@ -1101,16 +1077,16 @@ class Vec2$1 { * Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2$1(this.x, this.y) + return new Vector2$1(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -1166,10 +1142,10 @@ class Vec2$1 { * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2$1()) { + reflect(normal, target = new Vector2$1()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1207,33 +1183,33 @@ class Vec2$1 { * Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -1243,22 +1219,22 @@ class Vec2$1 { * Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2$1.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2$1.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2$1()) { + static fromRad(radian, target = new Vector2$1()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -1266,32 +1242,32 @@ class Vec2$1 { * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2$1.fromRad(degree * Math.PI / 180, target) + return Vector2$1.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2$1.fromRad(Math.random() * TWO_PI, target) + return Vector2$1.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2$1()) { - target = target || new Vec2$1(); + static lerp(v1, v2, t, target = new Vector2$1()) { + target = target || new Vector2$1(); return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -1301,17 +1277,17 @@ class Vec2$1 { /** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2$1.toRad(v) / Math.PI * 180 + return Vector2$1.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -1324,12 +1300,24 @@ class Vec2$1 { * * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2$1()) + static ZERO = Object.freeze(new Vector2$1()) } - +class Vector extends Vector2$1{ + constructor(x,y){ + super(x,y); + console.error("The class `Vector` is depreciated since v0.4.13.Use Vector2 instead."); + } +} +class Vec2 extends Vector2$1{ + constructor(x,y){ + super(x,y); + console.error("The class `Vec2` is depreciated since v0.4.13.Use Vector2 instead."); + } +} + /** * Wrapper class since JavaScript doesn't support references to numbers explicitly. * Keeps record of the orientation of an entity. @@ -1413,8 +1401,8 @@ class Angle { type: this.CHAOS_OBJ_TYPE } } -} - +} + /** * A class that is used to transform positions through rotation, scaling and translation. */ @@ -1558,7 +1546,7 @@ class Matrix2 { /** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x; @@ -1628,8 +1616,8 @@ class Matrix2 { yield this.e; yield this.f; } -} - +} + function wrapAngle(x) { let a = x; while (a > Math.PI * 2) { @@ -1639,8 +1627,8 @@ function wrapAngle(x) { a = a + Math.PI * 2; } return a -} - +} + const Easing = { Linear: { In: function(x) { @@ -1886,23 +1874,23 @@ const Interpolation = { return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1 }, -}; - +}; + class Geometry { /** - * @type Vec2[] + * @type Vector2[] */ vertices = null /** - * @type Vec2[] + * @type Vector2[] */ normals = null /** - * @type Vec2[] + * @type Vector2[] */ _dynNormals = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices; @@ -1923,7 +1911,7 @@ class Geometry { } /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || []; @@ -1934,7 +1922,7 @@ class Geometry { } /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -1956,8 +1944,8 @@ class Geometry { } /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -1976,12 +1964,12 @@ class Geometry { return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)); + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)); this.normals = this.calcFaceNormals(); this._dynNormals = this.normals.map(e => e.clone()); } -} - +} + /**@enum {number}*/ const ShapeType = Object.freeze({ CIRCLE: 0, @@ -2020,9 +2008,9 @@ const Settings = { collisionResponse: true, autoUpdateBound: true, type:BodyType.DYNAMIC -}; - -let tmp1$c = new Vec2$1(); +}; + +let tmp1$c = new Vector2$1(); /** * This class makes a body tangible @@ -2045,13 +2033,13 @@ class Shape { /** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -2062,11 +2050,11 @@ class Shape { geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2$1(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); @@ -2095,8 +2083,8 @@ class Shape { * Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -2104,7 +2092,7 @@ class Shape { /** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -2116,9 +2104,9 @@ class Shape { /** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices @@ -2151,8 +2139,8 @@ class Shape { } static CIRCLE = 0 static POLYGON = 1 -} - +} + class Line extends Shape { /** * @type number @@ -2160,19 +2148,19 @@ class Line extends Shape { length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2$1(1).multiply(length / 2), - end = new Vec2$1(1).multiply(-length / 2); + let start = new Vector2$1(1).multiply(length / 2), + end = new Vector2$1(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } -} - -let _vec1 = new Vec2$1(); -let _vec2 = new Vec2$1(); +} + +let _vec1 = new Vector2$1(); +let _vec2 = new Vector2$1(); /** * A circular shape. @@ -2185,14 +2173,14 @@ class Circle extends Shape { radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vec2$1(), new Vec2$1(), new Vec2$1()]; + this.vertices = [new Vector2$1(), new Vector2$1(), new Vector2$1()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2210,9 +2198,9 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || []; @@ -2225,8 +2213,8 @@ class Circle extends Shape { /** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -2245,7 +2233,7 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -2269,12 +2257,12 @@ class Circle extends Shape { fromJson(obj) { return new Circle( obj.radius, - new Vec2$1().fromJson(obj.offset), + new Vector2$1().fromJson(obj.offset), obj.offAngle ) } -} - +} + class Rectangle extends Shape { /** * @type number @@ -2287,14 +2275,14 @@ class Rectangle extends Shape { /** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2$1(-width / 2, -height / 2); - let v2 = new Vec2$1(-width / 2, height / 2); - let v3 = new Vec2$1(width / 2, height / 2); - let v4 = new Vec2$1(width / 2, -height / 2); + let v1 = new Vector2$1(-width / 2, -height / 2); + let v2 = new Vector2$1(-width / 2, height / 2); + let v3 = new Vector2$1(width / 2, height / 2); + let v4 = new Vector2$1(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2313,9 +2301,9 @@ class Rectangle extends Shape { return this.width * this.height } -} - -let tmp1$b = new Vec2$1(); +} + +let tmp1$b = new Vector2$1(); /** * A triangular shape. @@ -2327,16 +2315,16 @@ class Triangle extends Shape { * @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2$1().set(1, 0).multiply(base); - let l2 = Vec2$1.fromRad(angle).multiply(height/Math.sin(angle)); + let l1 = new Vector2$1().set(1, 0).multiply(base); + let l2 = Vector2$1.fromRad(angle).multiply(height/Math.sin(angle)); let center = tmp1$b.set((l1.x + l2.x) / 3, l2.y / 3); super([ - new Vec2$1().sub(center), + new Vector2$1().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle); @@ -2344,8 +2332,8 @@ class Triangle extends Shape { static calcInertia(mass,base,height,angle){ return 0.5 * mass * base * height * (1 - 2/3 * (1 - (Math.cos(2 * angle * 180/Math.PI))/2)) } -} - +} + /** * Holds information needed for collision detection and response. * @@ -2362,23 +2350,23 @@ class Body { * World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2$1() + _position = new Vector2$1() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2$1() + _velocity = new Vector2$1() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2$1() + _acceleration = new Vector2$1() /** * World space orientation of a body * @@ -2426,22 +2414,22 @@ class Body { * Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2$1() + lastPosition = new Vector2$1() /** * Inverse mass of the body. * @@ -2612,7 +2600,7 @@ class Body { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -2623,7 +2611,7 @@ class Body { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -2700,7 +2688,7 @@ class Body { /** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -2755,11 +2743,11 @@ class Body { /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2767,7 +2755,7 @@ class Body { * Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -2776,20 +2764,20 @@ class Body { * Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2$1()) { + getLocalAnchor(index, target = new Vector2$1()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2$1.ZERO) { + applyForce(force, arm = Vector2$1.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2889,7 +2877,7 @@ class Body { body.id = obj.id; body.mask = obj.mask; obj.anchors.forEach((v) => { - body.setAnchor(new Vec2$1().fromJson(v)); + body.setAnchor(new Vector2$1().fromJson(v)); }); } /** @@ -2913,8 +2901,8 @@ class Body { */ static DYNAMIC = ObjType.DYNAMIC } -Utils$1.inheritComponent(Body, false, false); - +Component.implement(Body); + /** * A body with a circle shape on it. * @@ -2940,8 +2928,8 @@ class Ball extends Body { this.inv_mass = x === 0 ? 0 : 1 / x; this.inertia = Circle.calcInertia(this.mass, this.shapes[0].radius); } -} - +} + /** * A body with a rectangle shape on it. * @@ -2969,8 +2957,8 @@ class Box extends Body { get mass(){ return this._mass } -} - +} + /** * Holds a group of related bodies and constraints. */ @@ -3033,10 +3021,10 @@ class Composite { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2$1(); + let acceleration = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3050,10 +3038,10 @@ class Composite { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2$1(); + let velocity = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3127,11 +3115,11 @@ class Composite { /** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2$1(); - for (var i = 0; i < this.shapes.length; i++) { + let position = new Vector2$1(); + for (var i = 0; i < this.bodies.length; i++) { position.add(this.bodies[i].position); } return position @@ -3177,8 +3165,8 @@ class Composite { } } } -Utils$1.inheritComponent(Composite); - +Component.implement(Composite); + class Trigon extends Body { /** * @param {number} base @@ -3205,8 +3193,8 @@ class Trigon extends Body { this.inv_mass = x === 0 ? 0 : 1 / x; this.inertia = Triangle.calcInertia(this.mass, this.base, this.height,this.bangle); } -} - +} + /** * Base class for constructing different types of constraints. * @@ -3218,14 +3206,14 @@ class Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vec2$1(); - this.localB = localB || new Vec2$1(); + this.localA = localA || new Vector2$1(); + this.localB = localB || new Vector2$1(); this.stiffness = 50; this.dampening = 0.03; } @@ -3287,20 +3275,20 @@ class Constraint { let constraint = new Constraint( bod1, bod2, - new Vec2$1().fromJson(obj.localA), - new Vec2$1().fromJson(obj.localB) + new Vector2$1().fromJson(obj.localA), + new Vector2$1().fromJson(obj.localB) ); constraint.stiffness = obj.stiffness; constraint.dampening = obj.dampening; return constraint } -} - -let tmp1$a = new Vec2$1(), - tmp2$8 = new Vec2$1(), - tmp3$4 = new Vec2$1(), - tmp4$4 = new Vec2$1(), - tmp5$3 = new Vec2$1(); +} + +let tmp1$a = new Vector2$1(), + tmp2$8 = new Vector2$1(), + tmp3$4 = new Vector2$1(), + tmp4$4 = new Vector2$1(), + tmp5$3 = new Vector2$1(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3309,8 +3297,8 @@ class DistanceConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); @@ -3353,14 +3341,14 @@ class DistanceConstraint extends Constraint { body1.rotation.radian += tmp4$4.cross(arm1) * body1.inv_inertia; body2.rotation.radian += tmp4$4.cross(arm2) * -body2.inv_inertia; } -} - -let tmp1$9 = new Vec2$1(), - tmp2$7 = new Vec2$1(), - tmp3$3 = new Vec2$1(), - tmp4$3 = new Vec2$1(), - tmp5$2 = new Vec2$1(), - zero = new Vec2$1(); +} + +let tmp1$9 = new Vector2$1(), + tmp2$7 = new Vector2$1(), + tmp3$3 = new Vector2$1(), + tmp4$3 = new Vector2$1(), + tmp5$2 = new Vector2$1(), + zero = new Vector2$1(); /** * A constraint that acts like a spring between two bodies */ @@ -3368,13 +3356,13 @@ class SpringConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vec2$1().copy(localA || zero); - this.localB = new Vec2$1().copy(localB || zero); + this.localA = new Vector2$1().copy(localA || zero); + this.localB = new Vector2$1().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; this.dampening = 1; this.maxDistance = 100; @@ -3409,13 +3397,13 @@ class SpringConstraint extends Constraint { body1.rotation.radian += force.cross(arm1) * body1.inv_inertia; body2.rotation.radian += force.cross(arm2) * -body2.inv_inertia; } -} - -new Vec2$1(); - -let position = new Vec2$1(); -let acceleration = new Vec2$1(); -let velocity = new Vec2$1(); +} + +new Vector2$1(); + +let position = new Vector2$1(); +let acceleration = new Vector2$1(); +let velocity = new Vector2$1(); /** * Verlet intergration. @@ -3439,13 +3427,13 @@ class VerletSolver { body.angle += body.angularVelocity * dt; body.angularVelocity += body.angularAcceleration * dt * 0.5; } -} - -let tmp1$8 = new Vec2$1(), - tmp2$6 = new Vec2$1(), - tmp3$2 = new Vec2$1(), - tmp4$2 = new Vec2$1(), - tmp5$1 = new Vec2$1(); +} + +let tmp1$8 = new Vector2$1(), + tmp2$6 = new Vector2$1(), + tmp3$2 = new Vector2$1(), + tmp4$2 = new Vector2$1(), + tmp5$1 = new Vector2$1(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3490,8 +3478,8 @@ const FrictionSolver = { manifold.rotA += ca1.cross(jt) * a.inv_inertia; manifold.rotB += ca2.cross(jt) * -b.inv_inertia; } -}; - +}; + let v = { x: 0, y: 0 }; let velocityLimit = 1; @@ -3519,10 +3507,10 @@ const ContactSolver = { b.velocity = v; b.acceleration = v; } -}; - -const tmp1$7 = new Vec2$1(), - tmp2$5 = new Vec2$1(); +}; + +const tmp1$7 = new Vector2$1(), + tmp2$5 = new Vector2$1(); let dampen = Settings.posDampen; /** @@ -3542,12 +3530,12 @@ const PenetrationSolver = { bodyB.rotation.radian += ca2.cross(jp) * -bodyB.inv_inertia * inv_dt; manifold.contactData.lastOverlap = overlap; } -}; - -let tmp1$6 = new Vec2$1(), - tmp2$4 = new Vec2$1(), - tmp3$1 = new Vec2$1(), - tmp4$1 = new Vec2$1(); +}; + +let tmp1$6 = new Vector2$1(), + tmp2$4 = new Vector2$1(), + tmp3$1 = new Vector2$1(), + tmp4$1 = new Vector2$1(); /** * Solves for the collision normal impulse of a given body pair. @@ -3586,8 +3574,8 @@ const ImpulseSolver = { manifold.rotB = ang2; manifold.impulse = j; } -}; - +}; + /** * This is an abstract class that extended to classes that are used to filter out unnecessary collision checks to boost performance. * @@ -3655,8 +3643,8 @@ class Broadphase { * @returns {Body[]} */ query(bounds, target) {} -} - +} + /** * Most basic broadphase.Should be used when number of bodies are few(i.e less than 100) */ @@ -3716,8 +3704,8 @@ class NaiveBroadphase extends Broadphase { return target } -} - +} + class Client { constructor(body) { this.body = body; @@ -4189,14 +4177,14 @@ class Tree extends Broadphase { * @callback Traverser * @param {Node} node * @returns {boolean} -*/ - +*/ + const _arr = [], tmp1$5 = { overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2$1(), + axis: new Vector2$1(), vertex: null, shape: null }, @@ -4210,9 +4198,9 @@ const _arr = [], max: 0, indexN: 0 }, - tmp4 = new Vec2$1(), - tmp5 = new Vec2$1(), - tmp6 = new Vec2$1(); + tmp4 = new Vector2$1(), + tmp5 = new Vector2$1(), + tmp6 = new Vector2$1(); /** * Used for narrowphase collision detection and contact info generation. @@ -4299,7 +4287,7 @@ const SAT = { /** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -4359,8 +4347,8 @@ const SAT = { return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -4385,9 +4373,9 @@ const SAT = { return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -4415,7 +4403,7 @@ const SAT = { }, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -4423,9 +4411,9 @@ const SAT = { return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -4435,7 +4423,7 @@ const SAT = { return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { @@ -4456,14 +4444,14 @@ const SAT = { return true; } -}; - +}; + class NarrowPhase{ records = new Map() getCollisionPairs(contactList,clmds){ } -} - +} + /** * Uses the Separation Axis Theorem. * Best when your body shapes have few vertices. @@ -4487,7 +4475,7 @@ class SATNarrowPhase extends NarrowPhase { lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2$1(), + axis: new Vector2$1(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4500,13 +4488,13 @@ class SATNarrowPhase extends NarrowPhase { stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2$1(), - ca2: new Vec2$1(), + ca1: new Vector2$1(), + ca2: new Vector2$1(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2$1(), - velB: new Vec2$1(), + velA: new Vector2$1(), + velB: new Vector2$1(), rotA: 0, rotB: 0 }); @@ -4517,13 +4505,13 @@ class SATNarrowPhase extends NarrowPhase { SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4541,8 +4529,8 @@ class SATNarrowPhase extends NarrowPhase { } return clmds } -} - +} + /** * Class responsible for updating bodies,constraints and composites. */ @@ -4617,9 +4605,9 @@ class World { /** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2$1(0, 0) + gravitationalAcceleration = new Vector2$1(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4648,6 +4636,12 @@ class World { * @type NarrowPhase */ narrowphase = null + /** + * Moves the bodies forward in time. + * + * @type {Intergrator} + */ + intergrator = VerletSolver /** * @constructor World * @@ -4666,7 +4660,7 @@ class World { /** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration @@ -4744,7 +4738,8 @@ class World { for (var i = 0; i < length; i++) { let a = this.objects[i]; if (!a.sleeping) - VerletSolver.solve(a, dt); + this.intergrator.solve(a, dt); + //VerletSolver.solve(a, dt) } } /** @@ -4937,8 +4932,8 @@ class World { this.broadphase.query(bound, target); return target } -} - +} + //import { Component } from "./component.js" /** @@ -4955,7 +4950,7 @@ class Transform { * @returns */ constructor(x,y,a){ - this.position = new Vec2$1(x,y); + this.position = new Vector2$1(x,y); this.orientation = new Angle(a); } init(){} @@ -4969,8 +4964,8 @@ class Transform { this.position.fromJson(obj.position); this.orientation.fromJson(obj.orientation); } -} - +} + class Camera { /** * @readonly @@ -4980,7 +4975,7 @@ class Camera { constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position @@ -4989,8 +4984,8 @@ class Camera { this.transform.position.copy(x); } update() {} -} - +} + /** * This is an abstract class from which different types of renderers are implemented. * @@ -5134,8 +5129,8 @@ class Renderer { let canvas = this.domElement; canvas.style.width = w + "px"; canvas.style.height = h + "px"; - canvas.width = w; - canvas.height = h; + canvas.width = w * devicePixelRatio; + canvas.height = h * devicePixelRatio; } /** * Width of the renderer @@ -5159,8 +5154,8 @@ class Renderer { set height(x) { this.domElement.height = x; } -} - +} + /** * Renders images and paths to the 2D context of a canvas. * @@ -5236,8 +5231,8 @@ class Renderer2D extends Renderer { requestFullScreen() { this.domElement.parentElement.requestFullscreen(); } -} - +} + //Dont get too excited yet :) /** @@ -5249,8 +5244,8 @@ class WebGPURenderer extends Renderer{ constructor(){ throw new Error("Dont get too excited yet :)") } -} - +} + /** * Renders images and paths to the webgl context of a canvas. * @@ -5260,8 +5255,8 @@ class WebGLRenderer extends Renderer{ constructor(){ throw new Error("Hold your horses there!I haven't implemented this yet!") } -} - +} + /** * This is the base class used to render images and paths onto the renderer. * Extend it to create your custom behaviour. @@ -5316,7 +5311,7 @@ class Sprite { /** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -5350,9 +5345,9 @@ class Sprite { */ init(entity) { if(!entity){ - this._position = new Vec2$1(); + this._position = new Vector2$1(); this._orientation = new Angle(); - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return } this.entity = entity; @@ -5361,7 +5356,7 @@ class Sprite { this._position = transform.position; this._orientation = transform.orientation; //TODO - Correct this later - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return this } toJson(){ @@ -5382,8 +5377,8 @@ class Sprite { this.parent = renderer.getById(obj.parent); } } -Utils$1.inheritComponent(Sprite); - +Component.implement(Sprite); + /** * @interface */ @@ -5396,8 +5391,8 @@ class Material{ render(ctx,dt,path){ throw "Override this method in derived class" } -} - +} + /** * * @implements Material @@ -5434,8 +5429,8 @@ class BasicMaterial { ctx.strokeStyle = this.stroke; ctx.stroke(path); } -} - +} + /** * * @implements Material @@ -5477,8 +5472,8 @@ class StaticImageMaterial { render(ctx) { ctx.drawImage(this.image, this.offset.x, this.offset.y, this.width, this.height); } -} - +} + /** * @param {CanvasRenderingContext2D} ctx * @param {number} x1 @@ -5511,7 +5506,7 @@ function circle(ctx, x, y, r) { } /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ function vertices(ctx, vertices, close = true) { @@ -5586,8 +5581,8 @@ function drawImage( x, y, w, h); -} - +} + /** * * @implements Material @@ -5726,9 +5721,9 @@ class SpriteMaterial { if (this._frame >= this._maxFrame) this._frame = 0; } -} - -let r = new Vec2$1(); +} + +let r = new Vector2$1(); let material$1 = new BasicMaterial(); material$1.wireframe = true; /** @@ -5856,7 +5851,7 @@ class BodySprite extends Sprite { shape.position.x, shape.position.y, shape.radius); - Vec2$1.fromRad(shape.angle, r).multiply(shape.radius); + Vector2$1.fromRad(shape.angle, r).multiply(shape.radius); line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y); @@ -5875,12 +5870,12 @@ class BodySprite extends Sprite { this.body = parent.get("body"); super.init(parent); } -} - +} + class BufferGeometry { /** * @readonly - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -5889,7 +5884,7 @@ class BufferGeometry { */ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || []; @@ -5902,8 +5897,8 @@ class BufferGeometry { let path = this.drawable = new Path2D(); vertices(path, this.vertices, true); } -} - +} + class CircleGeometry { /** * @param {number} radius @@ -5924,12 +5919,12 @@ class CircleGeometry { render(ctx) { circle(ctx, 0, 0, this.radius); } -} - +} + let geometry = new BufferGeometry([ - new Vec2$1(-10, -10), - new Vec2$1(-10, 10), - new Vec2$1(20, 0) + new Vector2$1(-10, -10), + new Vector2$1(-10, 10), + new Vector2$1(20, 0) ]); let material = new BasicMaterial(); material.fill = "purple"; @@ -5964,20 +5959,20 @@ class AgentSprite extends Sprite { this.agent.draw(ctx); super.render(ctx); } -} - +} + /** * Its a fricking particle! */ class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -6003,13 +5998,13 @@ class Particle { */ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vec2$1(); + this.velocity = new Vector2$1(); this.radius = radius; this.color = { r: 100, @@ -6097,7 +6092,7 @@ class ParticleSystemSprite extends Sprite { */ create() { return new Particle( - new Vec2$1(...this.position), + new Vector2$1(...this.position), rand(1, 10), rand(1, 6) ) @@ -6140,8 +6135,8 @@ class ParticleSystemSprite extends Sprite { this.initParticles(this.frameIncrease); } } -} - +} + /** * Used for grouping similar. * @@ -6220,25 +6215,25 @@ class Group extends Sprite { this._children[i].render(ctx, dt); } } -} - +} + class CamController { /** * @readonly - * @type Vec2 + * @type Vector2 */ - offset = new Vec2$1() + offset = new Vector2$1() /** * @param {Camera} camera */ constructor(camera) { this.transform = camera.transform; - this.offset = new Vec2$1(); + this.offset = new Vector2$1(); this.targetPosition = null; this.targetOrientation = null; } /** - * @param { Vec2} position + * @param { Vector2} position * @param {Angle} orientation */ follow(position, orientation = null) { @@ -6267,8 +6262,8 @@ class CamController { if (this.targetOrientation) this.transform.orientation.copy(this.targetOrientation); } -} - +} + //import { DEVICE } from "../device/index.js" class Loader { constructor(manager) { @@ -6301,7 +6296,7 @@ class Loader { } else if (type === "json") { that.json[name] = JSON.parse(xhr.response); } else { - return Err$1.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) + return Err.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) } that._filesLoaded += 1; @@ -6322,7 +6317,7 @@ class Loader { }, onerror: function(e) { that._filesErr += 1; - Err$1.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); + Err.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); if (that._filesLoaded + that._filesErr === that._totalFileNo && that.onfinish) that.onfinish(); } }; @@ -6392,8 +6387,8 @@ class Loader { } } -} - +} + /** * This class manages all events by a game manager. * When adding a handler to an event with another handler,the latter will not be overriden,rather,the former will be added to complement the latter. @@ -6433,8 +6428,8 @@ class EventDispatcher { } this.handlers[name] = [handler]; } -} - +} + /** * This handles events created by the DOM. */ @@ -6507,8 +6502,8 @@ class DOMEventHandler { Ill leave it for now. */ init() {} -} - +} + /** * This provides a way to fire off an entity's collision event handler registered to it. * @@ -6555,8 +6550,8 @@ function defaultPrecollisionHandler(clmds) { clmds[i] ); } -} - +} + /**@enum {string}*/ const Events = { COLLISION : "collision", @@ -6569,8 +6564,43 @@ const Events = { REMOVE : "remove", PAUSE : "pause", PLAY : "play" -}; - +}; + +class Signal { + _listeners = [] + _value = null + constructor(value){ + this._value = value; + } + set value(x) { + this._value == x; + for (var i = 0; i < this._listeners.length; i++) { + let func = this._listeners[i]; + func.listener(this); + if(func.callOnce) + this.removeListener(func.listener); + } + } + get value() { + return this._value + } + addListener(listener,callOnce=false) { + this._listeners.push({ + listener, + callOnce + }); + } + removeListener(listener) { + for (var i = 0; i < this._listeners.length; i++) { + if (this._listeners[i].listener == listener) + return this._detach(i) + } + } + _detach(bindingIndex){ + this._listeners.splice(i, 1); + } +} + /** * Handled the keyboard input of an application on a PC. */ @@ -6625,8 +6655,8 @@ class Keyboard { _onUp = e =>{ this.keys[this.normalize(e.code)] = false; } -} - +} + /** * This handles all inputs from mouse and touchpad on laptops */ @@ -6788,8 +6818,8 @@ class Mouse { update() { this.lastPosition = { ...this.position }; } -} - +} + /** * Handles the touch input of an application from a smartphone,tablet or PCs with touchscreens. * @@ -6852,13 +6882,13 @@ class Touch { this.touches = e.touches; } update() {} -} - +} + /** * This handles all inputs from the mouse,touch and keyboards. * */ -class Input { +class Input$1 { /** * This attaches callbacks to the DOM. * @@ -6905,8 +6935,8 @@ class Input { this.keyboard.dispose(); this.touch.dispose(); } -} - +} + /** * */ @@ -6915,7 +6945,7 @@ class Input { * entities and ensuring that systems are updated every frame. * */ -class Manager { +class Manager$1 { /** * RAF number of current frame.Used for pausing the manager. * @@ -7064,7 +7094,7 @@ class Manager { input: true }, options); if (options.input) - this.registerSystem("input", new Input()); + this.registerSystem("input", new Input$1()); if (options.physics) { this.registerSystem("world", new World()); this.events.add("collision", defaultCollisionHandler); @@ -7101,7 +7131,7 @@ class Manager { */ add(object) { if (object.manager) { - Err$1.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); + Err.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); return } this.objects.push(object); @@ -7254,7 +7284,7 @@ class Manager { */ registerClass(obj, override = false) { let n = obj.name.toLowerCase(); - if (n in this._classes && !override) return Err$1.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) + if (n in this._classes && !override) return Err.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) this._classes[n] = obj; } /** @@ -7336,7 +7366,7 @@ class Manager { * @param {Array} comps An array containing the component names to be searched * @returns {Entity} */ - getEntityByComponents(comps) { + getEntityByComponents(comps,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < comps.length; j++) { if (!entities[i].has(comps[j])) continue @@ -7368,7 +7398,7 @@ class Manager { * @param {Array} tags An array containing the tags to be searched * @returns {Entity} */ - getEntityByTags(tags) { + getEntityByTags(tags,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < tags.length; j++) { if (!entities[i].hasTag(tags[j])) continue @@ -7403,7 +7433,7 @@ class Manager { if (n) { if (n in this._classes) return new this._classes[n]() - Err$1.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); + Err.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); } return obj instanceof Array ? [] : {} } @@ -7459,42 +7489,58 @@ class Manager { ///TODO - What will happen if there is no world? ...Yes,it will crash. return this._coreSystems.world.query(bound) } -} - +} + /** * Updates components assigned to it. * * @interface -*/ -class System{} + */ +class System { + init() { + Err.warnOnce("Please override the init method in the system " + proto.constructor.name); + } + update() { + Err.warnOnce("Please override the update method in the system " + proto.constructor.name); -Utils$1.inheritSystem(System); + } + add(component) { + this.objects.push(component); + } + remove(component) { + let index = this.objects.indexOf(component); + Utils$1.removeElement(this.objects, index); + } + static implement(system) { + mixin(System,system); + } +} /** * * @function * @name System#add * @param {Component} component -*/ + */ /** * * @function * @name System#remove * @param {Component} component -*/ + */ /** * * @function * @name System#init * @param {Manager} manager */ - /** - * - * @function - * @name System#update - * @param {number} dt - */ - +/** + * + * @function + * @name System#update + * @param {number} dt + */ + /** * Component to hold requirements for an entity to move. * @@ -7510,9 +7556,9 @@ class Movable extends Component { */ constructor(x, y, a) { super(); - this.velocity = new Vec2$1(x, y); + this.velocity = new Vector2$1(x, y); this.rotation = new Angle(a); - this.acceleration = new Vec2$1(); + this.acceleration = new Vector2$1(); } toJson() { return { @@ -7526,8 +7572,8 @@ class Movable extends Component { this.rotation.fromJson(obj.rptatjon); this.acceleration.fromJson(obj.acceleration); } -} - +} + /** * Component to hold the bounds of an entity. * @@ -7549,8 +7595,8 @@ class Bound extends Component { fromJson(obj){ this.bpunds.fromJson(obj.bounds); } -} - +} + /** * This is a container to hold components,tags and event handlers. * @@ -7821,8 +7867,54 @@ class Entity { obj.type = this.CHAOS_OBJ_TYPE; return obj } -} +} + +/** + * @param {number} x x-position of entity + * @param {number} y y-position of entity + * @param {number} a angle in degrees + */ +function createEntity(x, y, a) { + return new Entity() + .attach("transform", new Transform(x, y, a)) + .attach("movable", new Movable()) + .attach("bounds", new Bound()) +} + +/** + * Creates a new instance of Manager class with given default systems. + * + * @param {Object} [options] + * @param {boolean} [options.autoPlay=true] Whether the manager should immediately start playing after initialization + * @param {Object} [options.files={}] manager is passed onto the Loader.Please check `Loader.load()` for more information on it. + * @param {boolean} [options.physics=true] Adds physics world as a System. + * @param {boolean} [options.renderer=true] Adds a renderer as a system. + * @param {boolean} [options.input=true] Adds input as a system. + * + **/ +function createManager(options) { + options = Object.assign({ + autoPlay: true, + physics: true, + renderer: true, + input: true + }, options); + + let manager = new Manager(); + + if (options.input) + manager.registerSystem("input", new Input()); + if (options.physics) { + manager.registerSystem("world", new World()); + manager.events.add("collision", defaultCollisionHandler); + manager.events.add("precollision", defaultPrecollisionHandler); + } + if (options.renderer) + manager.registerSystem("renderer", new Renderer2D()); + return manager +} + /** * This class is responsible for playing a singular sound. */ @@ -7939,8 +8031,8 @@ class Sfx { this._source.disconnect(); this._source.connect(this._destination); } -} - +} + /** * Manages playing of audio using Web Audio. */ @@ -8137,8 +8229,8 @@ class AudioHandler { sfx.disconnect(); Utils$1.removeElement(this.playing, id); } -} - +} + /** * A system that manages agent components by updating them. */ @@ -8168,8 +8260,8 @@ class AgentManager { this.objects[i].update(inv_dt); } } -} - +} + /** * Manages the behaviours for an agent. * @@ -8185,7 +8277,7 @@ class BehaviourManager { /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2$1() + _accumulated = new Vector2$1() /** * Adds a behavior to the manager * @@ -8220,14 +8312,14 @@ class BehaviourManager { * @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2$1(); + let result = new Vector2$1(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vec2$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector2$1.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. @@ -8242,8 +8334,8 @@ class BehaviourManager { draw(renderer) { this._behaviours.forEach(b => b.draw(renderer)); } -} - +} + /** * This is a component class used to add AI behavior to an entity. * @@ -8253,19 +8345,19 @@ class Agent { /** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -8343,8 +8435,8 @@ class Agent { this.behaviours.draw(ctx); } } -Utils$1.inheritComponent(Agent); - +Component.implement(Agent); + /** * Base class for implementing customized behaviours. * @@ -8355,13 +8447,13 @@ class Behaviour { /** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -8391,9 +8483,9 @@ class Behaviour { /** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -8402,9 +8494,9 @@ class Behaviour { * @param {Renderer} renderer */ draw(renderer) {} -} - -let tmp1$4 = new Vec2$1(); +} + +let tmp1$4 = new Vector2$1(); /** * Creates a behaviour to evade a certain position. * @@ -8418,7 +8510,7 @@ class EvadeBehaviour extends Behaviour { */ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super(); @@ -8435,9 +8527,9 @@ class EvadeBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$4.copy(this.position).sub(this.pursuer); @@ -8449,10 +8541,10 @@ class EvadeBehaviour extends Behaviour { steering.clamp(0, this.maxForce); target.copy(steering); } -} - -let tmp1$3 = new Vec2$1(), - tmp2$2 = new Vec2$1(); +} + +let tmp1$3 = new Vector2$1(), + tmp2$2 = new Vector2$1(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8489,21 +8581,21 @@ class WanderBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vec2$1.random(forward); + Vector2$1.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2$1.fromDeg(this._theta + Vec2$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector2$1.fromDeg(this._theta + Vector2$1.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8511,8 +8603,8 @@ class WanderBehaviour extends Behaviour { target.copy(forward); } -} - +} + /** * Not impemented. * @@ -8531,15 +8623,15 @@ class Pursuit extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ } -} - +} + /** * not complete. * @@ -8563,16 +8655,16 @@ class Flock extends Behaviour{ } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { } -} - -let tmp1$2 = new Vec2$1(); +} + +let tmp1$2 = new Vector2$1(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8588,11 +8680,11 @@ class SeekBehaviour extends Behaviour { */ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8608,9 +8700,9 @@ class SeekBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$2.copy(this.target).sub(this.position); @@ -8620,10 +8712,10 @@ class SeekBehaviour extends Behaviour { steering.clamp(0, this.maxForce); target.copy(steering); } -} - -let tmp1$1 = new Vec2$1(), - tmp2$1 = new Vec2$1(); +} + +let tmp1$1 = new Vector2$1(), + tmp2$1 = new Vector2$1(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8638,7 +8730,7 @@ class ArriveBehaviour extends Behaviour { */ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8655,9 +8747,9 @@ class ArriveBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1$1.copy(this.target).sub(this.position); @@ -8676,10 +8768,10 @@ class ArriveBehaviour extends Behaviour { steering.draw(ctx, ...this.position); target.add(steering); } -} - -const tmp1 = new Vec2$1(); -const tmp2 = new Vec2$1(); +} + +const tmp1 = new Vector2$1(); +const tmp2 = new Vector2$1(); /** * Creates a behaviour that follows a certain path. * @@ -8702,14 +8794,14 @@ class PathFollowing extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position); let [p1, p2] = this.path.current(); - tmp2.normalize(); + tmp2.copy(p2).sub(p1).normalize(); let proj = tmp2.dot(tmp1.sub(p1)); let projPoint = this.path.update(proj); @@ -8742,7 +8834,7 @@ class PathFollowing extends Behaviour { /** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point); @@ -8777,13 +8869,13 @@ class PathFollowing extends Behaviour { ctx.closePath(); this.path.draw(ctx); } -} - -let tmp = new Vec2$1(); +} + +let tmp = new Vector2$1(); class Path { /** * @private - * type Vec2[] + * type Vector2[] */ _points = [] /** @@ -8821,15 +8913,15 @@ class Path { _finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2$1() + _lerpedPoint = new Vector2$1() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point); @@ -8878,7 +8970,7 @@ class Path { if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vec2$1.lerp( + Vector2$1.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -8907,8 +8999,8 @@ class Path { stroke(ctx, "lightgreen"); ctx.closePath(); } -} - +} + /** * Contains values showing which features are supported,general model of the device and browser used. */ @@ -9096,8 +9188,8 @@ DEVICE.webgl = !!window.WebGLRenderingContext; Object.freeze(DEVICE); Object.freeze(DEVICE.supportedAudio); -Object.freeze(DEVICE.supportedImages); - +Object.freeze(DEVICE.supportedImages); + /** * Used to manipulate and read from the cookie string. * @@ -9147,8 +9239,8 @@ const Cookies = { this.delete(pair[0]); } } -}; - +}; + /** * This provides temporary storage when your application tab is open. * @@ -9180,8 +9272,8 @@ const Session = { clear() { sessionStorage.clear(); } -}; - +}; + /** * This provides permanent storage */ @@ -9212,9 +9304,9 @@ const Storage = { clear() { localStorage.clear(); } -}; - -export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, Bound, BoundingBox, BoundingCircle, Box, BufferGeometry, CamController, Camera, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DistanceConstraint, Easing, Entity, Err$1 as Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Group, Input, Interpolation, Keyboard, Line, Loader, Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, NarrowPhase, Overlaps, Particle, ParticleSystemSprite, Path, PathFollowing, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SATNarrowPhase, SeekBehaviour, Session, Sfx, Shape, SpringConstraint, Sprite, SpriteMaterial, StaticImageMaterial, Storage, System, Touch, Transform, Triangle, Trigon, Utils$1 as Utils, Vec2$1 as Vec2, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, arc, circle, clamp, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, drawImage, exp, fill, fillText, lerp, line, map, naturalizePair, radToDeg, rand, rect, round, sq, sqrt, stroke, vertices, wrapAngle }; +}; + +export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, Bound, BoundingBox, BoundingCircle, Box, BufferGeometry, CamController, Camera, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DistanceConstraint, Easing, Entity, Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Group, Input$1 as Input, Interpolation, Keyboard, Line, Loader, Manager$1 as Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, NarrowPhase, Overlaps, Particle, ParticleSystemSprite, Path, PathFollowing, Perf, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SATNarrowPhase, SeekBehaviour, Session, Sfx, Shape, Signal, SpringConstraint, Sprite, SpriteMaterial, StaticImageMaterial, Storage, System, Touch, Transform, Triangle, Trigon, Utils$1 as Utils, Vec2, Vector, Vector2$1 as Vector2, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, arc, circle, clamp, createEntity, createManager, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, drawImage, exp, fill, fillText, lerp, line, map, mixin, naturalizePair, radToDeg, rand, rect, round, sq, sqrt, stroke, vertices, wrapAngle }; /** * @typedef Bounds * @property {Vector_like} max @@ -9233,13 +9325,13 @@ export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, * @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -9249,9 +9341,9 @@ export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, * @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo diff --git a/dist/chaos.umd.js b/dist/chaos.umd.js index 5355a79c..4bea0064 100644 --- a/dist/chaos.umd.js +++ b/dist/chaos.umd.js @@ -1,10 +1,10 @@ -/* - * @author Wayne Mwashuma - * {@link https://github.com/waynemwashuma/chaos-engine.git} - * @copyright 2023-2023 Wayne Mwashuma - * @license MIT - * - * +/* + * @author Wayne Mwashuma + * {@link https://github.com/waynemwashuma/chaos-engine.git} + * @copyright 2023-2023 Wayne Mwashuma + * @license MIT + * + * * MIT License Copyright (c) 2023 Wayne Mwashuma @@ -26,14 +26,14 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - */ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CHAOS = {})); -})(this, (function (exports) { 'use strict'; - + + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CHAOS = {})); +})(this, (function (exports) { 'use strict'; + /** * This module is used to check if bounds of a body overlap */ @@ -76,17 +76,17 @@ SOFTWARE. (x - b.pos.x) * (x - b.pos.x) + (y - b.pos.y) * (y - b.pos.y); - return distance < b.r; + return distance < b.r * b.r; } - }; - + }; + let marker = `🚀Chaos Engine Says::::\n`; let mess = []; /** * A set of functions to streamline logging of items to the console */ - const Err$1 = {}; + const Err = {}; /** * Logs out a warning to the console. @@ -94,7 +94,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.warn = function(message) { + Err.warn = function(message) { console.warn(marker + message); }; @@ -104,7 +104,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.throw = function(message) { + Err.throw = function(message) { throw new Error(marker + message) }; @@ -114,7 +114,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.error = function(message) { + Err.error = function(message) { console.error(marker + message); }; @@ -124,7 +124,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.log = function(message) { + Err.log = function(message) { console.log(marker + message); }; /** @@ -133,10 +133,10 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.warnOnce = function(message) { + Err.warnOnce = function warnOnce(message) { if (mess.includes(message)) return mess.push(message); - Err$1.warn(message); + Err.warn(message); }; /** * Logs out a message,warning or error to the console according to the supplied log function. @@ -146,11 +146,21 @@ SOFTWARE. * @param {string} message * @param {Function} errfunc */ - Err$1.assert = function(test, errfunc, message) { + Err.assert = function(test, errfunc, message) { if (!test) errfunc(message); return test }; + /** + * Logs out a warning to the console. + * + * @memberof Err + * @param {string} message + */ + Err.deprecate = function deprecate(message) { + Err.warnOnce(message); + }; + /** * Contains a subset of useful functionality. * @@ -259,7 +269,7 @@ SOFTWARE. } if (!proto.update && overrideUpdate) { proto.update = function() { - Err$1.warnOnce("Please override the update function in the component " + proto.constructor.name); + Err.warnOnce("Please override the update function in the component " + proto.constructor.name); }; } @@ -269,7 +279,7 @@ SOFTWARE. proto.requires = function(...names) { for (var i = 0; i < names.length; i++) if (!this.entity.has(names[i])) - Err$1.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); + Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); }; proto.query = function(bound, target = []) { @@ -297,39 +307,27 @@ SOFTWARE. }); }; /** - * Mixes the functions required by a system into a class. + * Mixes the functions required by an object into another object. * * @memberof Utils - * @param {Function} system the class constructor function to add methods to. + * @param {Object} from the object constructor function to add methods from. + * @param {Object} to the object constructor function to add methods to. */ - Utils$1.inheritSystem = function(system) { - if (system == void 0 || typeof system !== "function") return - let proto = system.prototype; - if (!proto.init) { - proto.init = function() { - Err$1.warnOnce("Please override the init method in the system " + proto.constructor.name); - }; - } - if (!proto.update) { - proto.update = function() { - Err$1.warnOnce("Please override the update method in the system " + proto.constructor.name); - - }; - } - if (!proto.add) { - proto.add = function(component) { - this.objects.push(component); - }; - } - - if (!proto.remove) { - proto.remove = function(component) { - let index = this.objects.indexOf(component); - Utils$1.removeElement(this.objects, index); - }; + function mixin(from, to,props = []) { + let proto = from.prototype; + let proto2 = to.prototype; + console.log(proto2); + Object.assign(proto,from); + for (let name of props) { + props[name]; + //if(!(methodName in proto))continue + //if (methodName in proto2) continue + + proto2[name] = proto[name]; } - }; - + //console.log(new to()); + } + /** * Handles time management for the game. */ @@ -365,27 +363,36 @@ SOFTWARE. return this.dt/1000 } - } - + } + + class Perf{ + _start = 0 + _time = 0 + start(){ + this._start = Performance.now(); + } + end(){ + this._time = Performance.now() - this._start; + return this._time + } + fps(){ + return 1000/this._time + } + } + /** * A helper class. * Since there are no interfaces in JavaScript, * you might have to extend this to create a component, but there is another solution. - * Use instead Utils.inheritComponent() if you have your own hierarchy of classes. + * Use instead `Component.implement()` if you have your own hierarchy of classes. * In typescript,this would be an interface. * * @interface * */ class Component { - /** - * @type Entity | null - */ - entity = null - destroy() { - this.entity = null; - } + destroy() {} /** * @type string */ @@ -399,25 +406,20 @@ SOFTWARE. return "component" } /** - * @param {Entity} entity - */ - init(entity) { - this.entity = entity; - } + init(entity) {} /** * @param {number} dt */ update(dt) { Err.warnOnce("Please override the update function in the component " + proto.constructor.name); - } /** * @param {string} n */ - get(n) { - return this.entity.getComponent(n); + get(entity,n) { + return entity.getComponent(n); } /** * @param {...string} names @@ -431,8 +433,8 @@ SOFTWARE. * @param {CircleBounding | BoxBounding} bound * @param {Entity} [target=[]] */ - query(bound, target = []) { - return this.entity.query(bound, target) + query(entity,bound, target = []) { + return entity.query(bound, target) } static fromJson() { throw "Implement static method fromJson() in your component " + this.CHOAS_CLASSNAME @@ -440,37 +442,11 @@ SOFTWARE. static toJson() { throw "Implement static method toJson() in your component " + this.CHOAS_CLASSNAME } - } - Utils$1.inheritComponent(Component); - /** - * Destroys the component. - * - * @function - * @name Component#destroy - */ - /** - * Initializes a component. - * - * @function - * @name Component#init - * @param {Entity} entity - */ - /** - * Updates a component.Called by the system which manages its type. - * - * @function - * @name Component#update - * @param {number} dt - */ - /** - * Gets a component in the entity containing this entity. - * - * @function - * @name Component#requires - * @param {string} ...names - * @throws Qhen a named component isnt in the parent entity - */ - + static implement(component) { + Utils$1.inheritComponent(component); + } + } + /** * A rectangular bound that is used to contain a body so that broadphase can be used for quick collision detection. */ @@ -576,7 +552,7 @@ SOFTWARE. /** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x; @@ -645,8 +621,8 @@ SOFTWARE. target.min.y = bound1.min.y < bound2.min.y ? bound1.min.y : bound2.min.y; return target } - } - + } + /** * A circular bound that is used to contain a body so that broadphase can be used for quick collision detection. */ @@ -733,8 +709,8 @@ SOFTWARE. this.pos.y = obj.posY; this.r = obj.r; } - } - + } + const RHI = Math.PI / 180, RHI_INV = 1 / RHI; @@ -860,8 +836,8 @@ SOFTWARE. */ function radToDeg(rad) { return rad * RHI_INV - } - + } + let obj$1 = { x: 0, y: 0 @@ -873,7 +849,7 @@ SOFTWARE. * @author Wayne Mwashuma * @license MIT */ - class Vec2$1 { + class Vector2$1 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -919,28 +895,28 @@ SOFTWARE. } /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Math.sqrt( Vec2$1.prototype.magnitudeSquared.call(obj$1)) + return Math.sqrt( Vector2$1.prototype.magnitudeSquared.call(obj$1)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj$1.x = this.x - v.x; obj$1.y = this.y - v.y; - return Vec2$1.prototype.magnitudeSquared.call(obj$1) + return Vector2$1.prototype.magnitudeSquared.call(obj$1) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -963,7 +939,7 @@ SOFTWARE. /** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -985,7 +961,7 @@ SOFTWARE. /** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -994,7 +970,7 @@ SOFTWARE. /** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -1038,7 +1014,7 @@ SOFTWARE. * Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -1056,21 +1032,21 @@ SOFTWARE. * Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2$1(); + target = target || new Vector2$1(); target.copy(this).normalize(); return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2$1()) { + normalFast(target = new Vector2$1()) { return target.set(-this.y, this.x) } /** @@ -1107,16 +1083,16 @@ SOFTWARE. * Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2$1(this.x, this.y) + return new Vector2$1(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -1172,10 +1148,10 @@ SOFTWARE. * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2$1()) { + reflect(normal, target = new Vector2$1()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1213,33 +1189,33 @@ SOFTWARE. * Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2); - let deg = Vec2$1.getDegBtwn(v1, v2); + let deg = Vector2$1.getDegBtwn(v1, v2); return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -1249,22 +1225,22 @@ SOFTWARE. * Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2$1.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2$1.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2$1()) { + static fromRad(radian, target = new Vector2$1()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -1272,32 +1248,32 @@ SOFTWARE. * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2$1.fromRad(degree * Math.PI / 180, target) + return Vector2$1.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2$1.fromRad(Math.random() * TWO_PI, target) + return Vector2$1.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2$1()) { - target = target || new Vec2$1(); + static lerp(v1, v2, t, target = new Vector2$1()) { + target = target || new Vector2$1(); return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -1307,17 +1283,17 @@ SOFTWARE. /** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2$1.toRad(v) / Math.PI * 180 + return Vector2$1.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -1330,12 +1306,24 @@ SOFTWARE. * * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2$1()) + static ZERO = Object.freeze(new Vector2$1()) } - + class Vector extends Vector2$1{ + constructor(x,y){ + super(x,y); + console.error("The class `Vector` is depreciated since v0.4.13.Use Vector2 instead."); + } + } + class Vec2 extends Vector2$1{ + constructor(x,y){ + super(x,y); + console.error("The class `Vec2` is depreciated since v0.4.13.Use Vector2 instead."); + } + } + /** * Wrapper class since JavaScript doesn't support references to numbers explicitly. * Keeps record of the orientation of an entity. @@ -1419,8 +1407,8 @@ SOFTWARE. type: this.CHAOS_OBJ_TYPE } } - } - + } + /** * A class that is used to transform positions through rotation, scaling and translation. */ @@ -1564,7 +1552,7 @@ SOFTWARE. /** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x; @@ -1634,8 +1622,8 @@ SOFTWARE. yield this.e; yield this.f; } - } - + } + function wrapAngle(x) { let a = x; while (a > Math.PI * 2) { @@ -1645,8 +1633,8 @@ SOFTWARE. a = a + Math.PI * 2; } return a - } - + } + const Easing = { Linear: { In: function(x) { @@ -1892,23 +1880,23 @@ SOFTWARE. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1 }, - }; - + }; + class Geometry { /** - * @type Vec2[] + * @type Vector2[] */ vertices = null /** - * @type Vec2[] + * @type Vector2[] */ normals = null /** - * @type Vec2[] + * @type Vector2[] */ _dynNormals = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices; @@ -1929,7 +1917,7 @@ SOFTWARE. } /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || []; @@ -1940,7 +1928,7 @@ SOFTWARE. } /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -1962,8 +1950,8 @@ SOFTWARE. } /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -1982,12 +1970,12 @@ SOFTWARE. return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)); + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)); this.normals = this.calcFaceNormals(); this._dynNormals = this.normals.map(e => e.clone()); } - } - + } + /**@enum {number}*/ const ShapeType = Object.freeze({ CIRCLE: 0, @@ -2026,9 +2014,9 @@ SOFTWARE. collisionResponse: true, autoUpdateBound: true, type:BodyType.DYNAMIC - }; - - let tmp1$c = new Vec2$1(); + }; + + let tmp1$c = new Vector2$1(); /** * This class makes a body tangible @@ -2051,13 +2039,13 @@ SOFTWARE. /** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -2068,11 +2056,11 @@ SOFTWARE. geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2$1(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); @@ -2101,8 +2089,8 @@ SOFTWARE. * Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -2110,7 +2098,7 @@ SOFTWARE. /** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -2122,9 +2110,9 @@ SOFTWARE. /** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices @@ -2157,8 +2145,8 @@ SOFTWARE. } static CIRCLE = 0 static POLYGON = 1 - } - + } + class Line extends Shape { /** * @type number @@ -2166,19 +2154,19 @@ SOFTWARE. length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2$1(1).multiply(length / 2), - end = new Vec2$1(1).multiply(-length / 2); + let start = new Vector2$1(1).multiply(length / 2), + end = new Vector2$1(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } - } - - let _vec1 = new Vec2$1(); - let _vec2 = new Vec2$1(); + } + + let _vec1 = new Vector2$1(); + let _vec2 = new Vector2$1(); /** * A circular shape. @@ -2191,14 +2179,14 @@ SOFTWARE. radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vec2$1(), new Vec2$1(), new Vec2$1()]; + this.vertices = [new Vector2$1(), new Vector2$1(), new Vector2$1()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2216,9 +2204,9 @@ SOFTWARE. /** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || []; @@ -2231,8 +2219,8 @@ SOFTWARE. /** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -2251,7 +2239,7 @@ SOFTWARE. /** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -2275,12 +2263,12 @@ SOFTWARE. fromJson(obj) { return new Circle( obj.radius, - new Vec2$1().fromJson(obj.offset), + new Vector2$1().fromJson(obj.offset), obj.offAngle ) } - } - + } + class Rectangle extends Shape { /** * @type number @@ -2293,14 +2281,14 @@ SOFTWARE. /** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2$1(-width / 2, -height / 2); - let v2 = new Vec2$1(-width / 2, height / 2); - let v3 = new Vec2$1(width / 2, height / 2); - let v4 = new Vec2$1(width / 2, -height / 2); + let v1 = new Vector2$1(-width / 2, -height / 2); + let v2 = new Vector2$1(-width / 2, height / 2); + let v3 = new Vector2$1(width / 2, height / 2); + let v4 = new Vector2$1(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2319,9 +2307,9 @@ SOFTWARE. return this.width * this.height } - } - - let tmp1$b = new Vec2$1(); + } + + let tmp1$b = new Vector2$1(); /** * A triangular shape. @@ -2333,16 +2321,16 @@ SOFTWARE. * @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2$1().set(1, 0).multiply(base); - let l2 = Vec2$1.fromRad(angle).multiply(height/Math.sin(angle)); + let l1 = new Vector2$1().set(1, 0).multiply(base); + let l2 = Vector2$1.fromRad(angle).multiply(height/Math.sin(angle)); let center = tmp1$b.set((l1.x + l2.x) / 3, l2.y / 3); super([ - new Vec2$1().sub(center), + new Vector2$1().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle); @@ -2350,8 +2338,8 @@ SOFTWARE. static calcInertia(mass,base,height,angle){ return 0.5 * mass * base * height * (1 - 2/3 * (1 - (Math.cos(2 * angle * 180/Math.PI))/2)) } - } - + } + /** * Holds information needed for collision detection and response. * @@ -2368,23 +2356,23 @@ SOFTWARE. * World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2$1() + _position = new Vector2$1() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2$1() + _velocity = new Vector2$1() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2$1() + _acceleration = new Vector2$1() /** * World space orientation of a body * @@ -2432,22 +2420,22 @@ SOFTWARE. * Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2$1() + lastPosition = new Vector2$1() /** * Inverse mass of the body. * @@ -2618,7 +2606,7 @@ SOFTWARE. /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -2629,7 +2617,7 @@ SOFTWARE. /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -2706,7 +2694,7 @@ SOFTWARE. /** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -2761,11 +2749,11 @@ SOFTWARE. /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector2$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2773,7 +2761,7 @@ SOFTWARE. * Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -2782,20 +2770,20 @@ SOFTWARE. * Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2$1()) { + getLocalAnchor(index, target = new Vector2$1()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2$1.ZERO) { + applyForce(force, arm = Vector2$1.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2895,7 +2883,7 @@ SOFTWARE. body.id = obj.id; body.mask = obj.mask; obj.anchors.forEach((v) => { - body.setAnchor(new Vec2$1().fromJson(v)); + body.setAnchor(new Vector2$1().fromJson(v)); }); } /** @@ -2919,8 +2907,8 @@ SOFTWARE. */ static DYNAMIC = ObjType.DYNAMIC } - Utils$1.inheritComponent(Body, false, false); - + Component.implement(Body); + /** * A body with a circle shape on it. * @@ -2946,8 +2934,8 @@ SOFTWARE. this.inv_mass = x === 0 ? 0 : 1 / x; this.inertia = Circle.calcInertia(this.mass, this.shapes[0].radius); } - } - + } + /** * A body with a rectangle shape on it. * @@ -2975,8 +2963,8 @@ SOFTWARE. get mass(){ return this._mass } - } - + } + /** * Holds a group of related bodies and constraints. */ @@ -3039,10 +3027,10 @@ SOFTWARE. /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2$1(); + let acceleration = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3056,10 +3044,10 @@ SOFTWARE. /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2$1(); + let velocity = new Vector2$1(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3133,11 +3121,11 @@ SOFTWARE. /** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2$1(); - for (var i = 0; i < this.shapes.length; i++) { + let position = new Vector2$1(); + for (var i = 0; i < this.bodies.length; i++) { position.add(this.bodies[i].position); } return position @@ -3183,8 +3171,8 @@ SOFTWARE. } } } - Utils$1.inheritComponent(Composite); - + Component.implement(Composite); + class Trigon extends Body { /** * @param {number} base @@ -3211,8 +3199,8 @@ SOFTWARE. this.inv_mass = x === 0 ? 0 : 1 / x; this.inertia = Triangle.calcInertia(this.mass, this.base, this.height,this.bangle); } - } - + } + /** * Base class for constructing different types of constraints. * @@ -3224,14 +3212,14 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vec2$1(); - this.localB = localB || new Vec2$1(); + this.localA = localA || new Vector2$1(); + this.localB = localB || new Vector2$1(); this.stiffness = 50; this.dampening = 0.03; } @@ -3293,20 +3281,20 @@ SOFTWARE. let constraint = new Constraint( bod1, bod2, - new Vec2$1().fromJson(obj.localA), - new Vec2$1().fromJson(obj.localB) + new Vector2$1().fromJson(obj.localA), + new Vector2$1().fromJson(obj.localB) ); constraint.stiffness = obj.stiffness; constraint.dampening = obj.dampening; return constraint } - } - - let tmp1$a = new Vec2$1(), - tmp2$8 = new Vec2$1(), - tmp3$4 = new Vec2$1(), - tmp4$4 = new Vec2$1(), - tmp5$3 = new Vec2$1(); + } + + let tmp1$a = new Vector2$1(), + tmp2$8 = new Vector2$1(), + tmp3$4 = new Vector2$1(), + tmp4$4 = new Vector2$1(), + tmp5$3 = new Vector2$1(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3315,8 +3303,8 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); @@ -3359,14 +3347,14 @@ SOFTWARE. body1.rotation.radian += tmp4$4.cross(arm1) * body1.inv_inertia; body2.rotation.radian += tmp4$4.cross(arm2) * -body2.inv_inertia; } - } - - let tmp1$9 = new Vec2$1(), - tmp2$7 = new Vec2$1(), - tmp3$3 = new Vec2$1(), - tmp4$3 = new Vec2$1(), - tmp5$2 = new Vec2$1(), - zero = new Vec2$1(); + } + + let tmp1$9 = new Vector2$1(), + tmp2$7 = new Vector2$1(), + tmp3$3 = new Vector2$1(), + tmp4$3 = new Vector2$1(), + tmp5$2 = new Vector2$1(), + zero = new Vector2$1(); /** * A constraint that acts like a spring between two bodies */ @@ -3374,13 +3362,13 @@ SOFTWARE. /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vec2$1().copy(localA || zero); - this.localB = new Vec2$1().copy(localB || zero); + this.localA = new Vector2$1().copy(localA || zero); + this.localB = new Vector2$1().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; this.dampening = 1; this.maxDistance = 100; @@ -3415,13 +3403,13 @@ SOFTWARE. body1.rotation.radian += force.cross(arm1) * body1.inv_inertia; body2.rotation.radian += force.cross(arm2) * -body2.inv_inertia; } - } - - new Vec2$1(); - - let position = new Vec2$1(); - let acceleration = new Vec2$1(); - let velocity = new Vec2$1(); + } + + new Vector2$1(); + + let position = new Vector2$1(); + let acceleration = new Vector2$1(); + let velocity = new Vector2$1(); /** * Verlet intergration. @@ -3445,13 +3433,13 @@ SOFTWARE. body.angle += body.angularVelocity * dt; body.angularVelocity += body.angularAcceleration * dt * 0.5; } - } - - let tmp1$8 = new Vec2$1(), - tmp2$6 = new Vec2$1(), - tmp3$2 = new Vec2$1(), - tmp4$2 = new Vec2$1(), - tmp5$1 = new Vec2$1(); + } + + let tmp1$8 = new Vector2$1(), + tmp2$6 = new Vector2$1(), + tmp3$2 = new Vector2$1(), + tmp4$2 = new Vector2$1(), + tmp5$1 = new Vector2$1(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3496,8 +3484,8 @@ SOFTWARE. manifold.rotA += ca1.cross(jt) * a.inv_inertia; manifold.rotB += ca2.cross(jt) * -b.inv_inertia; } - }; - + }; + let v = { x: 0, y: 0 }; let velocityLimit = 1; @@ -3525,10 +3513,10 @@ SOFTWARE. b.velocity = v; b.acceleration = v; } - }; - - const tmp1$7 = new Vec2$1(), - tmp2$5 = new Vec2$1(); + }; + + const tmp1$7 = new Vector2$1(), + tmp2$5 = new Vector2$1(); let dampen = Settings.posDampen; /** @@ -3548,12 +3536,12 @@ SOFTWARE. bodyB.rotation.radian += ca2.cross(jp) * -bodyB.inv_inertia * inv_dt; manifold.contactData.lastOverlap = overlap; } - }; - - let tmp1$6 = new Vec2$1(), - tmp2$4 = new Vec2$1(), - tmp3$1 = new Vec2$1(), - tmp4$1 = new Vec2$1(); + }; + + let tmp1$6 = new Vector2$1(), + tmp2$4 = new Vector2$1(), + tmp3$1 = new Vector2$1(), + tmp4$1 = new Vector2$1(); /** * Solves for the collision normal impulse of a given body pair. @@ -3592,8 +3580,8 @@ SOFTWARE. manifold.rotB = ang2; manifold.impulse = j; } - }; - + }; + /** * This is an abstract class that extended to classes that are used to filter out unnecessary collision checks to boost performance. * @@ -3661,8 +3649,8 @@ SOFTWARE. * @returns {Body[]} */ query(bounds, target) {} - } - + } + /** * Most basic broadphase.Should be used when number of bodies are few(i.e less than 100) */ @@ -3722,8 +3710,8 @@ SOFTWARE. return target } - } - + } + class Client { constructor(body) { this.body = body; @@ -4195,14 +4183,14 @@ SOFTWARE. * @callback Traverser * @param {Node} node * @returns {boolean} - */ - + */ + const _arr = [], tmp1$5 = { overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2$1(), + axis: new Vector2$1(), vertex: null, shape: null }, @@ -4216,9 +4204,9 @@ SOFTWARE. max: 0, indexN: 0 }, - tmp4 = new Vec2$1(), - tmp5 = new Vec2$1(), - tmp6 = new Vec2$1(); + tmp4 = new Vector2$1(), + tmp5 = new Vector2$1(), + tmp6 = new Vector2$1(); /** * Used for narrowphase collision detection and contact info generation. @@ -4305,7 +4293,7 @@ SOFTWARE. /** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -4365,8 +4353,8 @@ SOFTWARE. return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -4391,9 +4379,9 @@ SOFTWARE. return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -4421,7 +4409,7 @@ SOFTWARE. }, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -4429,9 +4417,9 @@ SOFTWARE. return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -4441,7 +4429,7 @@ SOFTWARE. return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { @@ -4462,14 +4450,14 @@ SOFTWARE. return true; } - }; - + }; + class NarrowPhase{ records = new Map() getCollisionPairs(contactList,clmds){ } - } - + } + /** * Uses the Separation Axis Theorem. * Best when your body shapes have few vertices. @@ -4493,7 +4481,7 @@ SOFTWARE. lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2$1(), + axis: new Vector2$1(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4506,13 +4494,13 @@ SOFTWARE. stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2$1(), - ca2: new Vec2$1(), + ca1: new Vector2$1(), + ca2: new Vector2$1(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2$1(), - velB: new Vec2$1(), + velA: new Vector2$1(), + velB: new Vector2$1(), rotA: 0, rotB: 0 }); @@ -4523,13 +4511,13 @@ SOFTWARE. SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vec2$1.lerp( + Vector2$1.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4547,8 +4535,8 @@ SOFTWARE. } return clmds } - } - + } + /** * Class responsible for updating bodies,constraints and composites. */ @@ -4623,9 +4611,9 @@ SOFTWARE. /** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2$1(0, 0) + gravitationalAcceleration = new Vector2$1(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4654,6 +4642,12 @@ SOFTWARE. * @type NarrowPhase */ narrowphase = null + /** + * Moves the bodies forward in time. + * + * @type {Intergrator} + */ + intergrator = VerletSolver /** * @constructor World * @@ -4672,7 +4666,7 @@ SOFTWARE. /** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration @@ -4750,7 +4744,8 @@ SOFTWARE. for (var i = 0; i < length; i++) { let a = this.objects[i]; if (!a.sleeping) - VerletSolver.solve(a, dt); + this.intergrator.solve(a, dt); + //VerletSolver.solve(a, dt) } } /** @@ -4943,8 +4938,8 @@ SOFTWARE. this.broadphase.query(bound, target); return target } - } - + } + //import { Component } from "./component.js" /** @@ -4961,7 +4956,7 @@ SOFTWARE. * @returns */ constructor(x,y,a){ - this.position = new Vec2$1(x,y); + this.position = new Vector2$1(x,y); this.orientation = new Angle(a); } init(){} @@ -4975,8 +4970,8 @@ SOFTWARE. this.position.fromJson(obj.position); this.orientation.fromJson(obj.orientation); } - } - + } + class Camera { /** * @readonly @@ -4986,7 +4981,7 @@ SOFTWARE. constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position @@ -4995,8 +4990,8 @@ SOFTWARE. this.transform.position.copy(x); } update() {} - } - + } + /** * This is an abstract class from which different types of renderers are implemented. * @@ -5140,8 +5135,8 @@ SOFTWARE. let canvas = this.domElement; canvas.style.width = w + "px"; canvas.style.height = h + "px"; - canvas.width = w; - canvas.height = h; + canvas.width = w * devicePixelRatio; + canvas.height = h * devicePixelRatio; } /** * Width of the renderer @@ -5165,8 +5160,8 @@ SOFTWARE. set height(x) { this.domElement.height = x; } - } - + } + /** * Renders images and paths to the 2D context of a canvas. * @@ -5242,8 +5237,8 @@ SOFTWARE. requestFullScreen() { this.domElement.parentElement.requestFullscreen(); } - } - + } + //Dont get too excited yet :) /** @@ -5255,8 +5250,8 @@ SOFTWARE. constructor(){ throw new Error("Dont get too excited yet :)") } - } - + } + /** * Renders images and paths to the webgl context of a canvas. * @@ -5266,8 +5261,8 @@ SOFTWARE. constructor(){ throw new Error("Hold your horses there!I haven't implemented this yet!") } - } - + } + /** * This is the base class used to render images and paths onto the renderer. * Extend it to create your custom behaviour. @@ -5322,7 +5317,7 @@ SOFTWARE. /** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -5356,9 +5351,9 @@ SOFTWARE. */ init(entity) { if(!entity){ - this._position = new Vec2$1(); + this._position = new Vector2$1(); this._orientation = new Angle(); - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return } this.entity = entity; @@ -5367,7 +5362,7 @@ SOFTWARE. this._position = transform.position; this._orientation = transform.orientation; //TODO - Correct this later - this._scale = new Vec2$1(1,1); + this._scale = new Vector2$1(1,1); return this } toJson(){ @@ -5388,8 +5383,8 @@ SOFTWARE. this.parent = renderer.getById(obj.parent); } } - Utils$1.inheritComponent(Sprite); - + Component.implement(Sprite); + /** * @interface */ @@ -5402,8 +5397,8 @@ SOFTWARE. render(ctx,dt,path){ throw "Override this method in derived class" } - } - + } + /** * * @implements Material @@ -5440,8 +5435,8 @@ SOFTWARE. ctx.strokeStyle = this.stroke; ctx.stroke(path); } - } - + } + /** * * @implements Material @@ -5483,8 +5478,8 @@ SOFTWARE. render(ctx) { ctx.drawImage(this.image, this.offset.x, this.offset.y, this.width, this.height); } - } - + } + /** * @param {CanvasRenderingContext2D} ctx * @param {number} x1 @@ -5517,7 +5512,7 @@ SOFTWARE. } /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ function vertices(ctx, vertices, close = true) { @@ -5592,8 +5587,8 @@ SOFTWARE. x, y, w, h); - } - + } + /** * * @implements Material @@ -5732,9 +5727,9 @@ SOFTWARE. if (this._frame >= this._maxFrame) this._frame = 0; } - } - - let r = new Vec2$1(); + } + + let r = new Vector2$1(); let material$1 = new BasicMaterial(); material$1.wireframe = true; /** @@ -5862,7 +5857,7 @@ SOFTWARE. shape.position.x, shape.position.y, shape.radius); - Vec2$1.fromRad(shape.angle, r).multiply(shape.radius); + Vector2$1.fromRad(shape.angle, r).multiply(shape.radius); line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y); @@ -5881,12 +5876,12 @@ SOFTWARE. this.body = parent.get("body"); super.init(parent); } - } - + } + class BufferGeometry { /** * @readonly - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -5895,7 +5890,7 @@ SOFTWARE. */ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || []; @@ -5908,8 +5903,8 @@ SOFTWARE. let path = this.drawable = new Path2D(); vertices(path, this.vertices, true); } - } - + } + class CircleGeometry { /** * @param {number} radius @@ -5930,12 +5925,12 @@ SOFTWARE. render(ctx) { circle(ctx, 0, 0, this.radius); } - } - + } + let geometry = new BufferGeometry([ - new Vec2$1(-10, -10), - new Vec2$1(-10, 10), - new Vec2$1(20, 0) + new Vector2$1(-10, -10), + new Vector2$1(-10, 10), + new Vector2$1(20, 0) ]); let material = new BasicMaterial(); material.fill = "purple"; @@ -5970,20 +5965,20 @@ SOFTWARE. this.agent.draw(ctx); super.render(ctx); } - } - + } + /** * Its a fricking particle! */ class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -6009,13 +6004,13 @@ SOFTWARE. */ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vec2$1(); + this.velocity = new Vector2$1(); this.radius = radius; this.color = { r: 100, @@ -6103,7 +6098,7 @@ SOFTWARE. */ create() { return new Particle( - new Vec2$1(...this.position), + new Vector2$1(...this.position), rand(1, 10), rand(1, 6) ) @@ -6146,8 +6141,8 @@ SOFTWARE. this.initParticles(this.frameIncrease); } } - } - + } + /** * Used for grouping similar. * @@ -6226,25 +6221,25 @@ SOFTWARE. this._children[i].render(ctx, dt); } } - } - + } + class CamController { /** * @readonly - * @type Vec2 + * @type Vector2 */ - offset = new Vec2$1() + offset = new Vector2$1() /** * @param {Camera} camera */ constructor(camera) { this.transform = camera.transform; - this.offset = new Vec2$1(); + this.offset = new Vector2$1(); this.targetPosition = null; this.targetOrientation = null; } /** - * @param { Vec2} position + * @param { Vector2} position * @param {Angle} orientation */ follow(position, orientation = null) { @@ -6273,8 +6268,8 @@ SOFTWARE. if (this.targetOrientation) this.transform.orientation.copy(this.targetOrientation); } - } - + } + //import { DEVICE } from "../device/index.js" class Loader { constructor(manager) { @@ -6307,7 +6302,7 @@ SOFTWARE. } else if (type === "json") { that.json[name] = JSON.parse(xhr.response); } else { - return Err$1.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) + return Err.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) } that._filesLoaded += 1; @@ -6328,7 +6323,7 @@ SOFTWARE. }, onerror: function(e) { that._filesErr += 1; - Err$1.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); + Err.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); if (that._filesLoaded + that._filesErr === that._totalFileNo && that.onfinish) that.onfinish(); } }; @@ -6398,8 +6393,8 @@ SOFTWARE. } } - } - + } + /** * This class manages all events by a game manager. * When adding a handler to an event with another handler,the latter will not be overriden,rather,the former will be added to complement the latter. @@ -6439,8 +6434,8 @@ SOFTWARE. } this.handlers[name] = [handler]; } - } - + } + /** * This handles events created by the DOM. */ @@ -6513,8 +6508,8 @@ SOFTWARE. Ill leave it for now. */ init() {} - } - + } + /** * This provides a way to fire off an entity's collision event handler registered to it. * @@ -6561,8 +6556,8 @@ SOFTWARE. clmds[i] ); } - } - + } + /**@enum {string}*/ const Events = { COLLISION : "collision", @@ -6575,8 +6570,43 @@ SOFTWARE. REMOVE : "remove", PAUSE : "pause", PLAY : "play" - }; - + }; + + class Signal { + _listeners = [] + _value = null + constructor(value){ + this._value = value; + } + set value(x) { + this._value == x; + for (var i = 0; i < this._listeners.length; i++) { + let func = this._listeners[i]; + func.listener(this); + if(func.callOnce) + this.removeListener(func.listener); + } + } + get value() { + return this._value + } + addListener(listener,callOnce=false) { + this._listeners.push({ + listener, + callOnce + }); + } + removeListener(listener) { + for (var i = 0; i < this._listeners.length; i++) { + if (this._listeners[i].listener == listener) + return this._detach(i) + } + } + _detach(bindingIndex){ + this._listeners.splice(i, 1); + } + } + /** * Handled the keyboard input of an application on a PC. */ @@ -6631,8 +6661,8 @@ SOFTWARE. _onUp = e =>{ this.keys[this.normalize(e.code)] = false; } - } - + } + /** * This handles all inputs from mouse and touchpad on laptops */ @@ -6794,8 +6824,8 @@ SOFTWARE. update() { this.lastPosition = { ...this.position }; } - } - + } + /** * Handles the touch input of an application from a smartphone,tablet or PCs with touchscreens. * @@ -6858,13 +6888,13 @@ SOFTWARE. this.touches = e.touches; } update() {} - } - + } + /** * This handles all inputs from the mouse,touch and keyboards. * */ - class Input { + class Input$1 { /** * This attaches callbacks to the DOM. * @@ -6911,8 +6941,8 @@ SOFTWARE. this.keyboard.dispose(); this.touch.dispose(); } - } - + } + /** * */ @@ -6921,7 +6951,7 @@ SOFTWARE. * entities and ensuring that systems are updated every frame. * */ - class Manager { + class Manager$1 { /** * RAF number of current frame.Used for pausing the manager. * @@ -7070,7 +7100,7 @@ SOFTWARE. input: true }, options); if (options.input) - this.registerSystem("input", new Input()); + this.registerSystem("input", new Input$1()); if (options.physics) { this.registerSystem("world", new World()); this.events.add("collision", defaultCollisionHandler); @@ -7107,7 +7137,7 @@ SOFTWARE. */ add(object) { if (object.manager) { - Err$1.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); + Err.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); return } this.objects.push(object); @@ -7260,7 +7290,7 @@ SOFTWARE. */ registerClass(obj, override = false) { let n = obj.name.toLowerCase(); - if (n in this._classes && !override) return Err$1.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) + if (n in this._classes && !override) return Err.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) this._classes[n] = obj; } /** @@ -7342,7 +7372,7 @@ SOFTWARE. * @param {Array} comps An array containing the component names to be searched * @returns {Entity} */ - getEntityByComponents(comps) { + getEntityByComponents(comps,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < comps.length; j++) { if (!entities[i].has(comps[j])) continue @@ -7374,7 +7404,7 @@ SOFTWARE. * @param {Array} tags An array containing the tags to be searched * @returns {Entity} */ - getEntityByTags(tags) { + getEntityByTags(tags,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < tags.length; j++) { if (!entities[i].hasTag(tags[j])) continue @@ -7409,7 +7439,7 @@ SOFTWARE. if (n) { if (n in this._classes) return new this._classes[n]() - Err$1.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); + Err.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); } return obj instanceof Array ? [] : {} } @@ -7465,42 +7495,58 @@ SOFTWARE. ///TODO - What will happen if there is no world? ...Yes,it will crash. return this._coreSystems.world.query(bound) } - } - + } + /** * Updates components assigned to it. * * @interface - */ - class System{} + */ + class System { + init() { + Err.warnOnce("Please override the init method in the system " + proto.constructor.name); + } + update() { + Err.warnOnce("Please override the update method in the system " + proto.constructor.name); - Utils$1.inheritSystem(System); + } + add(component) { + this.objects.push(component); + } + remove(component) { + let index = this.objects.indexOf(component); + Utils$1.removeElement(this.objects, index); + } + static implement(system) { + mixin(System,system); + } + } /** * * @function * @name System#add * @param {Component} component - */ + */ /** * * @function * @name System#remove * @param {Component} component - */ + */ /** * * @function * @name System#init * @param {Manager} manager */ - /** - * - * @function - * @name System#update - * @param {number} dt - */ - + /** + * + * @function + * @name System#update + * @param {number} dt + */ + /** * Component to hold requirements for an entity to move. * @@ -7516,9 +7562,9 @@ SOFTWARE. */ constructor(x, y, a) { super(); - this.velocity = new Vec2$1(x, y); + this.velocity = new Vector2$1(x, y); this.rotation = new Angle(a); - this.acceleration = new Vec2$1(); + this.acceleration = new Vector2$1(); } toJson() { return { @@ -7532,8 +7578,8 @@ SOFTWARE. this.rotation.fromJson(obj.rptatjon); this.acceleration.fromJson(obj.acceleration); } - } - + } + /** * Component to hold the bounds of an entity. * @@ -7555,8 +7601,8 @@ SOFTWARE. fromJson(obj){ this.bpunds.fromJson(obj.bounds); } - } - + } + /** * This is a container to hold components,tags and event handlers. * @@ -7827,8 +7873,54 @@ SOFTWARE. obj.type = this.CHAOS_OBJ_TYPE; return obj } - } + } + + /** + * @param {number} x x-position of entity + * @param {number} y y-position of entity + * @param {number} a angle in degrees + */ + function createEntity(x, y, a) { + return new Entity() + .attach("transform", new Transform(x, y, a)) + .attach("movable", new Movable()) + .attach("bounds", new Bound()) + } + + /** + * Creates a new instance of Manager class with given default systems. + * + * @param {Object} [options] + * @param {boolean} [options.autoPlay=true] Whether the manager should immediately start playing after initialization + * @param {Object} [options.files={}] manager is passed onto the Loader.Please check `Loader.load()` for more information on it. + * @param {boolean} [options.physics=true] Adds physics world as a System. + * @param {boolean} [options.renderer=true] Adds a renderer as a system. + * @param {boolean} [options.input=true] Adds input as a system. + * + **/ + function createManager(options) { + options = Object.assign({ + autoPlay: true, + physics: true, + renderer: true, + input: true + }, options); + + let manager = new Manager(); + + if (options.input) + manager.registerSystem("input", new Input()); + if (options.physics) { + manager.registerSystem("world", new World()); + manager.events.add("collision", defaultCollisionHandler); + manager.events.add("precollision", defaultPrecollisionHandler); + } + if (options.renderer) + manager.registerSystem("renderer", new Renderer2D()); + return manager + } + /** * This class is responsible for playing a singular sound. */ @@ -7945,8 +8037,8 @@ SOFTWARE. this._source.disconnect(); this._source.connect(this._destination); } - } - + } + /** * Manages playing of audio using Web Audio. */ @@ -8143,8 +8235,8 @@ SOFTWARE. sfx.disconnect(); Utils$1.removeElement(this.playing, id); } - } - + } + /** * A system that manages agent components by updating them. */ @@ -8174,8 +8266,8 @@ SOFTWARE. this.objects[i].update(inv_dt); } } - } - + } + /** * Manages the behaviours for an agent. * @@ -8191,7 +8283,7 @@ SOFTWARE. /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2$1() + _accumulated = new Vector2$1() /** * Adds a behavior to the manager * @@ -8226,14 +8318,14 @@ SOFTWARE. * @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2$1(); + let result = new Vector2$1(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vec2$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector2$1.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. @@ -8248,8 +8340,8 @@ SOFTWARE. draw(renderer) { this._behaviours.forEach(b => b.draw(renderer)); } - } - + } + /** * This is a component class used to add AI behavior to an entity. * @@ -8259,19 +8351,19 @@ SOFTWARE. /** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -8349,8 +8441,8 @@ SOFTWARE. this.behaviours.draw(ctx); } } - Utils$1.inheritComponent(Agent); - + Component.implement(Agent); + /** * Base class for implementing customized behaviours. * @@ -8361,13 +8453,13 @@ SOFTWARE. /** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -8397,9 +8489,9 @@ SOFTWARE. /** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -8408,9 +8500,9 @@ SOFTWARE. * @param {Renderer} renderer */ draw(renderer) {} - } - - let tmp1$4 = new Vec2$1(); + } + + let tmp1$4 = new Vector2$1(); /** * Creates a behaviour to evade a certain position. * @@ -8424,7 +8516,7 @@ SOFTWARE. */ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super(); @@ -8441,9 +8533,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$4.copy(this.position).sub(this.pursuer); @@ -8455,10 +8547,10 @@ SOFTWARE. steering.clamp(0, this.maxForce); target.copy(steering); } - } - - let tmp1$3 = new Vec2$1(), - tmp2$2 = new Vec2$1(); + } + + let tmp1$3 = new Vector2$1(), + tmp2$2 = new Vector2$1(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8495,21 +8587,21 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vec2$1.random(forward); + Vector2$1.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2$1.fromDeg(this._theta + Vec2$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector2$1.fromDeg(this._theta + Vector2$1.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8517,8 +8609,8 @@ SOFTWARE. target.copy(forward); } - } - + } + /** * Not impemented. * @@ -8537,15 +8629,15 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ } - } - + } + /** * not complete. * @@ -8569,16 +8661,16 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { } - } - - let tmp1$2 = new Vec2$1(); + } + + let tmp1$2 = new Vector2$1(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8594,11 +8686,11 @@ SOFTWARE. */ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8614,9 +8706,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1$2.copy(this.target).sub(this.position); @@ -8626,10 +8718,10 @@ SOFTWARE. steering.clamp(0, this.maxForce); target.copy(steering); } - } - - let tmp1$1 = new Vec2$1(), - tmp2$1 = new Vec2$1(); + } + + let tmp1$1 = new Vector2$1(), + tmp2$1 = new Vector2$1(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8644,7 +8736,7 @@ SOFTWARE. */ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super(); @@ -8661,9 +8753,9 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1$1.copy(this.target).sub(this.position); @@ -8682,10 +8774,10 @@ SOFTWARE. steering.draw(ctx, ...this.position); target.add(steering); } - } - - const tmp1 = new Vec2$1(); - const tmp2 = new Vec2$1(); + } + + const tmp1 = new Vector2$1(); + const tmp2 = new Vector2$1(); /** * Creates a behaviour that follows a certain path. * @@ -8708,14 +8800,14 @@ SOFTWARE. } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position); let [p1, p2] = this.path.current(); - tmp2.normalize(); + tmp2.copy(p2).sub(p1).normalize(); let proj = tmp2.dot(tmp1.sub(p1)); let projPoint = this.path.update(proj); @@ -8748,7 +8840,7 @@ SOFTWARE. /** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point); @@ -8783,13 +8875,13 @@ SOFTWARE. ctx.closePath(); this.path.draw(ctx); } - } - - let tmp = new Vec2$1(); + } + + let tmp = new Vector2$1(); class Path { /** * @private - * type Vec2[] + * type Vector2[] */ _points = [] /** @@ -8827,15 +8919,15 @@ SOFTWARE. _finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2$1() + _lerpedPoint = new Vector2$1() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point); @@ -8884,7 +8976,7 @@ SOFTWARE. if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vec2$1.lerp( + Vector2$1.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -8913,8 +9005,8 @@ SOFTWARE. stroke(ctx, "lightgreen"); ctx.closePath(); } - } - + } + /** * Contains values showing which features are supported,general model of the device and browser used. */ @@ -9102,8 +9194,8 @@ SOFTWARE. Object.freeze(DEVICE); Object.freeze(DEVICE.supportedAudio); - Object.freeze(DEVICE.supportedImages); - + Object.freeze(DEVICE.supportedImages); + /** * Used to manipulate and read from the cookie string. * @@ -9153,8 +9245,8 @@ SOFTWARE. this.delete(pair[0]); } } - }; - + }; + /** * This provides temporary storage when your application tab is open. * @@ -9186,8 +9278,8 @@ SOFTWARE. clear() { sessionStorage.clear(); } - }; - + }; + /** * This provides permanent storage */ @@ -9218,114 +9310,121 @@ SOFTWARE. clear() { localStorage.clear(); } - }; - - exports.Agent = Agent; - exports.AgentManager = AgentManager; - exports.AgentSprite = AgentSprite; - exports.Angle = Angle; - exports.ArriveBehaviour = ArriveBehaviour; - exports.AudioHandler = AudioHandler; - exports.Ball = Ball; - exports.BasicMaterial = BasicMaterial; - exports.Behaviour = Behaviour; - exports.Body = Body; - exports.BodySprite = BodySprite; - exports.Bound = Bound; - exports.BoundingBox = BoundingBox; - exports.BoundingCircle = BoundingCircle; - exports.Box = Box; - exports.BufferGeometry = BufferGeometry; - exports.CamController = CamController; - exports.Camera = Camera; - exports.Circle = Circle; - exports.CircleGeometry = CircleGeometry; - exports.Clock = Clock; - exports.Component = Component; - exports.Composite = Composite; - exports.Constraint = Constraint; - exports.Cookies = Cookies; - exports.DEVICE = DEVICE; - exports.DOMEventHandler = DOMEventHandler; - exports.DistanceConstraint = DistanceConstraint; - exports.Easing = Easing; - exports.Entity = Entity; - exports.Err = Err$1; - exports.EvadeBehaviour = EvadeBehaviour; - exports.EventDispatcher = EventDispatcher; - exports.Events = Events; - exports.Flock = Flock; - exports.Geometry = Geometry; - exports.Group = Group; - exports.Input = Input; - exports.Interpolation = Interpolation; - exports.Keyboard = Keyboard; - exports.Line = Line; - exports.Loader = Loader; - exports.Manager = Manager; - exports.Material = Material; - exports.Matrix = Matrix2; - exports.Matrix2 = Matrix2; - exports.Mouse = Mouse; - exports.Movable = Movable; - exports.NaiveBroadphase = NaiveBroadphase; - exports.NarrowPhase = NarrowPhase; - exports.Overlaps = Overlaps; - exports.Particle = Particle; - exports.ParticleSystemSprite = ParticleSystemSprite; - exports.Path = Path; - exports.PathFollowing = PathFollowing; - exports.Pursuit = Pursuit; - exports.QuadTreeBroadphase = Tree; - exports.Rectangle = Rectangle; - exports.Renderer = Renderer; - exports.Renderer2D = Renderer2D; - exports.SATNarrowPhase = SATNarrowPhase; - exports.SeekBehaviour = SeekBehaviour; - exports.Session = Session; - exports.Sfx = Sfx; - exports.Shape = Shape; - exports.SpringConstraint = SpringConstraint; - exports.Sprite = Sprite; - exports.SpriteMaterial = SpriteMaterial; - exports.StaticImageMaterial = StaticImageMaterial; - exports.Storage = Storage; - exports.System = System; - exports.Touch = Touch; - exports.Transform = Transform; - exports.Triangle = Triangle; - exports.Trigon = Trigon; - exports.Utils = Utils$1; - exports. Vec2 = Vec2$1; - exports.WanderBehaviour = WanderBehaviour; - exports.WebGLRenderer = WebGLRenderer; - exports.WebGPURenderer = WebGPURenderer; - exports.World = World; - exports.arc = arc; - exports.circle = circle; - exports.clamp = clamp; - exports.defaultCollisionHandler = defaultCollisionHandler; - exports.defaultPrecollisionHandler = defaultPrecollisionHandler; - exports.degToRad = degToRad; - exports.drawImage = drawImage; - exports.exp = exp; - exports.fill = fill; - exports.fillText = fillText; - exports.lerp = lerp; - exports.line = line; - exports.map = map; - exports.naturalizePair = naturalizePair; - exports.radToDeg = radToDeg; - exports.rand = rand; - exports.rect = rect; - exports.round = round; - exports.sq = sq; - exports.sqrt = sqrt; - exports.stroke = stroke; - exports.vertices = vertices; - exports.wrapAngle = wrapAngle; - -})); + }; + + exports.Agent = Agent; + exports.AgentManager = AgentManager; + exports.AgentSprite = AgentSprite; + exports.Angle = Angle; + exports.ArriveBehaviour = ArriveBehaviour; + exports.AudioHandler = AudioHandler; + exports.Ball = Ball; + exports.BasicMaterial = BasicMaterial; + exports.Behaviour = Behaviour; + exports.Body = Body; + exports.BodySprite = BodySprite; + exports.Bound = Bound; + exports.BoundingBox = BoundingBox; + exports.BoundingCircle = BoundingCircle; + exports.Box = Box; + exports.BufferGeometry = BufferGeometry; + exports.CamController = CamController; + exports.Camera = Camera; + exports.Circle = Circle; + exports.CircleGeometry = CircleGeometry; + exports.Clock = Clock; + exports.Component = Component; + exports.Composite = Composite; + exports.Constraint = Constraint; + exports.Cookies = Cookies; + exports.DEVICE = DEVICE; + exports.DOMEventHandler = DOMEventHandler; + exports.DistanceConstraint = DistanceConstraint; + exports.Easing = Easing; + exports.Entity = Entity; + exports.Err = Err; + exports.EvadeBehaviour = EvadeBehaviour; + exports.EventDispatcher = EventDispatcher; + exports.Events = Events; + exports.Flock = Flock; + exports.Geometry = Geometry; + exports.Group = Group; + exports.Input = Input$1; + exports.Interpolation = Interpolation; + exports.Keyboard = Keyboard; + exports.Line = Line; + exports.Loader = Loader; + exports.Manager = Manager$1; + exports.Material = Material; + exports.Matrix = Matrix2; + exports.Matrix2 = Matrix2; + exports.Mouse = Mouse; + exports.Movable = Movable; + exports.NaiveBroadphase = NaiveBroadphase; + exports.NarrowPhase = NarrowPhase; + exports.Overlaps = Overlaps; + exports.Particle = Particle; + exports.ParticleSystemSprite = ParticleSystemSprite; + exports.Path = Path; + exports.PathFollowing = PathFollowing; + exports.Perf = Perf; + exports.Pursuit = Pursuit; + exports.QuadTreeBroadphase = Tree; + exports.Rectangle = Rectangle; + exports.Renderer = Renderer; + exports.Renderer2D = Renderer2D; + exports.SATNarrowPhase = SATNarrowPhase; + exports.SeekBehaviour = SeekBehaviour; + exports.Session = Session; + exports.Sfx = Sfx; + exports.Shape = Shape; + exports.Signal = Signal; + exports.SpringConstraint = SpringConstraint; + exports.Sprite = Sprite; + exports.SpriteMaterial = SpriteMaterial; + exports.StaticImageMaterial = StaticImageMaterial; + exports.Storage = Storage; + exports.System = System; + exports.Touch = Touch; + exports.Transform = Transform; + exports.Triangle = Triangle; + exports.Trigon = Trigon; + exports.Utils = Utils$1; + exports.Vec2 = Vec2; + exports.Vector = Vector; + exports.Vector2 = Vector2$1; + exports.WanderBehaviour = WanderBehaviour; + exports.WebGLRenderer = WebGLRenderer; + exports.WebGPURenderer = WebGPURenderer; + exports.World = World; + exports.arc = arc; + exports.circle = circle; + exports.clamp = clamp; + exports.createEntity = createEntity; + exports.createManager = createManager; + exports.defaultCollisionHandler = defaultCollisionHandler; + exports.defaultPrecollisionHandler = defaultPrecollisionHandler; + exports.degToRad = degToRad; + exports.drawImage = drawImage; + exports.exp = exp; + exports.fill = fill; + exports.fillText = fillText; + exports.lerp = lerp; + exports.line = line; + exports.map = map; + exports.mixin = mixin; + exports.naturalizePair = naturalizePair; + exports.radToDeg = radToDeg; + exports.rand = rand; + exports.rect = rect; + exports.round = round; + exports.sq = sq; + exports.sqrt = sqrt; + exports.stroke = stroke; + exports.vertices = vertices; + exports.wrapAngle = wrapAngle; + +})); /** * @typedef Bounds * @property {Vector_like} max @@ -9344,13 +9443,13 @@ SOFTWARE. * @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -9360,9 +9459,9 @@ SOFTWARE. * @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo diff --git a/docs/AI_agent.js.html b/docs/AI_agent.js.html index 1e99b80d..7627e39b 100644 --- a/docs/AI_agent.js.html +++ b/docs/AI_agent.js.html @@ -23,7 +23,7 @@

Source: AI/agent.js

-
import { Utils } from "../utils/index.js"
+            
import { Component } from "../ecs/index.js"
 import { BehaviourManager } from "./behaviourManager.js"
 
 /**
@@ -35,19 +35,19 @@ 

Source: AI/agent.js

/** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -125,7 +125,7 @@

Source: AI/agent.js

this.behaviours.draw(ctx) } } -Utils.inheritComponent(Agent) +Component.implement(Agent) export { Agent }
@@ -138,13 +138,13 @@

Source: AI/agent.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviourManager.js.html b/docs/AI_behaviourManager.js.html index 149a4c45..466bfdae 100644 --- a/docs/AI_behaviourManager.js.html +++ b/docs/AI_behaviourManager.js.html @@ -24,7 +24,7 @@

Source: AI/behaviourManager.js

import { Utils } from "../utils/index.js"
-import { Vec2 } from "../math/index.js"
+import { Vector2 } from "../math/index.js"
 
 /**
  * Manages the behaviours for an agent.
@@ -41,7 +41,7 @@ 

Source: AI/behaviourManager.js

/** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2() + _accumulated = new Vector2() /** * Adds a behavior to the manager * @@ -76,14 +76,14 @@

Source: AI/behaviourManager.js

* @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2() + let result = new Vector2() this._accumulated.set(0, 0) for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt) this._accumulated.add(result) } this._agent.acceleration.add(this._accumulated) - this._agent.orientation.radian = Vec2.toRad(this._agent.velocity) + this._agent.orientation.radian = Vector2.toRad(this._agent.velocity) } /** * Removes all behaviours from a manager. @@ -111,13 +111,13 @@

Source: AI/behaviourManager.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_arrive.js.html b/docs/AI_behaviours_arrive.js.html index dc4cbe68..b440ea31 100644 --- a/docs/AI_behaviours_arrive.js.html +++ b/docs/AI_behaviours_arrive.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/arrive.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, map } from "../../math/index.js"
+import { Vector2, map } from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2()
 
 /**
  * This provides a seek behaviour which slows down when the agent approaches a target.
@@ -42,7 +42,7 @@ 

Source: AI/behaviours/arrive.js

*/ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -59,9 +59,9 @@

Source: AI/behaviours/arrive.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) @@ -94,13 +94,13 @@

Source: AI/behaviours/arrive.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_behaviour.js.html b/docs/AI_behaviours_behaviour.js.html index 59708b2e..356bd7a1 100644 --- a/docs/AI_behaviours_behaviour.js.html +++ b/docs/AI_behaviours_behaviour.js.html @@ -33,13 +33,13 @@

Source: AI/behaviours/behaviour.js

/** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -69,9 +69,9 @@

Source: AI/behaviours/behaviour.js

/** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** @@ -93,13 +93,13 @@

Source: AI/behaviours/behaviour.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_evade.js.html b/docs/AI_behaviours_evade.js.html index 85af1913..c180373d 100644 --- a/docs/AI_behaviours_evade.js.html +++ b/docs/AI_behaviours_evade.js.html @@ -24,9 +24,9 @@

Source: AI/behaviours/evade.js

import { Behaviour } from "./behaviour.js"
-import { Vec2,map } from "../../math/index.js"
+import { Vector2,map } from "../../math/index.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
 /**
  * Creates a behaviour to evade a certain position.
  * 
@@ -40,7 +40,7 @@ 

Source: AI/behaviours/evade.js

*/ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super() @@ -57,9 +57,9 @@

Source: AI/behaviours/evade.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.position).sub(this.pursuer) @@ -85,13 +85,13 @@

Source: AI/behaviours/evade.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_flocking.js.html b/docs/AI_behaviours_flocking.js.html index bf9530d2..23bde3b1 100644 --- a/docs/AI_behaviours_flocking.js.html +++ b/docs/AI_behaviours_flocking.js.html @@ -24,7 +24,7 @@

Source: AI/behaviours/flocking.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 
 /**
@@ -50,9 +50,9 @@ 

Source: AI/behaviours/flocking.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { @@ -71,13 +71,13 @@

Source: AI/behaviours/flocking.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_path.js.html b/docs/AI_behaviours_path.js.html index 84302f58..404910a3 100644 --- a/docs/AI_behaviours_path.js.html +++ b/docs/AI_behaviours_path.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/path.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, map } from "../../math/index.js"
+import { Vector2, map } from "../../math/index.js"
 import { circle, fill, stroke } from "../../render/index.js"
-const tmp1 = new Vec2()
-const tmp2 = new Vec2()
+const tmp1 = new Vector2()
+const tmp2 = new Vector2()
 /**
  * Creates a behaviour that follows a certain path.
  * 
@@ -50,14 +50,14 @@ 

Source: AI/behaviours/path.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position) let [p1, p2] = this.path.current() - tmp2.normalize() + tmp2.copy(p2).sub(p1).normalize() let proj = tmp2.dot(tmp1.sub(p1)) let projPoint = this.path.update(proj) @@ -90,7 +90,7 @@

Source: AI/behaviours/path.js

/** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point) @@ -135,13 +135,13 @@

Source: AI/behaviours/path.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_pursuit.js.html b/docs/AI_behaviours_pursuit.js.html index 00e9e4d1..2549d8fc 100644 --- a/docs/AI_behaviours_pursuit.js.html +++ b/docs/AI_behaviours_pursuit.js.html @@ -24,7 +24,7 @@

Source: AI/behaviours/pursuit.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 
 /**
@@ -45,9 +45,9 @@ 

Source: AI/behaviours/pursuit.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ @@ -66,13 +66,13 @@

Source: AI/behaviours/pursuit.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_seek.js.html b/docs/AI_behaviours_seek.js.html index fa2174e3..34031d6e 100644 --- a/docs/AI_behaviours_seek.js.html +++ b/docs/AI_behaviours_seek.js.html @@ -24,9 +24,9 @@

Source: AI/behaviours/seek.js

import { Behaviour } from "./behaviour.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
   
 /**
  * Creates a behaviour to seek out a target and move towards it.
@@ -42,11 +42,11 @@ 

Source: AI/behaviours/seek.js

*/ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -62,9 +62,9 @@

Source: AI/behaviours/seek.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) @@ -88,13 +88,13 @@

Source: AI/behaviours/seek.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_wandering.js.html b/docs/AI_behaviours_wandering.js.html index 4e791ead..51616fc6 100644 --- a/docs/AI_behaviours_wandering.js.html +++ b/docs/AI_behaviours_wandering.js.html @@ -24,10 +24,10 @@

Source: AI/behaviours/wandering.js

import { Behaviour } from "./behaviour.js"
-import { Vec2, rand } from "../../math/index.js"
+import { Vector2, rand } from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2()
   
 /**
  * Creates a behaviour that is used to make an agent wander in an organic manner.
@@ -64,21 +64,21 @@ 

Source: AI/behaviours/wandering.js

} /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta) let forward = tmp1.copy(this.velocity) if (forward.equalsZero()) - Vec2.random(forward) + Vector2.random(forward) let radius = this._radius * 0.8 forward.setMagnitude(this._radius) //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2.fromDeg(this._theta + Vec2.toDeg(this.velocity), tmp2).multiply(radius) + Vector2.fromDeg(this._theta + Vector2.toDeg(this.velocity), tmp2).multiply(radius) forward.add(tmp2) //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed) @@ -100,13 +100,13 @@

Source: AI/behaviours/wandering.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_manager.js.html b/docs/AI_manager.js.html index 3676cd8b..1bacac9a 100644 --- a/docs/AI_manager.js.html +++ b/docs/AI_manager.js.html @@ -62,13 +62,13 @@

Source: AI/manager.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AI_paths_path.js.html b/docs/AI_paths_path.js.html index 93c8372c..4de407b1 100644 --- a/docs/AI_paths_path.js.html +++ b/docs/AI_paths_path.js.html @@ -23,14 +23,14 @@

Source: AI/paths/path.js

-
import { Vec2, clamp } from "../../math/index.js"
+            
import { Vector2, clamp } from "../../math/index.js"
 import { vertices, stroke } from "../../render/index.js"
 
-let tmp = new Vec2()
+let tmp = new Vector2()
 export class Path {
   /**
    * @private
-   * type Vec2[]
+   * type Vector2[]
    */
   _points = []
   /**
@@ -68,15 +68,15 @@ 

Source: AI/paths/path.js

_finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2() + _lerpedPoint = new Vector2() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point) @@ -125,7 +125,7 @@

Source: AI/paths/path.js

if (!this.advance()) this._finished = true } this._lerp_t = clamp(this._lerp_t, 0, 1) - Vec2.lerp( + Vector2.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -164,13 +164,13 @@

Source: AI/paths/path.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/Agent.html b/docs/Agent.html index 4cccc7c1..2bb90299 100644 --- a/docs/Agent.html +++ b/docs/Agent.html @@ -1,1450 +1,1363 @@ - - - - - JSDoc: Class: Agent - - - - - - - - - -
- -

Class: Agent

- - - - - - -
- -
- -

Agent()

- -
This is a component class used to add AI behavior to an entity.
- - -
- -
-
- - - - -

Constructor

- - - -

new Agent()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

acceleration : Vec2

- - - - -
- The acceleration of the entity. -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

entity :Entity|null

- - - - - - -
Type:
-
    -
  • - -Entity -| - -null - - -
  • -
- - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

maxSpeed :number

- - - - -
- The maximum speed of the agent in pixels per second. -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

maxTurnRate

- - - - -
- Maximum rotation of the agent in radians per second -Not yet implemented. -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

orientation :Angle

- - - - -
- The orientation of the entity. -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - Vec2 Vec2 -

position :Vector

- - - - -
- The position of the entity. -
- - - -
Type:
-
    -
  • - Vec2 Vec2 -Vector - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

rotation :Angle

- - - - -
- The rotation of the entity. -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - Vec2 Vec2 -

velocity :Vector

- - - - -
- The velocity of the entity. -
- - - -
Type:
-
    -
  • - Vec2 Vec2 -Vector - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

add(behaviour)

- - - - - - -
- Adds a behavior to the agent. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
behaviour - - -Behaviour - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

draw(ctx)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

init(entity)

- - - - - - -
- Initializes a component. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
entity - - -Entity - - - -
- - - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

remove(behaviour)

- - - - - - -
- Removes a behavior to the agent. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
behaviour - - -Behaviour - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

update(dt)

- - - - - - -
- Updates a component.Called by the system which manages its type. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
dt - - -number - - - -
- - - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: Agent + + + + + + + + + +
+ +

Class: Agent

+ + + + + + +
+ +
+ +

Agent()

+ +
This is a component class used to add AI behavior to an entity.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Agent()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
Implements:
+
+ + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

acceleration :Vector2

+ + + + +
+ The acceleration of the entity. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

maxSpeed :number

+ + + + +
+ The maximum speed of the agent in pixels per second. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

maxTurnRate

+ + + + +
+ Maximum rotation of the agent in radians per second Not yet implemented. +
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

orientation :Angle

+ + + + +
+ The orientation of the entity. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

position :Vector2

+ + + + +
+ The position of the entity. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

rotation :Angle

+ + + + +
+ The rotation of the entity. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

velocity :Vector2

+ + + + +
+ The velocity of the entity. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

add(behaviour)

+ + + + + + +
+ Adds a behavior to the agent. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
behaviour + + +Behaviour + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

draw(ctx)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ctx + + +CanvasRenderingContext2D + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

init(entity)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
entity + + +Entity + + + +
+ + + + + + +
+ + + + + + + + + + + + +
Implements:
+
+ + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

remove(behaviour)

+ + + + + + +
+ Removes a behavior to the agent. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
behaviour + + +Behaviour + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

update(dt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dt + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + +
Implements:
+
+ + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/AgentManager.html b/docs/AgentManager.html index f5ee71a0..10c7a55c 100644 --- a/docs/AgentManager.html +++ b/docs/AgentManager.html @@ -506,13 +506,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/AgentSprite.html b/docs/AgentSprite.html index 9051703d..bf9f1b1e 100644 --- a/docs/AgentSprite.html +++ b/docs/AgentSprite.html @@ -388,7 +388,7 @@
Type:
-

position : Vec2

+

position :Vector2

@@ -403,7 +403,7 @@
Type:
- -
- - - - - - - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: SeekBehaviour + + + + + + + + + +
+ +

Class: SeekBehaviour

+ + + + + + +
+ +
+ +

SeekBehaviour(target)

+ +
Creates a behaviour to seek out a target and move towards it.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new SeekBehaviour(target)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Vector2 + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Members

+ + + +

active

+ + + + +
+ Whether to exert a behaviour's calculated force onto its agent +
+ + + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

maxForce :number

+ + + + +
+ Maximum force a behaviour will exert on the agent.This affects acceleration, deceleration and turn rate of the agent. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

maxSpeed :number

+ + + + +
+ The maximum speed a behaviour will reach when active. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

position :Vector2

+ + + + +
+ The position of the agent. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

radius :number

+ + + + +
+ Not implemented. Radius in which to seek out the target. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

target :Vector2

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

velocity :Vector2

+ + + + +
+ The velocity of the agent. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

calc(target, inv_dt)

+ + + + + + +
+ Calculates the amount of force required to satisfy a behavior. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Vector2 + + + +
inv_dt + + +number + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ Vector2 the first parameter +
+ + + + + + + + + + + + + + + +

draw(renderer)

+ + + + + + +
+ Used to debug a behavior visually. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
renderer + + +Renderer + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

init(agent)

+ + + + + + +
+ Sets up a behavior to work on an agent. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
agent + + +Agent + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/Sfx.html b/docs/Sfx.html index 36f4d3db..392f2f19 100644 --- a/docs/Sfx.html +++ b/docs/Sfx.html @@ -999,13 +999,13 @@

resume
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/Shape.html b/docs/Shape.html index 3fc3dffd..dfa8519e 100644 --- a/docs/Shape.html +++ b/docs/Shape.html @@ -1,1564 +1,1563 @@ - - - - - JSDoc: Class: Shape - - - - - - - - - -
- -

Class: Shape

- - - - - - -
- -
- -

Shape(vertices, offsetopt, offsetAngleopt)

- -
This class makes a body tangible -to collision detection and response.Without it,the body will not be able to interact with other bodies.
- - -
- -
-
- - - - -

Constructor

- - - -

new Shape(vertices, offsetopt, offsetAngleopt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
vertices - - Vec2 Vec2 -Array.<Vector> - - - - - - - - - - - - The vertices of the shape in local space coordinates.
offset - - Vec2 Vec2 -Vector - - - - - - <optional>
- - - - - -
- - vector - - offset position relative to parent body
offsetAngle - - -number - - - - - - <optional>
- - - - - -
- - 0 - - offset angle relative to parent body.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

area :number

- - - - -
- The area occupied by a shape. -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

geometry :Geometry

- - - - -
- Keeps the original normals and vertices of this shape -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

offAngle :number

- - - - -
- The offset angle of this shape from this body's angle. -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - Vec2 Vec2 -

offPosition :Vector

- - - - -
- The offset position of this shape from this body's position. -
- - - -
Type:
-
    -
  • - Vec2 Vec2 -Vector - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

(readonly) type :number

- - - - -
- Used to determine what type of shape this is. -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - Vec2 Vec2 -

vertices :Array.<Vector>

- - - - -
- The vertices describing the shape. -
- - - -
Type:
-
    -
  • - Vec2 Vec2 -Array.<Vector> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - Vec2 Vec2 -

getNormals(shape, targetopt) → {Array.<Vector>}

- - - - - - -
- Returns the normals of the faces when rotated. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
shape - - -Shape - - - - - - - - - - - -
target - - Vec2 Vec2 -Array.<Vector> - - - - - - <optional>
- - - - - -
- - [] - - An array where results are stored.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- Vec2 Vec2 -Array.<Vector> - - -
-
- - - - - - - - - - - - - Vec2 Vec2 -

getVertices(axis, target) → {Array.<Vector>}

- - - - - - -
- Returns the world coordinates of the vertices. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
axis - - Vec2 Vec2 -Vector - - - -
target - - Vec2 Vec2 -Array.<Vector> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- Vec2 Vec2 -Array.<Vector> - - -
-
- - - - - - - - - - - - - -

update(position, angle, scale)

- - - - - - -
- Transforms the local coordinates of the vertices to world coordinates. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
position - - Vec2 Vec2 -Vector - - - - the world position of the body
angle - - -number - - - - the orientation of body
scale - - -number - - - - the scale of the body
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

(abstract, static) calcInertia() → {number}

- - - - - - -
- Calculates the inertia of a given shape. -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: Shape + + + + + + + + + +
+ +

Class: Shape

+ + + + + + +
+ +
+ +

Shape(vertices, offsetopt, offsetAngleopt)

+ +
This class makes a body tangible to collision detection and response.Without it,the body will not be able to interact with other bodies.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Shape(vertices, offsetopt, offsetAngleopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
vertices + + +Array.<Vector2> + + + + + + + + + + + + The vertices of the shape in local space coordinates.
offset + + +Vector2 + + + + + + <optional>
+ + + + + +
+ + vector + + offset position relative to parent body
offsetAngle + + +number + + + + + + <optional>
+ + + + + +
+ + 0 + + offset angle relative to parent body.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

area :number

+ + + + +
+ The area occupied by a shape. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

geometry :Geometry

+ + + + +
+ Keeps the original normals and vertices of this shape +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

offAngle :number

+ + + + +
+ The offset angle of this shape from this body's angle. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

offPosition :Vector2

+ + + + +
+ The offset position of this shape from this body's position. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(readonly) type :number

+ + + + +
+ Used to determine what type of shape this is. +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

vertices :Array.<Vector2>

+ + + + +
+ The vertices describing the shape. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

getNormals(shape, targetopt) → {Array.<Vector2>}

+ + + + + + +
+ Returns the normals of the faces when rotated. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
shape + + +Shape + + + + + + + + + + + +
target + + +Array.<Vector2> + + + + + + <optional>
+ + + + + +
+ + [] + + An array where results are stored.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<Vector2> + + +
+
+ + + + + + + + + + + + + +

getVertices(axis, target) → {Array.<Vector2>}

+ + + + + + +
+ Returns the world coordinates of the vertices. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
axis + + +Vector2 + + + +
target + + +Array.<Vector2> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<Vector2> + + +
+
+ + + + + + + + + + + + + +

update(position, angle, scale)

+ + + + + + +
+ Transforms the local coordinates of the vertices to world coordinates. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
position + + +Vector2 + + + + the world position of the body
angle + + +number + + + + the orientation of body
scale + + +number + + + + the scale of the body
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

(abstract, static) calcInertia() → {number}

+ + + + + + +
+ Calculates the inertia of a given shape. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +number + + +
+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/SpringConstraint.html b/docs/SpringConstraint.html index 0534d6ad..91661d5f 100644 --- a/docs/SpringConstraint.html +++ b/docs/SpringConstraint.html @@ -134,7 +134,7 @@
Parameters:
- Vec2 +Vector2 @@ -157,7 +157,7 @@
Parameters:
- Vec2 +Vector2 @@ -453,13 +453,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/Sprite.html b/docs/Sprite.html index e47bd4ee..7c954420 100644 --- a/docs/Sprite.html +++ b/docs/Sprite.html @@ -1,676 +1,674 @@ - - - - - JSDoc: Class: Sprite - - - - - - - - - -
- -

Class: Sprite

- - - - - - -
- -
- -

Sprite(geometry, material)

- -
This is the base class used to render images and paths onto the renderer. -Extend it to create your custom behaviour.
- - -
- -
-
- - - - -

Constructor

- - - -

new Sprite(geometry, material)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
geometry - - -BufferGeometry - - - -
material - - -Material - - - -
- - - - - - -
- - - - - - - - - - - - -
Implements:
-
    - -
  • Component -TODO - ADD id property to this class and Group class.
  • - -
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

angle :number

- - - - -
- Angle in degrees -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

orientation :Angle

- - - - -
- Orientation of the sprite -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

parent :Group|null

- - - - - - -
Type:
-
    -
  • - -Group -| - -null - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - Vec2 Vec2 - -

position :Vector

- - - - -
- World space position. -
- - - -
Type:
-
    -
  • Vec2 Vec2 - -Vector - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

init(entity)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
entity - - -Entity - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- Vec2 Vec2 - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: Sprite + + + + + + + + + +
+ +

Class: Sprite

+ + + + + + +
+ +
+ +

Sprite(geometry, material)

+ +
This is the base class used to render images and paths onto the renderer. Extend it to create your custom behaviour.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Sprite(geometry, material)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
geometry + + +BufferGeometry + + + +
material + + +Material + + + +
+ + + + + + +
+ + + + + + + + + + + + +
Implements:
+
    + +
  • Component TODO - ADD id property to this class and Group class.
  • + +
+ + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

angle :number

+ + + + +
+ Angle in degrees +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

orientation :Angle

+ + + + +
+ Orientation of the sprite +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

parent :Group|null

+ + + + + + +
Type:
+
    +
  • + +Group +| + +null + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

position :Vector2

+ + + + +
+ World space position. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

init(entity)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
entity + + +Entity + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/SpriteMaterial.html b/docs/SpriteMaterial.html index a3f7e2ac..0776b4aa 100644 --- a/docs/SpriteMaterial.html +++ b/docs/SpriteMaterial.html @@ -1213,13 +1213,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/StaticImageMaterial.html b/docs/StaticImageMaterial.html index 315e064e..4b8850e0 100644 --- a/docs/StaticImageMaterial.html +++ b/docs/StaticImageMaterial.html @@ -631,13 +631,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/StaticImageSprite.html b/docs/StaticImageSprite.html index c7f73c5f..032dec5d 100644 --- a/docs/StaticImageSprite.html +++ b/docs/StaticImageSprite.html @@ -742,7 +742,7 @@
Parameters:

diff --git a/docs/System.html b/docs/System.html index 4e4c1dbc..834d5fcd 100644 --- a/docs/System.html +++ b/docs/System.html @@ -69,7 +69,7 @@

System

Source:
@@ -205,7 +205,7 @@
Parameters:
Source:
@@ -338,7 +338,7 @@
Parameters:
Source:
@@ -471,7 +471,7 @@
Parameters:
Source:
@@ -604,7 +604,7 @@
Parameters:
Source:
@@ -650,13 +650,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/Touch.html b/docs/Touch.html index 7249a1e2..e064341b 100644 --- a/docs/Touch.html +++ b/docs/Touch.html @@ -1,637 +1,634 @@ - - - - - JSDoc: Class: Touch - - - - - - - - - -
- -

Class: Touch

- - - - - - -
- -
- -

Touch(eh)

- -
Handles the touch input of an application from a smartphone,tablet or PCs with touchscreens. - -Realized i need to massively change this to make it work well.
- - -
- -
-
- - - - -

Constructor

- - - -

new Touch(eh)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
eh - - -DOMEventHandler - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

clickCount :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

touches :Array.<TouchEvent>

- - - - - - -
Type:
-
    -
  • - -Array.<TouchEvent> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

inDragBox(pos)

- - - - - - -
- Checks to see if the position is within the dragbox of the first two touches. -Not yet fully implemented -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
pos - - -Vector_like - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

init(eh)

- - - - - - -
- Adds Touch events to the DOM. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
eh - - -DOMEventHandler - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
Vec2 Vec2 - - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: Touch + + + + + + + + + +
+ +

Class: Touch

+ + + + + + +
+ +
+ +

Touch(eh)

+ +
Handles the touch input of an application from a smartphone,tablet or PCs with touchscreens. Realized i need to massively change this to make it work well.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Touch(eh)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
eh + + +DOMEventHandler + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

clickCount :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

touches :Array.<TouchEvent>

+ + + + + + +
Type:
+
    +
  • + +Array.<TouchEvent> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

inDragBox(pos)

+ + + + + + +
+ Checks to see if the position is within the dragbox of the first two touches. Not yet fully implemented +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Vector_like + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

init(eh)

+ + + + + + +
+ Adds Touch events to the DOM. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
eh + + +DOMEventHandler + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/Transform.html b/docs/Transform.html index 9287b538..35c7ff56 100644 --- a/docs/Transform.html +++ b/docs/Transform.html @@ -192,7 +192,7 @@
Parameters:
Source:
@@ -244,88 +244,6 @@
Returns:
-

Members

- - - -

entity :Entity|null

- - - - - - -
Type:
-
    -
  • - -Entity -| - -null - - -
  • -
- - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

Methods

@@ -343,10 +261,6 @@

init - Initializes a component. - - @@ -444,7 +358,7 @@
Parameters:
Source:
@@ -490,13 +404,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/Tree.html b/docs/Tree.html index 2a4a7ec0..477348b8 100644 --- a/docs/Tree.html +++ b/docs/Tree.html @@ -1,3037 +1,3034 @@ - - - - - JSDoc: Class: Tree - - - - - - - - - -
- -

Class: Tree

- - - - - - -
- -
- -

Tree()

- -
This is an unbounded broadphase used to speed up collision testing. -This can be used generally as it is faster than naive broadphase when a lot of objects are involved in the physics simulation.
- - -
- -
-
- - - - -

Constructor

- - - -

new Tree()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - -

Extends

- - - - - - - - - - - - - - - - - - - - - - -

Methods

- - - - - - - -

canCollide(a, b)

- - - - - - -
- Checks to see if two bodies can proceed to have their bounding boxes checked -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
a - - -Body - - - -
b - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

draw()

- - - - - - -
- Renders a representation of a broadphase -
- - - - - - - - - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

getCollisionPairs(target) → {Array.<CollisionPair>}

- - - - - - -
- Gets all possibly colliding pairs. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
target - - -Array.<CollisionPair> - - - - Empty array to store results.
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Array.<CollisionPair> - - -
-
- - - - - - - - - - - - - -

insert(obj)

- - - - - - -
- Adds a body to the broadphase -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

query(bounds, target) → {Array.<Body>}

- - - - - - -
- Returns bodies that are within the given bound. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds - - -Bounds - - - - Region to check in.
target - - -Array.<Body> - - - - Empty array to store results.
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Array.<Body> - - -
-
- - - - - - - - - - - - - -

recalculateBounds()

- - - - - - -
- Resizes a quadtree to a new bound size. -This method should not be used without care. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds. - - -Bounds - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

remove(obj)

- - - - - - -
- Removes a body from the broadphase -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

traverse(func)

- - - - - - -
- A depth first search of the quadtree that applies the given function to its nodes. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
func - - -function - - - - The function that checks every node unless it returns true.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

update(bodies)

- - - - - - -
- Updates the internals of the broadphase if needed. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bodies - - -Array.<Body> - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - -
- -
- -

Tree(bounds, maxdepthopt)

- -
This is a bounded broadphase that is used to speed up collision testing on sparse number of objects over a large area.
- - -
- -
-
- - - - -

Constructor

- - - -

new Tree(bounds, maxdepthopt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
bounds - - -Bounds - - - - - - - - - - - - The region it operates on.
maxdepth - - -number - - - - - - <optional>
- - - - - -
- - 3 - - Maximum number of branches.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - -

Extends

- - - - - - - - - - - - - - - - - - - - - - -

Methods

- - - - - - - -

canCollide(a, b)

- - - - - - -
- Checks to see if two bodies can proceed to have their bounding boxes checked -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
a - - -Body - - - -
b - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

draw()

- - - - - - -
- Renders a representation of a broadphase -
- - - - - - - - - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

getCollisionPairs(target) → {Array.<CollisionPair>}

- - - - - - -
- Gets all possibly colliding pairs. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
target - - -Array.<CollisionPair> - - - - Empty array to store results.
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Array.<CollisionPair> - - -
-
- - - - - - - - - - - - - -

insert(obj)

- - - - - - -
- Adds a body to the broadphase -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

query(bounds, target) → {Array.<Body>}

- - - - - - -
- Returns bodies that are within the given bound. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds - - -Bounds - - - - Region to check in.
target - - -Array.<Body> - - - - Empty array to store results.
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Array.<Body> - - -
-
- - - - - - - - - - - - - -

recalculateBounds()

- - - - - - -
- Resizes a quadtree to a new bound size. -This method should not be used without care. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds. - - -Bounds - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

remove(obj)

- - - - - - -
- Removes a body from the broadphase -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

traverse(func)

- - - - - - -
- A depth first search of the quadtree that applies the given function to its nodes. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
func - - -function - - - - The function that checks every node unless it returns true.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

update(bodies)

- - - - - - -
- Updates the internals of the broadphase if needed. -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bodies - - -Array.<Body> - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
Vec2 Vec2 - - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) -
- - - - + + + + + JSDoc: Class: Tree + + + + + + + + + +
+ +

Class: Tree

+ + + + + + +
+ +
+ +

Tree()

+ +
This is an unbounded broadphase used to speed up collision testing. This can be used generally as it is faster than naive broadphase when a lot of objects are involved in the physics simulation.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Tree()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + + +

canCollide(a, b)

+ + + + + + +
+ Checks to see if two bodies can proceed to have their bounding boxes checked +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
a + + +Body + + + +
b + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

draw()

+ + + + + + +
+ Renders a representation of a broadphase +
+ + + + + + + + + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

getCollisionPairs(target) → {Array.<CollisionPair>}

+ + + + + + +
+ Gets all possibly colliding pairs. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Array.<CollisionPair> + + + + Empty array to store results.
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<CollisionPair> + + +
+
+ + + + + + + + + + + + + +

insert(obj)

+ + + + + + +
+ Adds a body to the broadphase +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

query(bounds, target) → {Array.<Body>}

+ + + + + + +
+ Returns bodies that are within the given bound. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds + + +Bounds + + + + Region to check in.
target + + +Array.<Body> + + + + Empty array to store results.
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<Body> + + +
+
+ + + + + + + + + + + + + +

recalculateBounds()

+ + + + + + +
+ Resizes a quadtree to a new bound size. This method should not be used without care. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds. + + +Bounds + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

remove(obj)

+ + + + + + +
+ Removes a body from the broadphase +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

traverse(func)

+ + + + + + +
+ A depth first search of the quadtree that applies the given function to its nodes. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + The function that checks every node unless it returns true.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

update(bodies)

+ + + + + + +
+ Updates the internals of the broadphase if needed. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bodies + + +Array.<Body> + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ +
+ +

Tree(bounds, maxdepthopt)

+ +
This is a bounded broadphase that is used to speed up collision testing on sparse number of objects over a large area.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Tree(bounds, maxdepthopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
bounds + + +Bounds + + + + + + + + + + + + The region it operates on.
maxdepth + + +number + + + + + + <optional>
+ + + + + +
+ + 3 + + Maximum number of branches.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + + +

canCollide(a, b)

+ + + + + + +
+ Checks to see if two bodies can proceed to have their bounding boxes checked +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
a + + +Body + + + +
b + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

draw()

+ + + + + + +
+ Renders a representation of a broadphase +
+ + + + + + + + + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

getCollisionPairs(target) → {Array.<CollisionPair>}

+ + + + + + +
+ Gets all possibly colliding pairs. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Array.<CollisionPair> + + + + Empty array to store results.
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<CollisionPair> + + +
+
+ + + + + + + + + + + + + +

insert(obj)

+ + + + + + +
+ Adds a body to the broadphase +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

query(bounds, target) → {Array.<Body>}

+ + + + + + +
+ Returns bodies that are within the given bound. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds + + +Bounds + + + + Region to check in.
target + + +Array.<Body> + + + + Empty array to store results.
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<Body> + + +
+
+ + + + + + + + + + + + + +

recalculateBounds()

+ + + + + + +
+ Resizes a quadtree to a new bound size. This method should not be used without care. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds. + + +Bounds + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

remove(obj)

+ + + + + + +
+ Removes a body from the broadphase +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

traverse(func)

+ + + + + + +
+ A depth first search of the quadtree that applies the given function to its nodes. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + The function that checks every node unless it returns true.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

update(bodies)

+ + + + + + +
+ Updates the internals of the broadphase if needed. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bodies + + +Array.<Body> + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time) +
+ + + + \ No newline at end of file diff --git a/docs/Triangle.html b/docs/Triangle.html index 9211ea64..20acb4a5 100644 --- a/docs/Triangle.html +++ b/docs/Triangle.html @@ -157,7 +157,7 @@
Parameters:
- Vec2 +Vector2 @@ -669,7 +669,7 @@
Type:
-

offPosition : Vec2

+

offPosition :Vector2

@@ -684,7 +684,7 @@
Type:

@@ -204,13 +202,13 @@

**** FUTURE WORK ****


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/inputs_input.js.html b/docs/inputs_input.js.html index 45d37d4b..7fcbdc7f 100644 --- a/docs/inputs_input.js.html +++ b/docs/inputs_input.js.html @@ -92,13 +92,13 @@

Source: inputs/input.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/inputs_keyboard.js.html b/docs/inputs_keyboard.js.html index 483362a5..b3dde71e 100644 --- a/docs/inputs_keyboard.js.html +++ b/docs/inputs_keyboard.js.html @@ -91,13 +91,13 @@

Source: inputs/keyboard.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/inputs_mouse.js.html b/docs/inputs_mouse.js.html index 96cad4e1..35f90c32 100644 --- a/docs/inputs_mouse.js.html +++ b/docs/inputs_mouse.js.html @@ -198,13 +198,13 @@

Source: inputs/mouse.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/inputs_touch.js.html b/docs/inputs_touch.js.html index db43c07d..a90c9c11 100644 --- a/docs/inputs_touch.js.html +++ b/docs/inputs_touch.js.html @@ -99,13 +99,13 @@

Source: inputs/touch.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/manager_boundsComponent.js.html b/docs/manager_boundsComponent.js.html index 63e5421b..1567d42a 100644 --- a/docs/manager_boundsComponent.js.html +++ b/docs/manager_boundsComponent.js.html @@ -62,7 +62,7 @@

Source: manager/boundsComponent.js


diff --git a/docs/manager_component.js.html b/docs/manager_component.js.html index b81e8b23..4a9a5711 100644 --- a/docs/manager_component.js.html +++ b/docs/manager_component.js.html @@ -141,7 +141,7 @@

Source: manager/component.js


diff --git a/docs/manager_entity.js.html b/docs/manager_entity.js.html index e144a64c..6db451fd 100644 --- a/docs/manager_entity.js.html +++ b/docs/manager_entity.js.html @@ -307,7 +307,7 @@

Source: manager/entity.js


diff --git a/docs/manager_manager.js.html b/docs/manager_manager.js.html index 325d3a8f..a91e31ea 100644 --- a/docs/manager_manager.js.html +++ b/docs/manager_manager.js.html @@ -604,7 +604,7 @@

Source: manager/manager.js


diff --git a/docs/manager_movableComponent.js.html b/docs/manager_movableComponent.js.html index b024251c..061dd542 100644 --- a/docs/manager_movableComponent.js.html +++ b/docs/manager_movableComponent.js.html @@ -24,7 +24,7 @@

Source: manager/movableComponent.js

import { Component } from "./component.js"
-import { Vec2, Angle } from "../math/index.js"
+import { Vector2, Angle } from "../math/index.js"
 /**
  * Component to hold requirements for an entity to move.
  * 
@@ -40,9 +40,9 @@ 

Source: manager/movableComponent.js

*/ constructor(x, y, a) { super() - this.velocity = new Vec2(x, y) + this.velocity = new Vector2(x, y) this.rotation = new Angle(a) - this.acceleration = new Vec2() + this.acceleration = new Vector2() } toJson() { return { @@ -69,7 +69,7 @@

Source: manager/movableComponent.js


diff --git a/docs/manager_system.js.html b/docs/manager_system.js.html index e0f199e3..fa574f61 100644 --- a/docs/manager_system.js.html +++ b/docs/manager_system.js.html @@ -68,7 +68,7 @@

Source: manager/system.js


diff --git a/docs/manager_transformComponent.js.html b/docs/manager_transformComponent.js.html index c845a5e3..92ea7e40 100644 --- a/docs/manager_transformComponent.js.html +++ b/docs/manager_transformComponent.js.html @@ -24,7 +24,7 @@

Source: manager/transformComponent.js

//import { Component } from "./component.js"
-import { Vec2, Angle } from "../math/index.js"
+import { Vector2, Angle } from "../math/index.js"
 
 /**
  * Holds transformation info of an entity 
@@ -40,7 +40,7 @@ 

Source: manager/transformComponent.js

* @returns */ constructor(x,y,a){ - this.position = new Vec2(x,y) + this.position = new Vector2(x,y) this.orientation = new Angle(a) } init(){} @@ -67,7 +67,7 @@

Source: manager/transformComponent.js


diff --git a/docs/math_angle.js.html b/docs/math_angle.js.html index 18c14d3b..d3b3b551 100644 --- a/docs/math_angle.js.html +++ b/docs/math_angle.js.html @@ -120,13 +120,13 @@

Source: math/angle.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/math_math.js.html b/docs/math_math.js.html index 926604c2..1714b4b1 100644 --- a/docs/math_math.js.html +++ b/docs/math_math.js.html @@ -171,13 +171,13 @@

Source: math/math.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/math_matrix.js.html b/docs/math_matrix.js.html index c44ee1dc..22a3e8d9 100644 --- a/docs/math_matrix.js.html +++ b/docs/math_matrix.js.html @@ -166,7 +166,7 @@

Source: math/matrix.js

/** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x @@ -248,13 +248,13 @@

Source: math/matrix.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/math_vector.js.html b/docs/math_vector.js.html index 2d945a13..5635c9bd 100644 --- a/docs/math_vector.js.html +++ b/docs/math_vector.js.html @@ -34,7 +34,7 @@

Source: math/vector.js

* @author Wayne Mwashuma <mwashumawayne@gmail.com> * @license MIT */ -class Vec2 { +export class Vector2 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -80,28 +80,28 @@

Source: math/vector.js

} /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj.x = this.x - v.x obj.y = this.y - v.y - return Math.sqrt( Vec2.prototype.magnitudeSquared.call(obj)) + return Math.sqrt( Vector2.prototype.magnitudeSquared.call(obj)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj.x = this.x - v.x obj.y = this.y - v.y - return Vec2.prototype.magnitudeSquared.call(obj) + return Vector2.prototype.magnitudeSquared.call(obj) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -124,7 +124,7 @@

Source: math/vector.js

/** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -146,7 +146,7 @@

Source: math/vector.js

/** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -155,7 +155,7 @@

Source: math/vector.js

/** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -199,7 +199,7 @@

Source: math/vector.js

* Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -217,21 +217,21 @@

Source: math/vector.js

* Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2() + target = target || new Vector2() target.copy(this).normalize() return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2()) { + normalFast(target = new Vector2()) { return target.set(-this.y, this.x) } /** @@ -268,16 +268,16 @@

Source: math/vector.js

* Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2(this.x, this.y) + return new Vector2(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -333,10 +333,10 @@

Source: math/vector.js

* Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2()) { + reflect(normal, target = new Vector2()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -374,33 +374,33 @@

Source: math/vector.js

* Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2) - let deg = Vec2.getDegBtwn(v1, v2) + let deg = Vector2.getDegBtwn(v1, v2) return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2) - let deg = Vec2.getDegBtwn(v1, v2) + let deg = Vector2.getDegBtwn(v1, v2) return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -410,22 +410,22 @@

Source: math/vector.js

* Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2()) { + static fromRad(radian, target = new Vector2()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -433,32 +433,32 @@

Source: math/vector.js

* given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2.fromRad(degree * Math.PI / 180, target) + return Vector2.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2.fromRad(Math.random() * TWO_PI, target) + return Vector2.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2()) { - target = target || new Vec2() + static lerp(v1, v2, t, target = new Vector2()) { + target = target || new Vector2() return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -468,17 +468,17 @@

Source: math/vector.js

/** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2.toRad(v) / Math.PI * 180 + return Vector2.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -491,14 +491,26 @@

Source: math/vector.js

* * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2()) + static ZERO = Object.freeze(new Vector2()) } - +class Vector extends Vector2{ + constructor(x,y){ + super(x,y) + console.error("The class `Vector` is depreciated since v0.4.13.Use Vector2 instead.") + } +} +class Vec2 extends Vector2{ + constructor(x,y){ + super(x,y) + console.error("The class `Vec2` is depreciated since v0.4.13.Use Vector2 instead.") + } +} export { - Vec2 + Vec2, + Vector }
@@ -509,13 +521,13 @@

Source: math/vector.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/module-Cookie.html b/docs/module-Cookie.html index f41122e0..0edf9089 100644 --- a/docs/module-Cookie.html +++ b/docs/module-Cookie.html @@ -111,13 +111,13 @@

Module: Cookie


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/module-Session.html b/docs/module-Session.html index e2ff5bb0..47a1837a 100644 --- a/docs/module-Session.html +++ b/docs/module-Session.html @@ -111,13 +111,13 @@

Module: Session


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/module-Utils.html b/docs/module-Utils.html index 2d162e8e..45054ad3 100644 --- a/docs/module-Utils.html +++ b/docs/module-Utils.html @@ -111,13 +111,13 @@

Module: Utils


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_AABB_boundingBox.js.html b/docs/physics_AABB_boundingBox.js.html index 4b136d3f..4e8d8728 100644 --- a/docs/physics_AABB_boundingBox.js.html +++ b/docs/physics_AABB_boundingBox.js.html @@ -24,7 +24,7 @@

Source: physics/AABB/boundingBox.js

import { Overlaps } from "./overlap.js"
-import { Component } from "../../manager/component.js"
+import { Component } from "../../ecs/component.js"
 
 /**
  * A rectangular bound that is used to contain a body so that broadphase can be used for quick collision detection.
@@ -131,7 +131,7 @@ 

Source: physics/AABB/boundingBox.js

/** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x @@ -210,13 +210,13 @@

Source: physics/AABB/boundingBox.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_AABB_boundingSphere.js.html b/docs/physics_AABB_boundingSphere.js.html index 9026069d..c606af15 100644 --- a/docs/physics_AABB_boundingSphere.js.html +++ b/docs/physics_AABB_boundingSphere.js.html @@ -121,13 +121,13 @@

Source: physics/AABB/boundingSphere.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_AABB_overlap.js.html b/docs/physics_AABB_overlap.js.html index cc5d5d3d..8c625ba5 100644 --- a/docs/physics_AABB_overlap.js.html +++ b/docs/physics_AABB_overlap.js.html @@ -65,7 +65,7 @@

Source: physics/AABB/overlap.js

(x - b.pos.x) * (x - b.pos.x) + (y - b.pos.y) * (y - b.pos.y) - return distance < b.r; + return distance < b.r * b.r; } }
@@ -77,13 +77,13 @@

Source: physics/AABB/overlap.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_SAT_index.js.html b/docs/physics_SAT_index.js.html index cc14f151..b7c71daa 100644 --- a/docs/physics_SAT_index.js.html +++ b/docs/physics_SAT_index.js.html @@ -23,7 +23,7 @@

Source: physics/SAT/index.js

-
import { Vec2 } from "../../math/index.js"
+            
import { Vector2 } from "../../math/index.js"
 import { Utils } from "../../utils/index.js"
 
 const _arr = [],
@@ -31,7 +31,7 @@ 

Source: physics/SAT/index.js

overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2(), + axis: new Vector2(), vertex: null, shape: null }, @@ -45,9 +45,9 @@

Source: physics/SAT/index.js

max: 0, indexN: 0 }, - tmp4 = new Vec2(), - tmp5 = new Vec2(), - tmp6 = new Vec2() + tmp4 = new Vector2(), + tmp5 = new Vector2(), + tmp6 = new Vector2() /** * Used for narrowphase collision detection and contact info generation. @@ -134,7 +134,7 @@

Source: physics/SAT/index.js

/** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -194,8 +194,8 @@

Source: physics/SAT/index.js

return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -220,9 +220,9 @@

Source: physics/SAT/index.js

return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -250,7 +250,7 @@

Source: physics/SAT/index.js

}, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -258,9 +258,9 @@

Source: physics/SAT/index.js

return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -270,7 +270,7 @@

Source: physics/SAT/index.js

return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { @@ -301,13 +301,13 @@

Source: physics/SAT/index.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_bodies_ball.js.html b/docs/physics_bodies_ball.js.html index aa3e5317..5ce15c8d 100644 --- a/docs/physics_bodies_ball.js.html +++ b/docs/physics_bodies_ball.js.html @@ -66,13 +66,13 @@

Source: physics/bodies/ball.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_bodies_body.js.html b/docs/physics_bodies_body.js.html index b92c58cc..f3077592 100644 --- a/docs/physics_bodies_body.js.html +++ b/docs/physics_bodies_body.js.html @@ -23,8 +23,9 @@

Source: physics/bodies/body.js

-
import { Vec2, Angle } from "../../math/index.js"
-import { Utils } from "../../utils/index.js"
+            
import { Vector2, Angle } from "../../math/index.js"
+import { Component } from "../../ecs/index.js"
+import {Utils} from "../../utils/index.js"
 import { BoundingBox } from "../AABB/index.js"
 import { ObjType, Settings } from "../settings.js"
 import { Shape } from "../shapes/index.js"
@@ -45,23 +46,23 @@ 

Source: physics/bodies/body.js

* World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2() + _position = new Vector2() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2() + _velocity = new Vector2() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2() + _acceleration = new Vector2() /** * World space orientation of a body * @@ -109,22 +110,22 @@

Source: physics/bodies/body.js

* Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2() + lastPosition = new Vector2() /** * Inverse mass of the body. * @@ -295,7 +296,7 @@

Source: physics/bodies/body.js

/** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -306,7 +307,7 @@

Source: physics/bodies/body.js

/** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -383,7 +384,7 @@

Source: physics/bodies/body.js

/** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -438,11 +439,11 @@

Source: physics/bodies/body.js

/** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2(v.x, v.y).rotate(this.orientation.radian).add(this.position)) + this.anchors.push(new Vector2(v.x, v.y).rotate(this.orientation.radian).add(this.position)) return this._localanchors.push(v) - 1 } /** @@ -450,7 +451,7 @@

Source: physics/bodies/body.js

* Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -459,20 +460,20 @@

Source: physics/bodies/body.js

* Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2()) { + getLocalAnchor(index, target = new Vector2()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2.ZERO) { + applyForce(force, arm = Vector2.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)) this.rotation.degree += arm.cross(force) * this.inv_inertia } @@ -572,7 +573,7 @@

Source: physics/bodies/body.js

body.id = obj.id body.mask = obj.mask obj.anchors.forEach((v) => { - body.setAnchor(new Vec2().fromJson(v)) + body.setAnchor(new Vector2().fromJson(v)) }) } /** @@ -596,7 +597,7 @@

Source: physics/bodies/body.js

*/ static DYNAMIC = ObjType.DYNAMIC } -Utils.inheritComponent(Body, false, false) +Component.implement(Body) export { Body }
@@ -609,13 +610,13 @@

Source: physics/bodies/body.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_bodies_box.js.html b/docs/physics_bodies_box.js.html index e48e32bc..07c197b2 100644 --- a/docs/physics_bodies_box.js.html +++ b/docs/physics_bodies_box.js.html @@ -67,13 +67,13 @@

Source: physics/bodies/box.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_bodies_composite.js.html b/docs/physics_bodies_composite.js.html index 241afd8e..61c2ac2b 100644 --- a/docs/physics_bodies_composite.js.html +++ b/docs/physics_bodies_composite.js.html @@ -23,8 +23,8 @@

Source: physics/bodies/composite.js

-
import { Vec2 } from "../../math/index.js"
-import { Utils } from "../../utils/index.js"
+            
import { Vector2 } from "../../math/index.js"
+import { Component } from "../../ecs/index.js"
 import { ObjType } from "../settings.js"
 
 /**
@@ -89,10 +89,10 @@ 

Source: physics/bodies/composite.js

/** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2() + let acceleration = new Vector2() for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration) } @@ -106,10 +106,10 @@

Source: physics/bodies/composite.js

/** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2() + let velocity = new Vector2() for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity) @@ -184,11 +184,11 @@

Source: physics/bodies/composite.js

/** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2() - for (var i = 0; i < this.shapes.length; i++) { + let position = new Vector2() + for (var i = 0; i < this.bodies.length; i++) { position.add(this.bodies[i].position) } return position @@ -234,7 +234,7 @@

Source: physics/bodies/composite.js

} } } -Utils.inheritComponent(Composite) +Component.implement(Composite) export { Composite }
@@ -247,13 +247,13 @@

Source: physics/bodies/composite.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_bodies_trigon.js.html b/docs/physics_bodies_trigon.js.html index 01284006..77769cca 100644 --- a/docs/physics_bodies_trigon.js.html +++ b/docs/physics_bodies_trigon.js.html @@ -62,13 +62,13 @@

Source: physics/bodies/trigon.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_broadphases_AABBTree.js.html b/docs/physics_broadphases_AABBTree.js.html index 7741a0cf..c937e234 100644 --- a/docs/physics_broadphases_AABBTree.js.html +++ b/docs/physics_broadphases_AABBTree.js.html @@ -49,13 +49,13 @@

Source: physics/broadphases/AABBTree.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_broadphases_Naive.js.html b/docs/physics_broadphases_Naive.js.html index db9dc026..d1c35443 100644 --- a/docs/physics_broadphases_Naive.js.html +++ b/docs/physics_broadphases_Naive.js.html @@ -98,13 +98,13 @@

Source: physics/broadphases/Naive.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_broadphases_Quadtree.js.html b/docs/physics_broadphases_Quadtree.js.html index 5b74750d..a87ccac8 100644 --- a/docs/physics_broadphases_Quadtree.js.html +++ b/docs/physics_broadphases_Quadtree.js.html @@ -512,13 +512,13 @@

Source: physics/broadphases/Quadtree.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_broadphases_SpartialHash.js.html b/docs/physics_broadphases_SpartialHash.js.html index 0ea9e310..fffd7a78 100644 --- a/docs/physics_broadphases_SpartialHash.js.html +++ b/docs/physics_broadphases_SpartialHash.js.html @@ -196,13 +196,13 @@

Source: physics/broadphases/SpartialHash.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_broadphases_broadphase.js.html b/docs/physics_broadphases_broadphase.js.html index 97e86565..3e8f0ee3 100644 --- a/docs/physics_broadphases_broadphase.js.html +++ b/docs/physics_broadphases_broadphase.js.html @@ -104,13 +104,13 @@

Source: physics/broadphases/broadphase.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_constraints_constraint.js.html b/docs/physics_constraints_constraint.js.html index afa7e8e6..6763ff10 100644 --- a/docs/physics_constraints_constraint.js.html +++ b/docs/physics_constraints_constraint.js.html @@ -24,7 +24,7 @@

Source: physics/constraints/constraint.js

import { ObjType } from "../settings.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 /**
  * Base class for constructing different types of constraints.
@@ -37,14 +37,14 @@ 

Source: physics/constraints/constraint.js

/** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1 this.body2 = body2 - this.localA = localA || new Vec2() - this.localB = localB || new Vec2() + this.localA = localA || new Vector2() + this.localB = localB || new Vector2() this.stiffness = 50 this.dampening = 0.03 } @@ -106,8 +106,8 @@

Source: physics/constraints/constraint.js

let constraint = new Constraint( bod1, bod2, - new Vec2().fromJson(obj.localA), - new Vec2().fromJson(obj.localB) + new Vector2().fromJson(obj.localA), + new Vector2().fromJson(obj.localB) ) constraint.stiffness = obj.stiffness constraint.dampening = obj.dampening @@ -126,13 +126,13 @@

Source: physics/constraints/constraint.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_constraints_distanceConstraint.js.html b/docs/physics_constraints_distanceConstraint.js.html index 031d145b..907b04f1 100644 --- a/docs/physics_constraints_distanceConstraint.js.html +++ b/docs/physics_constraints_distanceConstraint.js.html @@ -24,13 +24,13 @@

Source: physics/constraints/distanceConstraint.js

import { Constraint } from "./constraint.js";
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2(),
-  tmp3 = new Vec2(),
-  tmp4 = new Vec2(),
-  tmp5 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2(),
+  tmp3 = new Vector2(),
+  tmp4 = new Vector2(),
+  tmp5 = new Vector2()
 
 /**
  * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint.
@@ -39,8 +39,8 @@ 

Source: physics/constraints/distanceConstraint.js

/** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB) @@ -96,13 +96,13 @@

Source: physics/constraints/distanceConstraint.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_constraints_springConstraint.js.html b/docs/physics_constraints_springConstraint.js.html index b7569a2d..4421ca9c 100644 --- a/docs/physics_constraints_springConstraint.js.html +++ b/docs/physics_constraints_springConstraint.js.html @@ -24,14 +24,14 @@

Source: physics/constraints/springConstraint.js

import { Constraint } from "./constraint.js";
-import { Vec2 } from "../../math/index.js"
-
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2(),
-  tmp3 = new Vec2(),
-  tmp4 = new Vec2(),
-  tmp5 = new Vec2(),
-  zero = new Vec2()
+import { Vector2 } from "../../math/index.js"
+
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2(),
+  tmp3 = new Vector2(),
+  tmp4 = new Vector2(),
+  tmp5 = new Vector2(),
+  zero = new Vector2()
  /**
   * A constraint that acts like a spring between two bodies
  */
@@ -39,13 +39,13 @@ 

Source: physics/constraints/springConstraint.js

/** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2) - this.localA = new Vec2().copy(localA || zero) - this.localB = new Vec2().copy(localB || zero) + this.localA = new Vector2().copy(localA || zero) + this.localB = new Vector2().copy(localB || zero) this.fixed = !body1.mass || !body2.mass this.dampening = 1 this.maxDistance = 100 @@ -93,13 +93,13 @@

Source: physics/constraints/springConstraint.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_integrators_euler.js.html b/docs/physics_integrators_euler.js.html index 492359e3..417b339a 100644 --- a/docs/physics_integrators_euler.js.html +++ b/docs/physics_integrators_euler.js.html @@ -23,9 +23,9 @@

Source: physics/integrators/euler.js

-
import { Vec2 }from "../../math/index.js"
+            
import { Vector2 }from "../../math/index.js"
 
-let a = new Vec2()
+let a = new Vector2()
 
 /**
  * Semi implicit euler integration.
@@ -57,13 +57,13 @@ 

Source: physics/integrators/euler.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_integrators_rungeKutter.js.html b/docs/physics_integrators_rungeKutter.js.html index 224adc80..16e2ffdf 100644 --- a/docs/physics_integrators_rungeKutter.js.html +++ b/docs/physics_integrators_rungeKutter.js.html @@ -23,9 +23,9 @@

Source: physics/integrators/rungeKutter.js

-
import { Vec2 }from "../../math/index.js"
+            
import { Vector2 }from "../../math/index.js"
 
-let a = new Vec2()
+let a = new Vector2()
 
 /**
  * Runge Kutta 4 (RK-4) 
@@ -55,13 +55,13 @@ 

Source: physics/integrators/rungeKutter.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_integrators_verlet.js.html b/docs/physics_integrators_verlet.js.html index 75924263..42d20d87 100644 --- a/docs/physics_integrators_verlet.js.html +++ b/docs/physics_integrators_verlet.js.html @@ -23,10 +23,10 @@

Source: physics/integrators/verlet.js

-
import { Vec2 } from "../../math/index.js"
-let position = new Vec2()
-let acceleration = new Vec2()
-let velocity = new Vec2()
+            
import { Vector2 } from "../../math/index.js"
+let position = new Vector2()
+let acceleration = new Vector2()
+let velocity = new Vector2()
 
 /**
  * Verlet intergration.
@@ -63,13 +63,13 @@ 

Source: physics/integrators/verlet.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_narrowphase_SATNarrowphase.js.html b/docs/physics_narrowphase_SATNarrowphase.js.html index 56d9d566..78c65417 100644 --- a/docs/physics_narrowphase_SATNarrowphase.js.html +++ b/docs/physics_narrowphase_SATNarrowphase.js.html @@ -23,7 +23,7 @@

Source: physics/narrowphase/SATNarrowphase.js

-
import { Vec2, naturalizePair } from "../../math/index.js"
+            
import { Vector2, naturalizePair } from "../../math/index.js"
 import { SAT } from "../SAT/index.js";
 import { NarrowPhase } from "./Narrowphase.js"
 
@@ -51,7 +51,7 @@ 

Source: physics/narrowphase/SATNarrowphase.js

lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2(), + axis: new Vector2(), verticesA: [], verticesB: [], vertShapeA: null, @@ -64,13 +64,13 @@

Source: physics/narrowphase/SATNarrowphase.js

stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2(), - ca2: new Vec2(), + ca1: new Vector2(), + ca2: new Vector2(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2(), - velB: new Vec2(), + velA: new Vector2(), + velB: new Vector2(), rotA: 0, rotB: 0 }) @@ -81,13 +81,13 @@

Source: physics/narrowphase/SATNarrowphase.js

SAT.shapesInBodyCollided(a, b, collisionData) if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2.lerp( + Vector2.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position) - Vec2.lerp( + Vector2.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -115,13 +115,13 @@

Source: physics/narrowphase/SATNarrowphase.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_settings.js.html b/docs/physics_settings.js.html index dccda4f2..4ab761b5 100644 --- a/docs/physics_settings.js.html +++ b/docs/physics_settings.js.html @@ -71,13 +71,13 @@

Source: physics/settings.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_circle.js.html b/docs/physics_shapes_circle.js.html index bb121d96..766deeb1 100644 --- a/docs/physics_shapes_circle.js.html +++ b/docs/physics_shapes_circle.js.html @@ -24,10 +24,10 @@

Source: physics/shapes/circle.js

import { Shape } from "./shape.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
-let _vec1 = new Vec2()
-let _vec2 = new Vec2()
+let _vec1 = new Vector2()
+let _vec2 = new Vector2()
 let _arr = []
 
 /**
@@ -41,14 +41,14 @@ 

Source: physics/shapes/circle.js

radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle) - this.vertices = [new Vec2(), new Vec2(), new Vec2()] + this.vertices = [new Vector2(), new Vector2(), new Vector2()] this.radius = radius this.type = Shape.CIRCLE } @@ -66,9 +66,9 @@

Source: physics/shapes/circle.js

/** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || [] @@ -81,8 +81,8 @@

Source: physics/shapes/circle.js

/** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -101,7 +101,7 @@

Source: physics/shapes/circle.js

/** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -125,7 +125,7 @@

Source: physics/shapes/circle.js

fromJson(obj) { return new Circle( obj.radius, - new Vec2().fromJson(obj.offset), + new Vector2().fromJson(obj.offset), obj.offAngle ) } @@ -143,13 +143,13 @@

Source: physics/shapes/circle.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_geometry.js.html b/docs/physics_shapes_geometry.js.html index aaea6917..3906ceea 100644 --- a/docs/physics_shapes_geometry.js.html +++ b/docs/physics_shapes_geometry.js.html @@ -25,19 +25,19 @@

Source: physics/shapes/geometry.js

class Geometry {
   /**
-   * @type Vec2[]
+   * @type Vector2[]
    */
   vertices = null
   /**
-   * @type Vec2[]
+   * @type Vector2[]
    */
   normals = null
   /**
-   * @type Vec2[]
+   * @type Vector2[]
    */
   _dynNormals = null
   /**
-   * @param { Vec2[]} vertices
+   * @param { Vector2[]} vertices
    */
   constructor(vertices) {
     this.vertices = vertices
@@ -58,7 +58,7 @@ 

Source: physics/shapes/geometry.js

} /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || [] @@ -69,7 +69,7 @@

Source: physics/shapes/geometry.js

} /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -91,8 +91,8 @@

Source: physics/shapes/geometry.js

} /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -111,7 +111,7 @@

Source: physics/shapes/geometry.js

return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)) + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)) this.normals = this.calcFaceNormals() this._dynNormals = this.normals.map(e => e.clone()) } @@ -129,13 +129,13 @@

Source: physics/shapes/geometry.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_line.js.html b/docs/physics_shapes_line.js.html index 0447c09a..b1c0d541 100644 --- a/docs/physics_shapes_line.js.html +++ b/docs/physics_shapes_line.js.html @@ -24,7 +24,7 @@

Source: physics/shapes/line.js

import { Shape } from "./shape.js"
-import { Vec2 }from "../../math/index.js"
+import { Vector2 }from "../../math/index.js"
 
 class Line extends Shape {
   /**
@@ -33,12 +33,12 @@ 

Source: physics/shapes/line.js

length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2(1).multiply(length / 2), - end = new Vec2(1).multiply(-length / 2) + let start = new Vector2(1).multiply(length / 2), + end = new Vector2(1).multiply(-length / 2) super([start, end],offset,offsetAngle) this.length = length } @@ -56,13 +56,13 @@

Source: physics/shapes/line.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_rectangle.js.html b/docs/physics_shapes_rectangle.js.html index 8251d016..90c73597 100644 --- a/docs/physics_shapes_rectangle.js.html +++ b/docs/physics_shapes_rectangle.js.html @@ -24,7 +24,7 @@

Source: physics/shapes/rectangle.js

import { Shape } from "./shape.js"
-import { Vec2, sq }from "../../math/index.js"
+import { Vector2, sq }from "../../math/index.js"
 
 class Rectangle extends Shape {
   /**
@@ -38,14 +38,14 @@ 

Source: physics/shapes/rectangle.js

/** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2(-width / 2, -height / 2) - let v2 = new Vec2(-width / 2, height / 2) - let v3 = new Vec2(width / 2, height / 2) - let v4 = new Vec2(width / 2, -height / 2) + let v1 = new Vector2(-width / 2, -height / 2) + let v2 = new Vector2(-width / 2, height / 2) + let v3 = new Vector2(width / 2, height / 2) + let v4 = new Vector2(width / 2, -height / 2) super([v1, v2, v3, v4], offset, offsetAngle) this.height = height this.width = width @@ -78,13 +78,13 @@

Source: physics/shapes/rectangle.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_shape.js.html b/docs/physics_shapes_shape.js.html index 922c2e7c..59a7d874 100644 --- a/docs/physics_shapes_shape.js.html +++ b/docs/physics_shapes_shape.js.html @@ -23,11 +23,11 @@

Source: physics/shapes/shape.js

-
import { Vec2 } from "../../math/index.js"
+            
import { Vector2 } from "../../math/index.js"
 import { Geometry } from "./geometry.js"
 import { ShapeType } from "../settings.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
 
 /**
  * This class makes a body tangible
@@ -50,13 +50,13 @@ 

Source: physics/shapes/shape.js

/** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -67,11 +67,11 @@

Source: physics/shapes/shape.js

geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2(), offsetAngle = 0) { this.offPosition = offset this.offAngle = offsetAngle * Math.PI / 180 this.vertices = vertices.map(v => v.clone()) @@ -100,8 +100,8 @@

Source: physics/shapes/shape.js

* Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -109,7 +109,7 @@

Source: physics/shapes/shape.js

/** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -121,9 +121,9 @@

Source: physics/shapes/shape.js

/** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices @@ -170,13 +170,13 @@

Source: physics/shapes/shape.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_shapes_triangle.js.html b/docs/physics_shapes_triangle.js.html index 845a73dc..f85263f8 100644 --- a/docs/physics_shapes_triangle.js.html +++ b/docs/physics_shapes_triangle.js.html @@ -24,9 +24,9 @@

Source: physics/shapes/triangle.js

import { Shape } from "./shape.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
-let tmp1 = new Vec2()
+let tmp1 = new Vector2()
 
 /**
  * A triangular shape.
@@ -38,16 +38,16 @@ 

Source: physics/shapes/triangle.js

* @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2().set(1, 0).multiply(base) - let l2 = Vec2.fromRad(angle).multiply(height/Math.sin(angle)) + let l1 = new Vector2().set(1, 0).multiply(base) + let l2 = Vector2.fromRad(angle).multiply(height/Math.sin(angle)) let center = tmp1.set((l1.x + l2.x) / 3, l2.y / 3) super([ - new Vec2().sub(center), + new Vector2().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle) @@ -69,13 +69,13 @@

Source: physics/shapes/triangle.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_solvers_contactSolver.js.html b/docs/physics_solvers_contactSolver.js.html index 230ea6be..89811926 100644 --- a/docs/physics_solvers_contactSolver.js.html +++ b/docs/physics_solvers_contactSolver.js.html @@ -60,13 +60,13 @@

Source: physics/solvers/contactSolver.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_solvers_frictionSolver.js.html b/docs/physics_solvers_frictionSolver.js.html index 83ed019d..84824b79 100644 --- a/docs/physics_solvers_frictionSolver.js.html +++ b/docs/physics_solvers_frictionSolver.js.html @@ -23,13 +23,13 @@

Source: physics/solvers/frictionSolver.js

-
import { Vec2, sq }from "../../math/index.js"
+            
import { Vector2, sq }from "../../math/index.js"
 
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2(),
-  tmp3 = new Vec2(),
-  tmp4 = new Vec2(),
-  tmp5 = new Vec2()
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2(),
+  tmp3 = new Vector2(),
+  tmp4 = new Vector2(),
+  tmp5 = new Vector2()
 
 /**
  * Solves for impulse along collision tangent for a given body pair.
@@ -84,13 +84,13 @@ 

Source: physics/solvers/frictionSolver.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_solvers_impulseSolver.js.html b/docs/physics_solvers_impulseSolver.js.html index e509e917..c87b5b12 100644 --- a/docs/physics_solvers_impulseSolver.js.html +++ b/docs/physics_solvers_impulseSolver.js.html @@ -23,11 +23,11 @@

Source: physics/solvers/impulseSolver.js

-
import { Vec2, sq }from "../../math/index.js"
-let tmp1 = new Vec2(),
-  tmp2 = new Vec2(),
-  tmp3 = new Vec2(),
-  tmp4 = new Vec2()
+            
import { Vector2, sq }from "../../math/index.js"
+let tmp1 = new Vector2(),
+  tmp2 = new Vector2(),
+  tmp3 = new Vector2(),
+  tmp4 = new Vector2()
 
 /**
  * Solves for the collision normal impulse of a given body pair.
@@ -76,13 +76,13 @@ 

Source: physics/solvers/impulseSolver.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_solvers_penetrationSolver.js.html b/docs/physics_solvers_penetrationSolver.js.html index d898d807..73c5d3b4 100644 --- a/docs/physics_solvers_penetrationSolver.js.html +++ b/docs/physics_solvers_penetrationSolver.js.html @@ -23,10 +23,10 @@

Source: physics/solvers/penetrationSolver.js

-
import { Vec2, sq }from "../../math/index.js"
+            
import { Vector2, sq }from "../../math/index.js"
 import { Settings } from "../settings.js"
-const tmp1 = new Vec2(),
-  tmp2 = new Vec2()
+const tmp1 = new Vector2(),
+  tmp2 = new Vector2()
 let dampen = Settings.posDampen
 
 /**
@@ -56,13 +56,13 @@ 

Source: physics/solvers/penetrationSolver.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/physics_world_index.js.html b/docs/physics_world_index.js.html index 8b940beb..d61b150d 100644 --- a/docs/physics_world_index.js.html +++ b/docs/physics_world_index.js.html @@ -25,7 +25,7 @@

Source: physics/world/index.js

import { VerletSolver } from "../integrators/index.js";
 import { PenetrationSolver, FrictionSolver, ImpulseSolver, ContactSolver } from "../solvers/index.js";
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 import { Utils } from "../../utils/index.js"
 import { ObjType } from "../settings.js"
 import { NaiveBroadphase } from "../broadphases/index.js"
@@ -35,7 +35,7 @@ 

Source: physics/world/index.js

/** * Class responsible for updating bodies,constraints and composites. */ -class World { +export class World { /** * Used to check if a manifold is persistent. * @@ -106,9 +106,9 @@

Source: physics/world/index.js

/** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2(0, 0) + gravitationalAcceleration = new Vector2(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -137,6 +137,12 @@

Source: physics/world/index.js

* @type NarrowPhase */ narrowphase = null + /** + * Moves the bodies forward in time. + * + * @type {Intergrator} + */ + intergrator = VerletSolver /** * @constructor World * @@ -155,7 +161,7 @@

Source: physics/world/index.js

/** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration @@ -233,7 +239,8 @@

Source: physics/world/index.js

for (var i = 0; i < length; i++) { let a = this.objects[i] if (!a.sleeping) - VerletSolver.solve(a, dt) + this.intergrator.solve(a, dt) + //VerletSolver.solve(a, dt) } } /** @@ -426,10 +433,6 @@

Source: physics/world/index.js

this.broadphase.query(bound, target) return target } -} - -export { - World }
@@ -440,13 +443,13 @@

Source: physics/world/index.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_camController.js.html b/docs/render_camController.js.html index dd9cb0c0..f706ae61 100644 --- a/docs/render_camController.js.html +++ b/docs/render_camController.js.html @@ -23,25 +23,25 @@

Source: render/camController.js

-
import { Vec2 } from '../math/index.js'
+            
import { Vector2 } from '../math/index.js'
 
 export class CamController {
   /**
    * @readonly
-   * @type Vec2
+   * @type Vector2
    */
-  offset = new Vec2()
+  offset = new Vector2()
   /**
    * @param {Camera} camera
    */
   constructor(camera) {
     this.transform = camera.transform
-    this.offset = new Vec2()
+    this.offset = new Vector2()
     this.targetPosition = null
     this.targetOrientation = null
   }
   /**
-   * @param { Vec2} position
+   * @param { Vector2} position
    * @param {Angle} orientation
    */
   follow(position, orientation = null) {
@@ -80,13 +80,13 @@ 

Source: render/camController.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_camera.js.html b/docs/render_camera.js.html index 29dbd930..00bcc714 100644 --- a/docs/render_camera.js.html +++ b/docs/render_camera.js.html @@ -23,7 +23,7 @@

Source: render/camera.js

-
import {Transform} from '../manager/transformComponent.js'
+            
import {Transform} from '../ecs/transformComponent.js'
 class Camera {
   /**
    * @readonly
@@ -33,7 +33,7 @@ 

Source: render/camera.js

constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position @@ -55,13 +55,13 @@

Source: render/camera.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_geometry_circlegeometry.js.html b/docs/render_geometry_circlegeometry.js.html index 9a9e3fe2..fc2a0985 100644 --- a/docs/render_geometry_circlegeometry.js.html +++ b/docs/render_geometry_circlegeometry.js.html @@ -56,13 +56,13 @@

Source: render/geometry/circlegeometry.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_geometry_geometry.js.html b/docs/render_geometry_geometry.js.html index d9e054f7..d3911cbb 100644 --- a/docs/render_geometry_geometry.js.html +++ b/docs/render_geometry_geometry.js.html @@ -23,13 +23,13 @@

Source: render/geometry/geometry.js

-
import { Vec2 } from "../../math/index.js"
+            
import { Vector2 } from "../../math/index.js"
 import { vertices } from "../utils/index.js"
 
 export class BufferGeometry {
   /**
    * @readonly
-   * @type Vec2[]
+   * @type Vector2[]
    */
   vertices = null
   /**
@@ -38,7 +38,7 @@ 

Source: render/geometry/geometry.js

*/ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || [] @@ -61,13 +61,13 @@

Source: render/geometry/geometry.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_material_BasicMaterial.js.html b/docs/render_material_BasicMaterial.js.html index 5f082b18..c130b0e4 100644 --- a/docs/render_material_BasicMaterial.js.html +++ b/docs/render_material_BasicMaterial.js.html @@ -69,13 +69,13 @@

Source: render/material/BasicMaterial.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_material_SpriteMaterial.js.html b/docs/render_material_SpriteMaterial.js.html index 29c967f7..0ac8aa28 100644 --- a/docs/render_material_SpriteMaterial.js.html +++ b/docs/render_material_SpriteMaterial.js.html @@ -172,13 +172,13 @@

Source: render/material/SpriteMaterial.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_material_StaticImageMaterial.js.html b/docs/render_material_StaticImageMaterial.js.html index 71dc6a6d..7e3fd48d 100644 --- a/docs/render_material_StaticImageMaterial.js.html +++ b/docs/render_material_StaticImageMaterial.js.html @@ -74,13 +74,13 @@

Source: render/material/StaticImageMaterial.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_material_material.js.html b/docs/render_material_material.js.html index a226bfa0..9b8f72f1 100644 --- a/docs/render_material_material.js.html +++ b/docs/render_material_material.js.html @@ -46,13 +46,13 @@

Source: render/material/material.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_renderers_canvas.js.html b/docs/render_renderers_canvas.js.html index fcb0ba71..82d10018 100644 --- a/docs/render_renderers_canvas.js.html +++ b/docs/render_renderers_canvas.js.html @@ -111,13 +111,13 @@

Source: render/renderers/canvas.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_renderers_renderer.js.html b/docs/render_renderers_renderer.js.html index 09e41e04..57a319f7 100644 --- a/docs/render_renderers_renderer.js.html +++ b/docs/render_renderers_renderer.js.html @@ -169,8 +169,8 @@

Source: render/renderers/renderer.js

let canvas = this.domElement canvas.style.width = w + "px" canvas.style.height = h + "px" - canvas.width = w - canvas.height = h + canvas.width = w * devicePixelRatio + canvas.height = h * devicePixelRatio } /** * Width of the renderer @@ -204,13 +204,13 @@

Source: render/renderers/renderer.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_renderers_webgpurenderer.js.html b/docs/render_renderers_webgpurenderer.js.html index 4d9d26f6..5ab167ee 100644 --- a/docs/render_renderers_webgpurenderer.js.html +++ b/docs/render_renderers_webgpurenderer.js.html @@ -47,13 +47,13 @@

Source: render/renderers/webgpurenderer.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_renderers_weglrenderer.js.html b/docs/render_renderers_weglrenderer.js.html index 729db2e2..1f170123 100644 --- a/docs/render_renderers_weglrenderer.js.html +++ b/docs/render_renderers_weglrenderer.js.html @@ -44,13 +44,13 @@

Source: render/renderers/weglrenderer.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_AgentSprite.js.html b/docs/render_sprites_AgentSprite.js.html index 4ac31375..32decfe6 100644 --- a/docs/render_sprites_AgentSprite.js.html +++ b/docs/render_sprites_AgentSprite.js.html @@ -26,12 +26,12 @@

Source: render/sprites/AgentSprite.js

import { Sprite } from "./sprite.js"
 import { BufferGeometry } from "../geometry/index.js"
 import { BasicMaterial } from "../material/index.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 
 let geometry = new BufferGeometry([
-  new Vec2(-10, -10),
-  new Vec2(-10, 10),
-  new Vec2(20, 0)
+  new Vector2(-10, -10),
+  new Vector2(-10, 10),
+  new Vector2(20, 0)
   ])
 let material = new BasicMaterial()
 material.fill = "purple"
@@ -76,13 +76,13 @@ 

Source: render/sprites/AgentSprite.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_bodysprite.js.html b/docs/render_sprites_bodysprite.js.html index f5f00343..ef56b10e 100644 --- a/docs/render_sprites_bodysprite.js.html +++ b/docs/render_sprites_bodysprite.js.html @@ -24,7 +24,7 @@

Source: render/sprites/bodysprite.js

import { Sprite } from "./sprite.js"
-import { Vec2 } from "../../math/index.js"
+import { Vector2 } from "../../math/index.js"
 import { Shape } from "../../physics/index.js"
 import { BasicMaterial } from "../material/index.js"
 import { ObjType } from "../../physics/settings.js"
@@ -32,7 +32,7 @@ 

Source: render/sprites/bodysprite.js

-let r = new Vec2() +let r = new Vector2() let material = new BasicMaterial() material.wireframe = true /** @@ -160,7 +160,7 @@

Source: render/sprites/bodysprite.js

shape.position.x, shape.position.y, shape.radius) - Vec2.fromRad(shape.angle, r).multiply(shape.radius) + Vector2.fromRad(shape.angle, r).multiply(shape.radius) line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y) @@ -193,13 +193,13 @@

Source: render/sprites/bodysprite.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_group.js.html b/docs/render_sprites_group.js.html index ac452327..ae9dbb63 100644 --- a/docs/render_sprites_group.js.html +++ b/docs/render_sprites_group.js.html @@ -114,13 +114,13 @@

Source: render/sprites/group.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_imagesprite.js.html b/docs/render_sprites_imagesprite.js.html index b202002c..06748946 100644 --- a/docs/render_sprites_imagesprite.js.html +++ b/docs/render_sprites_imagesprite.js.html @@ -126,7 +126,7 @@

Source: render/sprites/imagesprite.js


diff --git a/docs/render_sprites_particleSystem.js.html b/docs/render_sprites_particleSystem.js.html index eedbda2e..04e5162f 100644 --- a/docs/render_sprites_particleSystem.js.html +++ b/docs/render_sprites_particleSystem.js.html @@ -24,7 +24,7 @@

Source: render/sprites/particleSystem.js

import { Sprite } from "./sprite.js"
-import { Vec2, rand } from "../../math/index.js"
+import { Vector2, rand } from "../../math/index.js"
 import { circle, fill } from "../utils/index.js"
 
 /**
@@ -33,12 +33,12 @@ 

Source: render/sprites/particleSystem.js

class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -64,13 +64,13 @@

Source: render/sprites/particleSystem.js

*/ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos - this.velocity = new Vec2() + this.velocity = new Vector2() this.radius = radius this.color = { r: 100, @@ -158,7 +158,7 @@

Source: render/sprites/particleSystem.js

*/ create() { return new Particle( - new Vec2(...this.position), + new Vector2(...this.position), rand(1, 10), rand(1, 6) ) @@ -215,13 +215,13 @@

Source: render/sprites/particleSystem.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_sprite.js.html b/docs/render_sprites_sprite.js.html index cb3e6742..89be478c 100644 --- a/docs/render_sprites_sprite.js.html +++ b/docs/render_sprites_sprite.js.html @@ -23,8 +23,8 @@

Source: render/sprites/sprite.js

-
import { Vec2, Angle } from "../../math/index.js"
-import { Utils } from "../../utils/index.js"
+            
import { Vector2, Angle } from "../../math/index.js"
+import { Component } from "../../ecs/index.js"
 
 /**
  * This is the base class used to render images and paths onto the renderer.
@@ -80,7 +80,7 @@ 

Source: render/sprites/sprite.js

/** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -114,9 +114,9 @@

Source: render/sprites/sprite.js

*/ init(entity) { if(!entity){ - this._position = new Vec2() + this._position = new Vector2() this._orientation = new Angle() - this._scale = new Vec2(1,1) + this._scale = new Vector2(1,1) return } this.entity = entity @@ -125,7 +125,7 @@

Source: render/sprites/sprite.js

this._position = transform.position this._orientation = transform.orientation //TODO - Correct this later - this._scale = new Vec2(1,1) + this._scale = new Vector2(1,1) return this } toJson(){ @@ -146,7 +146,7 @@

Source: render/sprites/sprite.js

this.parent = renderer.getById(obj.parent) } } -Utils.inheritComponent(Sprite) +Component.implement(Sprite) export { Sprite }
@@ -159,13 +159,13 @@

Source: render/sprites/sprite.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/render_sprites_staticimagesprite.js.html b/docs/render_sprites_staticimagesprite.js.html index b997c87c..6331fae8 100644 --- a/docs/render_sprites_staticimagesprite.js.html +++ b/docs/render_sprites_staticimagesprite.js.html @@ -88,7 +88,7 @@

Source: render/sprites/staticimagesprite.js


diff --git a/docs/render_utils_canvasfunc.js.html b/docs/render_utils_canvasfunc.js.html index 065e4d90..eda92b48 100644 --- a/docs/render_utils_canvasfunc.js.html +++ b/docs/render_utils_canvasfunc.js.html @@ -55,7 +55,7 @@

Source: render/utils/canvasfunc.js

} /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ export function vertices(ctx, vertices, close = true) { @@ -140,13 +140,13 @@

Source: render/utils/canvasfunc.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/storage_cookie.js.html b/docs/storage_cookie.js.html index a382c09f..85e52b81 100644 --- a/docs/storage_cookie.js.html +++ b/docs/storage_cookie.js.html @@ -82,13 +82,13 @@

Source: storage/cookie.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/storage_localStorage.js.html b/docs/storage_localStorage.js.html index 37699bd8..0ee92761 100644 --- a/docs/storage_localStorage.js.html +++ b/docs/storage_localStorage.js.html @@ -63,13 +63,13 @@

Source: storage/localStorage.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/storage_sessionStorage.js.html b/docs/storage_sessionStorage.js.html index 7e22ef5c..cd2dffd5 100644 --- a/docs/storage_sessionStorage.js.html +++ b/docs/storage_sessionStorage.js.html @@ -64,13 +64,13 @@

Source: storage/sessionStorage.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/typedef_bounds.js.html b/docs/typedef_bounds.js.html index 5b6558c5..f1a30690 100644 --- a/docs/typedef_bounds.js.html +++ b/docs/typedef_bounds.js.html @@ -37,13 +37,13 @@

Source: typedef/bounds.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/typedef_manifold.js.html b/docs/typedef_manifold.js.html index 30607a5f..83ff5045 100644 --- a/docs/typedef_manifold.js.html +++ b/docs/typedef_manifold.js.html @@ -37,13 +37,13 @@

Source: typedef/manifold.js

* @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -53,9 +53,9 @@

Source: typedef/manifold.js

* @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo @@ -71,13 +71,13 @@

Source: typedef/manifold.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/typedef_vectorlike.js.html b/docs/typedef_vectorlike.js.html index 1449ca78..073ed9e7 100644 --- a/docs/typedef_vectorlike.js.html +++ b/docs/typedef_vectorlike.js.html @@ -37,13 +37,13 @@

Source: typedef/vectorlike.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/utils_clock.js.html b/docs/utils_clock.js.html index eee6c42c..93198473 100644 --- a/docs/utils_clock.js.html +++ b/docs/utils_clock.js.html @@ -71,13 +71,13 @@

Source: utils/clock.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/utils_common.js.html b/docs/utils_common.js.html index b10a7638..35c78d42 100644 --- a/docs/utils_common.js.html +++ b/docs/utils_common.js.html @@ -170,37 +170,25 @@

Source: utils/common.js

}) } /** - * Mixes the functions required by a system into a class. + * Mixes the functions required by an object into another object. * * @memberof Utils - * @param {Function} system the class constructor function to add methods to. + * @param {Object} from the object constructor function to add methods from. + * @param {Object} to the object constructor function to add methods to. */ -Utils.inheritSystem = function(system) { - if (system == void 0 || typeof system !== "function") return - let proto = system.prototype - if (!proto.init) { - proto.init = function() { - Err.warnOnce("Please override the init method in the system " + proto.constructor.name) - } - } - if (!proto.update) { - proto.update = function() { - Err.warnOnce("Please override the update method in the system " + proto.constructor.name) - - } - } - if (!proto.add) { - proto.add = function(component) { - this.objects.push(component) - } - } - - if (!proto.remove) { - proto.remove = function(component) { - let index = this.objects.indexOf(component) - Utils.removeElement(this.objects, index) - } +export function mixin(from, to,props = []) { + let proto = from.prototype + let proto2 = to.prototype + console.log(proto2); + Object.assign(proto,from) + for (let name of props) { + let methodName = props[name] + //if(!(methodName in proto))continue + //if (methodName in proto2) continue + + proto2[name] = proto[name] } + //console.log(new to()); }
@@ -211,13 +199,13 @@

Source: utils/common.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/utils_error.js.html b/docs/utils_error.js.html index 6856bb8a..b92cca76 100644 --- a/docs/utils_error.js.html +++ b/docs/utils_error.js.html @@ -76,7 +76,7 @@

Source: utils/error.js

* @memberof Err * @param {string} message */ -Err.warnOnce = function(message) { +Err.warnOnce = function warnOnce(message) { if (mess.includes(message)) return mess.push(message) Err.warn(message) @@ -92,6 +92,16 @@

Source: utils/error.js

Err.assert = function(test, errfunc, message) { if (!test) errfunc(message) return test +} + +/** + * Logs out a warning to the console. + * + * @memberof Err + * @param {string} message + */ +Err.deprecate = function deprecate(message) { + Err.warnOnce(message) }
@@ -102,13 +112,13 @@

Source: utils/error.js


- Documentation generated by JSDoc 4.0.2 on Sat Oct 28 2023 11:28:11 GMT-0700 (Pacific Daylight Time) + Documentation generated by JSDoc 4.0.2 on Wed Nov 15 2023 17:32:29 GMT+0300 (East Africa Time)
diff --git a/docs/utils_pools_VectorPool.js.html b/docs/utils_pools_VectorPool.js.html index 4234f0db..f96de5ff 100644 --- a/docs/utils_pools_VectorPool.js.html +++ b/docs/utils_pools_VectorPool.js.html @@ -27,7 +27,7 @@

Source: utils/pools/VectorPool.js

import {Pool} from "./objectPool.js"
-import { Vec2} from "../math/index.js"
+import { Vector2} from "../math/index.js"
 
 /**
  * A vector pool.
@@ -36,10 +36,10 @@ 

Source: utils/pools/VectorPool.js

/** * @inheritdoc * - * @returns Vec2 + * @returns Vector2 */ create(){ - return new Vec2() + return new Vector2() } /** * @@ -60,7 +60,7 @@

Source: utils/pools/VectorPool.js


diff --git a/docs/utils_pools_objectPool.js.html b/docs/utils_pools_objectPool.js.html index 7aa49ae8..b836fdd6 100644 --- a/docs/utils_pools_objectPool.js.html +++ b/docs/utils_pools_objectPool.js.html @@ -122,7 +122,7 @@

Source: utils/pools/objectPool.js


diff --git a/package-lock.json b/package-lock.json index 55ca4536..008d4d88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chaos-studio", - "version": "0.4.13", + "version": "0.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "chaos-studio", - "version": "0.4.13", + "version": "0.5.0", "license": "MIT", "devDependencies": { "jsdoc": "4.0.2", diff --git a/package.json b/package.json index f05dd76f..52f9d41b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chaos-studio", - "version": "0.4.13", + "version": "0.5.0", "description": "a 2D game engine", "homepage": "https://waynemwashuma.github.io/chaos-engine/", "bugs": { diff --git a/src/AI/agent.js b/src/AI/agent.js index 69cb7469..1d3ecf45 100644 --- a/src/AI/agent.js +++ b/src/AI/agent.js @@ -1,4 +1,4 @@ -import { Utils } from "../utils/index.js" +import { Component } from "../ecs/index.js" import { BehaviourManager } from "./behaviourManager.js" /** @@ -10,19 +10,19 @@ class Agent { /** * The position of the entity. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the entity. * - * @type Vec2 + * @type Vector2 */ velocity = null /** * The acceleration of the entity. * - * @type Vec2 + * @type Vector2 */ acceleration = null /** @@ -100,7 +100,7 @@ class Agent { this.behaviours.draw(ctx) } } -Utils.inheritComponent(Agent) +Component.implement(Agent) export { Agent } \ No newline at end of file diff --git a/src/AI/behaviourManager.js b/src/AI/behaviourManager.js index 707ed8ea..57b91dd2 100644 --- a/src/AI/behaviourManager.js +++ b/src/AI/behaviourManager.js @@ -1,5 +1,5 @@ import { Utils } from "../utils/index.js" -import { Vec2 } from "../math/index.js" +import { Vector2 } from "../math/index.js" /** * Manages the behaviours for an agent. @@ -16,7 +16,7 @@ class BehaviourManager { /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vec2() + _accumulated = new Vector2() /** * Adds a behavior to the manager * @@ -51,14 +51,14 @@ class BehaviourManager { * @param {number} inv_dt */ update(inv_dt) { - let result = new Vec2() + let result = new Vector2() this._accumulated.set(0, 0) for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt) this._accumulated.add(result) } this._agent.acceleration.add(this._accumulated) - this._agent.orientation.radian = Vec2.toRad(this._agent.velocity) + this._agent.orientation.radian = Vector2.toRad(this._agent.velocity) } /** * Removes all behaviours from a manager. diff --git a/src/AI/behaviours/arrive.js b/src/AI/behaviours/arrive.js index da55c771..d75828c6 100644 --- a/src/AI/behaviours/arrive.js +++ b/src/AI/behaviours/arrive.js @@ -1,8 +1,8 @@ import { Behaviour } from "./behaviour.js" -import { Vec2, map } from "../../math/index.js" +import { Vector2, map } from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2() +let tmp1 = new Vector2(), + tmp2 = new Vector2() /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -17,7 +17,7 @@ class ArriveBehaviour extends Behaviour { */ radius = 1000 /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -34,9 +34,9 @@ class ArriveBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) diff --git a/src/AI/behaviours/behaviour.js b/src/AI/behaviours/behaviour.js index 5ece39a8..f5ca81c8 100644 --- a/src/AI/behaviours/behaviour.js +++ b/src/AI/behaviours/behaviour.js @@ -8,13 +8,13 @@ class Behaviour { /** * The position of the agent. * - * @type Vec2 + * @type Vector2 */ position = null /** * The velocity of the agent. * - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -44,9 +44,9 @@ class Behaviour { /** * Calculates the amount of force required to satisfy a behavior. * - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) {} /** diff --git a/src/AI/behaviours/evade.js b/src/AI/behaviours/evade.js index 37b4a372..27bfd42c 100644 --- a/src/AI/behaviours/evade.js +++ b/src/AI/behaviours/evade.js @@ -1,7 +1,7 @@ import { Behaviour } from "./behaviour.js" -import { Vec2,map } from "../../math/index.js" +import { Vector2,map } from "../../math/index.js" -let tmp1 = new Vec2() +let tmp1 = new Vector2() /** * Creates a behaviour to evade a certain position. * @@ -15,7 +15,7 @@ class EvadeBehaviour extends Behaviour { */ radius = 200 /** - * @param { Vec2} pursuer + * @param { Vector2} pursuer */ constructor(pursuer) { super() @@ -32,9 +32,9 @@ class EvadeBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.position).sub(this.pursuer) diff --git a/src/AI/behaviours/flocking.js b/src/AI/behaviours/flocking.js index 9e8273ff..e9c0cb08 100644 --- a/src/AI/behaviours/flocking.js +++ b/src/AI/behaviours/flocking.js @@ -1,5 +1,5 @@ import { Behaviour } from "./behaviour.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" /** @@ -25,9 +25,9 @@ class Flock extends Behaviour{ } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { diff --git a/src/AI/behaviours/path.js b/src/AI/behaviours/path.js index 647ef2ec..a06c3bb1 100644 --- a/src/AI/behaviours/path.js +++ b/src/AI/behaviours/path.js @@ -1,8 +1,8 @@ import { Behaviour } from "./behaviour.js" -import { Vec2, map } from "../../math/index.js" +import { Vector2, map } from "../../math/index.js" import { circle, fill, stroke } from "../../render/index.js" -const tmp1 = new Vec2() -const tmp2 = new Vec2() +const tmp1 = new Vector2() +const tmp2 = new Vector2() /** * Creates a behaviour that follows a certain path. * @@ -25,9 +25,9 @@ export class PathFollowing extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { tmp1.copy(this.position) @@ -65,7 +65,7 @@ export class PathFollowing extends Behaviour { /** * Adds a point into the path. * - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this.path.add(point) diff --git a/src/AI/behaviours/pursuit.js b/src/AI/behaviours/pursuit.js index 22693463..7303c70b 100644 --- a/src/AI/behaviours/pursuit.js +++ b/src/AI/behaviours/pursuit.js @@ -1,5 +1,5 @@ import { Behaviour } from "./behaviour.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" /** @@ -20,9 +20,9 @@ class Pursuit extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target){ diff --git a/src/AI/behaviours/seek.js b/src/AI/behaviours/seek.js index 20ceefd6..d9d83932 100644 --- a/src/AI/behaviours/seek.js +++ b/src/AI/behaviours/seek.js @@ -1,7 +1,7 @@ import { Behaviour } from "./behaviour.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" -let tmp1 = new Vec2() +let tmp1 = new Vector2() /** * Creates a behaviour to seek out a target and move towards it. @@ -17,11 +17,11 @@ class SeekBehaviour extends Behaviour { */ radius = 100 /** - * @type Vec2 + * @type Vector2 */ target = null /** - * @param { Vec2} target + * @param { Vector2} target */ constructor(target) { super() @@ -37,9 +37,9 @@ class SeekBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target,inv_dt) { let difference = tmp1.copy(this.target).sub(this.position) diff --git a/src/AI/behaviours/wandering.js b/src/AI/behaviours/wandering.js index d4368425..f0a46539 100644 --- a/src/AI/behaviours/wandering.js +++ b/src/AI/behaviours/wandering.js @@ -1,8 +1,8 @@ import { Behaviour } from "./behaviour.js" -import { Vec2, rand } from "../../math/index.js" +import { Vector2, rand } from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2() +let tmp1 = new Vector2(), + tmp2 = new Vector2() /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -39,21 +39,21 @@ class WanderBehaviour extends Behaviour { } /** * @inheritdoc - * @param { Vec2} target + * @param { Vector2} target * @param {number} inv_dt - * @returns Vec2 the first parameter + * @returns Vector2 the first parameter */ calc(target, inv_dt) { this._theta += rand(-this.dtheta, +this.dtheta) let forward = tmp1.copy(this.velocity) if (forward.equalsZero()) - Vec2.random(forward) + Vector2.random(forward) let radius = this._radius * 0.8 forward.setMagnitude(this._radius) //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vec2.fromDeg(this._theta + Vec2.toDeg(this.velocity), tmp2).multiply(radius) + Vector2.fromDeg(this._theta + Vector2.toDeg(this.velocity), tmp2).multiply(radius) forward.add(tmp2) //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed) diff --git a/src/AI/paths/path.js b/src/AI/paths/path.js index ec60731c..cbc1f318 100644 --- a/src/AI/paths/path.js +++ b/src/AI/paths/path.js @@ -1,11 +1,11 @@ -import { Vec2, clamp } from "../../math/index.js" +import { Vector2, clamp } from "../../math/index.js" import { vertices, stroke } from "../../render/index.js" -let tmp = new Vec2() +let tmp = new Vector2() export class Path { /** * @private - * type Vec2[] + * type Vector2[] */ _points = [] /** @@ -43,15 +43,15 @@ export class Path { _finished = false /** * @private - * type Vec2 + * type Vector2 */ - _lerpedPoint = new Vec2() + _lerpedPoint = new Vector2() /** * type boolean */ loop = false /** - * @param { Vec2} point + * @param { Vector2} point */ add(point) { this._points.push(point) @@ -100,7 +100,7 @@ export class Path { if (!this.advance()) this._finished = true } this._lerp_t = clamp(this._lerp_t, 0, 1) - Vec2.lerp( + Vector2.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, diff --git a/src/dataStructures/pools/VectorPool.js b/src/dataStructures/pools/VectorPool.js index d256c56e..5dedbfb4 100644 --- a/src/dataStructures/pools/VectorPool.js +++ b/src/dataStructures/pools/VectorPool.js @@ -1,5 +1,5 @@ import {Pool} from "./objectPool.js" -import { Vec2} from "../math/index.js" +import { Vector2} from "../math/index.js" /** * A vector pool. @@ -8,10 +8,10 @@ export class VectorPool extends Pool{ /** * @inheritdoc * - * @returns Vec2 + * @returns Vector2 */ create(){ - return new Vec2() + return new Vector2() } /** * diff --git a/src/ecs/component.js b/src/ecs/component.js index 028d6e3e..749f1d6c 100644 --- a/src/ecs/component.js +++ b/src/ecs/component.js @@ -1,25 +1,19 @@ -import { Utils } from "../utils/index.js" +import { Utils, Err, mixin } from "../utils/index.js" /** * A helper class. * Since there are no interfaces in JavaScript, * you might have to extend this to create a component, but there is another solution. - * Use instead Utils.inheritComponent() if you have your own hierarchy of classes. + * Use instead `Component.implement()` if you have your own hierarchy of classes. * In typescript,this would be an interface. * * @interface * */ class Component { - /** - * @type Entity | null - */ - entity = null - destroy() { - this.entity = null - } + destroy() {} /** * @type string */ @@ -33,25 +27,20 @@ class Component { return "component" } /** - * @param {Entity} entity - */ - init(entity) { - this.entity = entity - } + init(entity) {} /** * @param {number} dt */ update(dt) { Err.warnOnce("Please override the update function in the component " + proto.constructor.name) - } /** * @param {string} n */ - get(n) { - return this.entity.getComponent(n); + get(entity,n) { + return entity.getComponent(n); } /** * @param {...string} names @@ -65,8 +54,8 @@ class Component { * @param {CircleBounding | BoxBounding} bound * @param {Entity} [target=[]] */ - query(bound, target = []) { - return this.entity.query(bound, target) + query(entity,bound, target = []) { + return entity.query(bound, target) } static fromJson() { throw "Implement static method fromJson() in your component " + this.CHOAS_CLASSNAME @@ -74,36 +63,10 @@ class Component { static toJson() { throw "Implement static method toJson() in your component " + this.CHOAS_CLASSNAME } + static implement(component) { + Utils.inheritComponent(component) + } } -Utils.inheritComponent(Component) export { Component -} -/** - * Destroys the component. - * - * @function - * @name Component#destroy - */ -/** - * Initializes a component. - * - * @function - * @name Component#init - * @param {Entity} entity - */ -/** - * Updates a component.Called by the system which manages its type. - * - * @function - * @name Component#update - * @param {number} dt - */ -/** - * Gets a component in the entity containing this entity. - * - * @function - * @name Component#requires - * @param {string} ...names - * @throws Qhen a named component isnt in the parent entity - */ \ No newline at end of file +} \ No newline at end of file diff --git a/src/ecs/manager.js b/src/ecs/manager.js index c569cd23..66dfe904 100644 --- a/src/ecs/manager.js +++ b/src/ecs/manager.js @@ -443,7 +443,7 @@ class Manager { * @param {Array} comps An array containing the component names to be searched * @returns {Entity} */ - getEntityByComponents(comps) { + getEntityByComponents(comps,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < comps.length; j++) { if (!entities[i].has(comps[j])) continue @@ -475,7 +475,7 @@ class Manager { * @param {Array} tags An array containing the tags to be searched * @returns {Entity} */ - getEntityByTags(tags) { + getEntityByTags(tags,entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < tags.length; j++) { if (!entities[i].hasTag(tags[j])) continue diff --git a/src/ecs/movableComponent.js b/src/ecs/movableComponent.js index 2b025530..7d73e0be 100644 --- a/src/ecs/movableComponent.js +++ b/src/ecs/movableComponent.js @@ -1,5 +1,5 @@ import { Component } from "./component.js" -import { Vec2, Angle } from "../math/index.js" +import { Vector2, Angle } from "../math/index.js" /** * Component to hold requirements for an entity to move. * @@ -15,9 +15,9 @@ class Movable extends Component { */ constructor(x, y, a) { super() - this.velocity = new Vec2(x, y) + this.velocity = new Vector2(x, y) this.rotation = new Angle(a) - this.acceleration = new Vec2() + this.acceleration = new Vector2() } toJson() { return { diff --git a/src/ecs/system.js b/src/ecs/system.js index 0e28b9c9..42b88d96 100644 --- a/src/ecs/system.js +++ b/src/ecs/system.js @@ -1,36 +1,51 @@ -import { Utils } from "../utils/index.js" - +import { mixin, Err, Utils } from "../utils/index.js" /** * Updates components assigned to it. * * @interface -*/ -export class System{} + */ +export class System { + init() { + Err.warnOnce("Please override the init method in the system " + proto.constructor.name) + } + update() { + Err.warnOnce("Please override the update method in the system " + proto.constructor.name) -Utils.inheritSystem(System) + } + add(component) { + this.objects.push(component) + } + remove(component) { + let index = this.objects.indexOf(component) + Utils.removeElement(this.objects, index) + } + static implement(system) { + mixin(System,system) + } +} /** * * @function * @name System#add * @param {Component} component -*/ + */ /** * * @function * @name System#remove * @param {Component} component -*/ + */ /** * * @function * @name System#init * @param {Manager} manager */ - /** - * - * @function - * @name System#update - * @param {number} dt - */ \ No newline at end of file +/** + * + * @function + * @name System#update + * @param {number} dt + */ \ No newline at end of file diff --git a/src/ecs/transformComponent.js b/src/ecs/transformComponent.js index ca1c9502..8dd06aa7 100644 --- a/src/ecs/transformComponent.js +++ b/src/ecs/transformComponent.js @@ -1,5 +1,5 @@ //import { Component } from "./component.js" -import { Vec2, Angle } from "../math/index.js" +import { Vector2, Angle } from "../math/index.js" /** * Holds transformation info of an entity @@ -15,7 +15,7 @@ class Transform { * @returns */ constructor(x,y,a){ - this.position = new Vec2(x,y) + this.position = new Vector2(x,y) this.orientation = new Angle(a) } init(){} diff --git a/src/events/index.js b/src/events/index.js index f6383f3e..ab476dd3 100644 --- a/src/events/index.js +++ b/src/events/index.js @@ -1,4 +1,5 @@ export * from "./eventDispatcher.js" export * from "./DOMEventHandler.js" export * from "./eventHandlers.js" -export * from "./events.js" \ No newline at end of file +export * from "./events.js" +export * from "./signals.js" \ No newline at end of file diff --git a/src/events/signals.js b/src/events/signals.js new file mode 100644 index 00000000..41df380f --- /dev/null +++ b/src/events/signals.js @@ -0,0 +1,34 @@ +export class Signal { + _listeners = [] + _value = null + constructor(value){ + this._value = value + } + set value(x) { + this._value = x + for (var i = 0; i < this._listeners.length; i++) { + let func = this._listeners[i] + func.listener(this) + if(func.callOnce) + this.removeListener(func.listener) + } + } + get value() { + return this._value + } + addListener(listener,callOnce=false) { + this._listeners.push({ + listener, + callOnce + }) + } + removeListener(listener) { + for (var i = 0; i < this._listeners.length; i++) { + if (this._listeners[i].listener == listener) + return this._detach(i) + } + } + _detach(bindingIndex){ + this._listeners.splice(i, 1) + } +} \ No newline at end of file diff --git a/src/math/matrix.js b/src/math/matrix.js index 59b7956c..8988cb26 100644 --- a/src/math/matrix.js +++ b/src/math/matrix.js @@ -141,7 +141,7 @@ export class Matrix2 { /** * Transforms the given vector. * - * @param { Vec2} v + * @param { Vector2} v */ transform(v) { let x = v.x diff --git a/src/math/vector.js b/src/math/vector.js index a2e0472e..6234c458 100644 --- a/src/math/vector.js +++ b/src/math/vector.js @@ -9,7 +9,7 @@ let TWO_PI = Math.PI * 2 * @author Wayne Mwashuma * @license MIT */ -class Vec2 { +export class Vector2 { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -55,28 +55,28 @@ class Vec2 { } /** *Calculates length of this vector to another vector - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector */ distanceTo(v) { obj.x = this.x - v.x obj.y = this.y - v.y - return Math.sqrt( Vec2.prototype.magnitudeSquared.call(obj)) + return Math.sqrt( Vector2.prototype.magnitudeSquared.call(obj)) } /** *Calculates length squared of this vector to another vector * - * @param { Vec2} v the other vector + * @param { Vector2} v the other vector * @returns {number} */ distanceToSquared(v) { obj.x = this.x - v.x obj.y = this.y - v.y - return Vec2.prototype.magnitudeSquared.call(obj) + return Vector2.prototype.magnitudeSquared.call(obj) } /** * Adds a given vector into this * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ add(v) { @@ -99,7 +99,7 @@ class Vec2 { /** * Subtracts a given vector from this vector * - * @param { Vec2} v + * @param { Vector2} v * @returns {this} */ sub(v) { @@ -121,7 +121,7 @@ class Vec2 { /** * Calculates the dot product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ dot(v) { @@ -130,7 +130,7 @@ class Vec2 { /** * Calculates the cross product of two vectors. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ cross(v) { @@ -174,7 +174,7 @@ class Vec2 { * Checks to see if this vector is equal to * another vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {boolean} */ equals(v) { @@ -192,21 +192,21 @@ class Vec2 { * Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector. * * @param {number} l the length of the vector returned. - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ normal(l = 1, target) { - target = target || new Vec2() + target = target || new Vector2() target.copy(this).normalize() return target.set(-target.y * l, target.x * l); }; /** * Returns the normal to a vector, the normal has the same length as the vector. * - * @param { Vec2} [target = Vec2] Vec2 in which results are stored. - * @returns { Vec2} + * @param { Vector2} [target = Vector2] Vector2 in which results are stored. + * @returns { Vector2} */ - normalFast(target = new Vec2()) { + normalFast(target = new Vector2()) { return target.set(-this.y, this.x) } /** @@ -243,16 +243,16 @@ class Vec2 { * Copies x and y values of this vector to * a new vector and returns the new vector. * - * @return Vec2 + * @return Vector2 */ clone() { - return new Vec2(this.x, this.y) + return new Vector2(this.x, this.y) } /** * Copies x and y values of another vector * to this vector. * - * @@param { Vec2} v + * @@param { Vector2} v * @return this */ copy(v) { @@ -308,10 +308,10 @@ class Vec2 { * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param { Vec2} [target] - * @return { Vec2} + * @param { Vector2} [target] + * @return { Vector2} */ - reflect(normal, target = new Vec2()) { + reflect(normal, target = new Vector2()) { return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -349,33 +349,33 @@ class Vec2 { * Gets the angle (in degrees) between two * vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2 * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getAbsDegBtwn(v1, v2) { let a = v1.cross(v2) - let deg = Vec2.getDegBtwn(v1, v2) + let deg = Vector2.getDegBtwn(v1, v2) return a < 0 ? deg : 360 - deg } /** - * Same as ` Vec2.getAbsDegBtwn` but returns in radians. + * Same as ` Vector2.getAbsDegBtwn` but returns in radians. * - * @param { Vec2 } v1 start of the angle - * @param { Vec2 } v2 end of the angle + * @param { Vector2 } v1 start of the angle + * @param { Vector2 } v2 end of the angle * @returns {number} **/ static getAbsRadBtwn(v1, v2) { let a = v1.cross(v2) - let deg = Vec2.getDegBtwn(v1, v2) + let deg = Vector2.getDegBtwn(v1, v2) return a < 0 ? deg : 360 - deg } /** * Gets the angle (in radians) between two * vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getRadBtwn(v1, v2) { @@ -385,22 +385,22 @@ class Vec2 { * Gets the angle (in degrees) between two * vectors in shortest direction from v1 to v2 in the range `0°` to `180°` * - * @param { Vec2} v1 start of the angle - * @param { Vec2} v2 end of the angle + * @param { Vector2} v1 start of the angle + * @param { Vector2} v2 end of the angle * @returns {number} */ static getDegBtwn(v1, v2) { - return Vec2.getRadBtwn(v1, v2) * 180 / Math.PI + return Vector2.getRadBtwn(v1, v2) * 180 / Math.PI } /** * Returns a unit vector pointing in the * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ - static fromRad(radian, target = new Vec2()) { + static fromRad(radian, target = new Vector2()) { return target.set(Math.cos(radian), Math.sin(radian)) } /** @@ -408,32 +408,32 @@ class Vec2 { * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param { Vec2} [target] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target] Vector2 to store results in. + * @returns { Vector2} */ static fromDeg(degree, target) { - return Vec2.fromRad(degree * Math.PI / 180, target) + return Vector2.fromRad(degree * Math.PI / 180, target) } /** - * Generates a new unit Vec2 in a random direction + * Generates a new unit Vector2 in a random direction * - * @param { Vec2} [target] - * @returns { Vec2} + * @param { Vector2} [target] + * @returns { Vector2} */ static random(target) { - return Vec2.fromRad(Math.random() * TWO_PI, target) + return Vector2.fromRad(Math.random() * TWO_PI, target) } /** - * Returns a Vec2 that has been lerped between v1 and v2 - * @param { Vec2} v1 the vector to lerp from - * @param { Vec2} v2 the vector to lerp from - * @param {number} t a value from 0 to 1 to scale the new Vec2 between v1 and v2 - * @param { Vec2} [target] the vector to store results into + * Returns a Vector2 that has been lerped between v1 and v2 + * @param { Vector2} v1 the vector to lerp from + * @param { Vector2} v2 the vector to lerp from + * @param {number} t a value from 0 to 1 to scale the new Vector2 between v1 and v2 + * @param { Vector2} [target] the vector to store results into * - * @returns { Vec2} + * @returns { Vector2} */ - static lerp(v1, v2, t, target = new Vec2()) { - target = target || new Vec2() + static lerp(v1, v2, t, target = new Vector2()) { + target = target || new Vector2() return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y @@ -443,17 +443,17 @@ class Vec2 { /** * Returns the angle in degrees between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toDeg(v) { - return Vec2.toRad(v) / Math.PI * 180 + return Vector2.toRad(v) / Math.PI * 180 } /** * Returns the angle in radians between the positive x-axis and the vector. * - * @param { Vec2} v + * @param { Vector2} v * @returns {number} */ static toRad(v) { @@ -466,12 +466,24 @@ class Vec2 { * * @static * @readonly - * @type { Vec2} + * @type { Vector2} */ - static ZERO = Object.freeze(new Vec2()) + static ZERO = Object.freeze(new Vector2()) } - +class Vector extends Vector2{ + constructor(x,y){ + super(x,y) + console.error("The class `Vector` is depreciated since v0.4.13.Use Vector2 instead.") + } +} +class Vec2 extends Vector2{ + constructor(x,y){ + super(x,y) + console.error("The class `Vec2` is depreciated since v0.4.13.Use Vector2 instead.") + } +} export { - Vec2 + Vec2, + Vector } \ No newline at end of file diff --git a/src/physics/AABB/boundingBox.js b/src/physics/AABB/boundingBox.js index a19ba06f..0da36274 100644 --- a/src/physics/AABB/boundingBox.js +++ b/src/physics/AABB/boundingBox.js @@ -106,7 +106,7 @@ export class BoundingBox extends Component { /** * Translates this bound to the given position. * - * @param { Vec2} pos + * @param { Vector2} pos */ update(pos) { let dx = pos.x - this.pos.x diff --git a/src/physics/AABB/overlap.js b/src/physics/AABB/overlap.js index d68d44fc..8e47d8f1 100644 --- a/src/physics/AABB/overlap.js +++ b/src/physics/AABB/overlap.js @@ -40,6 +40,6 @@ export const Overlaps = { (x - b.pos.x) * (x - b.pos.x) + (y - b.pos.y) * (y - b.pos.y) - return distance < b.r; + return distance < b.r * b.r; } } \ No newline at end of file diff --git a/src/physics/SAT/index.js b/src/physics/SAT/index.js index 15693251..224234af 100644 --- a/src/physics/SAT/index.js +++ b/src/physics/SAT/index.js @@ -1,4 +1,4 @@ -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" import { Utils } from "../../utils/index.js" const _arr = [], @@ -6,7 +6,7 @@ const _arr = [], overlap: 0, verticesA: null, verticesB: null, - axis: new Vec2(), + axis: new Vector2(), vertex: null, shape: null }, @@ -20,9 +20,9 @@ const _arr = [], max: 0, indexN: 0 }, - tmp4 = new Vec2(), - tmp5 = new Vec2(), - tmp6 = new Vec2() + tmp4 = new Vector2(), + tmp5 = new Vector2(), + tmp6 = new Vector2() /** * Used for narrowphase collision detection and contact info generation. @@ -109,7 +109,7 @@ export const SAT = { /** * @param {Shape} shapeA * @param {Shape} shapeB - * @param { Vec2[]} axes + * @param { Vector2[]} axes * @param {Manifold} shapeA * @param {number} iu */ @@ -169,8 +169,8 @@ export const SAT = { return manifold }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis + * @param { Vector2[]} vertices + * @param { Vector2} axis * @param {Object} target */ projectVerticesToAxis(vertices, axis, target) { @@ -195,9 +195,9 @@ export const SAT = { return target }, /** - * @param { Vec2[]} vertices - * @param { Vec2} axis - * @param { Vec2[]} target + * @param { Vector2[]} vertices + * @param { Vector2} axis + * @param { Vector2[]} target * @param {number} nearVertexIndex */ findNearSupports(vertices, axis, target = [], nearVertexIndex) { @@ -225,7 +225,7 @@ export const SAT = { }, /** * @param {Shape} shape - * @param { Vec2} point + * @param { Vector2} point */ shapeContains(shape, point) { if (shape.type == "circle") @@ -233,9 +233,9 @@ export const SAT = { return SAT.verticesContain(shape.vertices, point) }, /** - * @param { Vec2} position + * @param { Vector2} position * @param {number} radius - * @param { Vec2} point + * @param { Vector2} point */ circleContains(position, radius, point) { let dx = point.x - position.x, @@ -245,7 +245,7 @@ export const SAT = { return true }, /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {number} point */ verticesContain(vertices, point) { diff --git a/src/physics/bodies/body.js b/src/physics/bodies/body.js index 2e34ccab..606f7795 100644 --- a/src/physics/bodies/body.js +++ b/src/physics/bodies/body.js @@ -1,5 +1,6 @@ -import { Vec2, Angle } from "../../math/index.js" -import { Utils } from "../../utils/index.js" +import { Vector2, Angle } from "../../math/index.js" +import { Component } from "../../ecs/index.js" +import {Utils} from "../../utils/index.js" import { BoundingBox } from "../AABB/index.js" import { ObjType, Settings } from "../settings.js" import { Shape } from "../shapes/index.js" @@ -20,23 +21,23 @@ class Body { * World space coordinates of a body * * @private - * @type Vec2 + * @type Vector2 */ - _position = new Vec2() + _position = new Vector2() /** * velocity of a body.Speed in pixels per second. * * @private - * @type Vec2 + * @type Vector2 */ - _velocity = new Vec2() + _velocity = new Vector2() /** * acceleration of a body in pixels per second squared. * * @private - * @type Vec2 + * @type Vector2 */ - _acceleration = new Vec2() + _acceleration = new Vector2() /** * World space orientation of a body * @@ -84,22 +85,22 @@ class Body { * Anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ _localanchors = [] /** * The original anchors of the body in local space. * * @private - * @type Vec2[] + * @type Vector2[] */ anchors = [] /** * Position of a body in the last frame.. * - * @type Vec2 + * @type Vector2 */ - lastPosition = new Vec2() + lastPosition = new Vector2() /** * Inverse mass of the body. * @@ -270,7 +271,7 @@ class Body { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { return this._acceleration @@ -281,7 +282,7 @@ class Body { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { return this._velocity @@ -358,7 +359,7 @@ class Body { /** * World space position of a body * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -413,11 +414,11 @@ class Body { /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * - * @param { Vec2} v The anchor arm + * @param { Vector2} v The anchor arm * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vec2(v.x, v.y).rotate(this.orientation.radian).add(this.position)) + this.anchors.push(new Vector2(v.x, v.y).rotate(this.orientation.radian).add(this.position)) return this._localanchors.push(v) - 1 } /** @@ -425,7 +426,7 @@ class Body { * Treat the returned value as read-only. * * @param {number} index the position of the - * @returns { Vec2} + * @returns { Vector2} */ getAnchor(index) { return this.anchors[index] @@ -434,20 +435,20 @@ class Body { * Returns a rotated anchor relative to the body. * * @param {number} index The position of the anchor. - * @param { Vec2} [target= Vec2] Vec2 to store results in. - * @returns { Vec2} + * @param { Vector2} [target= Vector2] Vector2 to store results in. + * @returns { Vector2} */ - getLocalAnchor(index, target = new Vec2()) { + getLocalAnchor(index, target = new Vector2()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** * Applies a force to a body affecting its direction of travel and rotation. * * - * @param { Vec2} force The force to be applied. - * @param { Vec2} [arm= Vec2] The collision arm. + * @param { Vector2} force The force to be applied. + * @param { Vector2} [arm= Vector2] The collision arm. */ - applyForce(force, arm = Vec2.ZERO) { + applyForce(force, arm = Vector2.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)) this.rotation.degree += arm.cross(force) * this.inv_inertia } @@ -547,7 +548,7 @@ class Body { body.id = obj.id body.mask = obj.mask obj.anchors.forEach((v) => { - body.setAnchor(new Vec2().fromJson(v)) + body.setAnchor(new Vector2().fromJson(v)) }) } /** @@ -571,7 +572,7 @@ class Body { */ static DYNAMIC = ObjType.DYNAMIC } -Utils.inheritComponent(Body, false, false) +Component.implement(Body) export { Body } \ No newline at end of file diff --git a/src/physics/bodies/composite.js b/src/physics/bodies/composite.js index e925eb7c..0dc4ebef 100644 --- a/src/physics/bodies/composite.js +++ b/src/physics/bodies/composite.js @@ -1,5 +1,5 @@ -import { Vec2 } from "../../math/index.js" -import { Utils } from "../../utils/index.js" +import { Vector2 } from "../../math/index.js" +import { Component } from "../../ecs/index.js" import { ObjType } from "../settings.js" /** @@ -64,10 +64,10 @@ class Composite { /** * Acceleration of a body * - * @type Vec2 + * @type Vector2 */ get acceleration() { - let acceleration = new Vec2() + let acceleration = new Vector2() for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration) } @@ -81,10 +81,10 @@ class Composite { /** * Velocity of a body * - * @type Vec2 + * @type Vector2 */ get velocity() { - let velocity = new Vec2() + let velocity = new Vector2() for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity) @@ -159,10 +159,10 @@ class Composite { /** * Position of a body * - * @type Vec2 + * @type Vector2 */ get position() { - let position = new Vec2() + let position = new Vector2() for (var i = 0; i < this.bodies.length; i++) { position.add(this.bodies[i].position) } @@ -209,7 +209,7 @@ class Composite { } } } -Utils.inheritComponent(Composite) +Component.implement(Composite) export { Composite } \ No newline at end of file diff --git a/src/physics/bodies/heightMap.js b/src/physics/bodies/heightMap.js index 948931b2..c2a089f8 100644 --- a/src/physics/bodies/heightMap.js +++ b/src/physics/bodies/heightMap.js @@ -1,4 +1,4 @@ -import { Vec2} from"../../math/index.js" +import { Vector2} from"../../math/index.js" import {Body} from"./body.js" import {Line} from "../shapes/index.js" @@ -7,13 +7,13 @@ class HeightMap extends Body { let l = [], j = [] for (let i = 0; i < heights.length; i++) { - l.push(new Vec2(step * i, heights[i])) + l.push(new Vector2(step * i, heights[i])) } for (let i = 1; i < l.length; i++) { let line = new Line(l[i - 1], l[i]) j.push(line) } - super(new Vec2(), ...j) + super(new Vector2(), ...j) this.mass = 0 this.mask.layer = 0 } diff --git a/src/physics/constraints/constraint.js b/src/physics/constraints/constraint.js index 31443de7..fbd8bf68 100644 --- a/src/physics/constraints/constraint.js +++ b/src/physics/constraints/constraint.js @@ -1,5 +1,5 @@ import { ObjType } from "../settings.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" /** * Base class for constructing different types of constraints. @@ -12,14 +12,14 @@ class Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { this.body1 = body1 this.body2 = body2 - this.localA = localA || new Vec2() - this.localB = localB || new Vec2() + this.localA = localA || new Vector2() + this.localB = localB || new Vector2() this.stiffness = 50 this.dampening = 0.03 } @@ -81,8 +81,8 @@ class Constraint { let constraint = new Constraint( bod1, bod2, - new Vec2().fromJson(obj.localA), - new Vec2().fromJson(obj.localB) + new Vector2().fromJson(obj.localA), + new Vector2().fromJson(obj.localB) ) constraint.stiffness = obj.stiffness constraint.dampening = obj.dampening diff --git a/src/physics/constraints/distanceConstraint.js b/src/physics/constraints/distanceConstraint.js index 79bfeb93..ed808d3a 100644 --- a/src/physics/constraints/distanceConstraint.js +++ b/src/physics/constraints/distanceConstraint.js @@ -1,11 +1,11 @@ import { Constraint } from "./constraint.js"; -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2(), - tmp3 = new Vec2(), - tmp4 = new Vec2(), - tmp5 = new Vec2() +let tmp1 = new Vector2(), + tmp2 = new Vector2(), + tmp3 = new Vector2(), + tmp4 = new Vector2(), + tmp5 = new Vector2() /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -14,8 +14,8 @@ class DistanceConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB) diff --git a/src/physics/constraints/springConstraint.js b/src/physics/constraints/springConstraint.js index 44ce9d57..a82ac810 100644 --- a/src/physics/constraints/springConstraint.js +++ b/src/physics/constraints/springConstraint.js @@ -1,12 +1,12 @@ import { Constraint } from "./constraint.js"; -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2(), - tmp3 = new Vec2(), - tmp4 = new Vec2(), - tmp5 = new Vec2(), - zero = new Vec2() +let tmp1 = new Vector2(), + tmp2 = new Vector2(), + tmp3 = new Vector2(), + tmp4 = new Vector2(), + tmp5 = new Vector2(), + zero = new Vector2() /** * A constraint that acts like a spring between two bodies */ @@ -14,13 +14,13 @@ class SpringConstraint extends Constraint { /** * @param {Body} body1 * @param {Body} body2 - * @param { Vec2} localA - * @param { Vec2} localB + * @param { Vector2} localA + * @param { Vector2} localB */ constructor(body1, body2, localA, localB) { super(body1, body2) - this.localA = new Vec2().copy(localA || zero) - this.localB = new Vec2().copy(localB || zero) + this.localA = new Vector2().copy(localA || zero) + this.localB = new Vector2().copy(localB || zero) this.fixed = !body1.mass || !body2.mass this.dampening = 1 this.maxDistance = 100 diff --git a/src/physics/integrators/euler.js b/src/physics/integrators/euler.js index 994f015f..ba48b7a4 100644 --- a/src/physics/integrators/euler.js +++ b/src/physics/integrators/euler.js @@ -1,6 +1,6 @@ -import { Vec2 }from "../../math/index.js" +import { Vector2 }from "../../math/index.js" -let a = new Vec2() +let a = new Vector2() /** * Semi implicit euler integration. diff --git a/src/physics/integrators/rungeKutter.js b/src/physics/integrators/rungeKutter.js index 644530d1..fee150a8 100644 --- a/src/physics/integrators/rungeKutter.js +++ b/src/physics/integrators/rungeKutter.js @@ -1,6 +1,6 @@ -import { Vec2 }from "../../math/index.js" +import { Vector2 }from "../../math/index.js" -let a = new Vec2() +let a = new Vector2() /** * Runge Kutta 4 (RK-4) diff --git a/src/physics/integrators/verlet.js b/src/physics/integrators/verlet.js index 67c524bb..09282f57 100644 --- a/src/physics/integrators/verlet.js +++ b/src/physics/integrators/verlet.js @@ -1,7 +1,7 @@ -import { Vec2 } from "../../math/index.js" -let position = new Vec2() -let acceleration = new Vec2() -let velocity = new Vec2() +import { Vector2 } from "../../math/index.js" +let position = new Vector2() +let acceleration = new Vector2() +let velocity = new Vector2() /** * Verlet intergration. diff --git a/src/physics/narrowphase/SATNarrowphase.js b/src/physics/narrowphase/SATNarrowphase.js index b9743092..ae34ad8c 100644 --- a/src/physics/narrowphase/SATNarrowphase.js +++ b/src/physics/narrowphase/SATNarrowphase.js @@ -1,4 +1,4 @@ -import { Vec2, naturalizePair } from "../../math/index.js" +import { Vector2, naturalizePair } from "../../math/index.js" import { SAT } from "../SAT/index.js"; import { NarrowPhase } from "./Narrowphase.js" @@ -26,7 +26,7 @@ export class SATNarrowPhase extends NarrowPhase { lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vec2(), + axis: new Vector2(), verticesA: [], verticesB: [], vertShapeA: null, @@ -39,13 +39,13 @@ export class SATNarrowPhase extends NarrowPhase { stmp: -1, impulse: 0, persistent: false, - ca1: new Vec2(), - ca2: new Vec2(), + ca1: new Vector2(), + ca2: new Vector2(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vec2(), - velB: new Vec2(), + velA: new Vector2(), + velB: new Vector2(), rotA: 0, rotB: 0 }) @@ -56,13 +56,13 @@ export class SATNarrowPhase extends NarrowPhase { SAT.shapesInBodyCollided(a, b, collisionData) if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vec2.lerp( + Vector2.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position) - Vec2.lerp( + Vector2.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, diff --git a/src/physics/shapes/circle.js b/src/physics/shapes/circle.js index eeea905d..d02bcc26 100644 --- a/src/physics/shapes/circle.js +++ b/src/physics/shapes/circle.js @@ -1,8 +1,8 @@ import { Shape } from "./shape.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" -let _vec1 = new Vec2() -let _vec2 = new Vec2() +let _vec1 = new Vector2() +let _vec2 = new Vector2() let _arr = [] /** @@ -16,14 +16,14 @@ class Circle extends Shape { radius = 0 /** * @param {number} radius - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(radius, offset, offsetAngle) { //the first vertex is position super([], offset, offsetAngle) - this.vertices = [new Vec2(), new Vec2(), new Vec2()] + this.vertices = [new Vector2(), new Vector2(), new Vector2()] this.radius = radius this.type = Shape.CIRCLE } @@ -41,9 +41,9 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} axis - * @param { Vec2[]} out - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} out + * @returns { Vector2[]} */ getVertices(axis, out) { let target = out || [] @@ -56,8 +56,8 @@ class Circle extends Shape { /** * * @param {Shape} shape - * @param { Vec2[]} [target=[]] target - * @returns Array< Vec2> + * @param { Vector2[]} [target=[]] target + * @returns Array< Vector2> */ getNormals(shape, target = []) { let min = null, @@ -76,7 +76,7 @@ class Circle extends Shape { /** * @inheritdoc * - * @param { Vec2} position + * @param { Vector2} position * @param {number} angle * @param {number} scale */ @@ -100,7 +100,7 @@ class Circle extends Shape { fromJson(obj) { return new Circle( obj.radius, - new Vec2().fromJson(obj.offset), + new Vector2().fromJson(obj.offset), obj.offAngle ) } diff --git a/src/physics/shapes/geometry.js b/src/physics/shapes/geometry.js index 6be5b52a..1d723e13 100644 --- a/src/physics/shapes/geometry.js +++ b/src/physics/shapes/geometry.js @@ -1,18 +1,18 @@ class Geometry { /** - * @type Vec2[] + * @type Vector2[] */ vertices = null /** - * @type Vec2[] + * @type Vector2[] */ normals = null /** - * @type Vec2[] + * @type Vector2[] */ _dynNormals = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices @@ -33,7 +33,7 @@ class Geometry { } /** * @param {number} rad - * @param { Vec2[]} target + * @param { Vector2[]} target */ getNormals(rad, target) { target = target || [] @@ -44,7 +44,7 @@ class Geometry { } /** * @private - * @returns Vec2[] + * @returns Vector2[] */ calcFaceNormals() { const axes = [], @@ -66,8 +66,8 @@ class Geometry { } /** * @param {number} n - * @param { Vec2[]} vertices - * @param { Vec2} pos + * @param { Vector2[]} vertices + * @param { Vector2} pos * @patam {number} rad */ transform(vertices, pos, rad, n) { @@ -86,7 +86,7 @@ class Geometry { return obj } fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vec2().fromJson(v)) + this.vertices = obj.vertices.map(v=>new Vector2().fromJson(v)) this.normals = this.calcFaceNormals() this._dynNormals = this.normals.map(e => e.clone()) } diff --git a/src/physics/shapes/line.js b/src/physics/shapes/line.js index 9cab64ce..f572c4b8 100644 --- a/src/physics/shapes/line.js +++ b/src/physics/shapes/line.js @@ -1,5 +1,5 @@ import { Shape } from "./shape.js" -import { Vec2 }from "../../math/index.js" +import { Vector2 }from "../../math/index.js" class Line extends Shape { /** @@ -8,12 +8,12 @@ class Line extends Shape { length = 0 /** * @param {number} length - * @param { Vec2} offset + * @param { Vector2} offset * @param {number} pffsetAngle */ constructor(length,offset,offsetAngle) { - let start = new Vec2(1).multiply(length / 2), - end = new Vec2(1).multiply(-length / 2) + let start = new Vector2(1).multiply(length / 2), + end = new Vector2(1).multiply(-length / 2) super([start, end],offset,offsetAngle) this.length = length } diff --git a/src/physics/shapes/rectangle.js b/src/physics/shapes/rectangle.js index fb1a340f..be7754c5 100644 --- a/src/physics/shapes/rectangle.js +++ b/src/physics/shapes/rectangle.js @@ -1,5 +1,5 @@ import { Shape } from "./shape.js" -import { Vec2, sq }from "../../math/index.js" +import { Vector2, sq }from "../../math/index.js" class Rectangle extends Shape { /** @@ -13,14 +13,14 @@ class Rectangle extends Shape { /** * @param {number} width * @param {number} height - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vec2(-width / 2, -height / 2) - let v2 = new Vec2(-width / 2, height / 2) - let v3 = new Vec2(width / 2, height / 2) - let v4 = new Vec2(width / 2, -height / 2) + let v1 = new Vector2(-width / 2, -height / 2) + let v2 = new Vector2(-width / 2, height / 2) + let v3 = new Vector2(width / 2, height / 2) + let v4 = new Vector2(width / 2, -height / 2) super([v1, v2, v3, v4], offset, offsetAngle) this.height = height this.width = width diff --git a/src/physics/shapes/shape.js b/src/physics/shapes/shape.js index f7316ea7..37ed2e3c 100644 --- a/src/physics/shapes/shape.js +++ b/src/physics/shapes/shape.js @@ -1,8 +1,8 @@ -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" import { Geometry } from "./geometry.js" import { ShapeType } from "../settings.js" -let tmp1 = new Vec2() +let tmp1 = new Vector2() /** * This class makes a body tangible @@ -25,13 +25,13 @@ class Shape { /** * The offset position of this shape from this body's position. * - * @type Vec2 + * @type Vector2 */ offPosition = null /** * The vertices describing the shape. * - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -42,11 +42,11 @@ class Shape { geometry = null /** - * @param { Vec2[]} vertices The vertices of the shape in local space coordinates. - * @param { Vec2} [offset=vector] offset position relative to parent body + * @param { Vector2[]} vertices The vertices of the shape in local space coordinates. + * @param { Vector2} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vec2(), offsetAngle = 0) { + constructor(vertices, offset = new Vector2(), offsetAngle = 0) { this.offPosition = offset this.offAngle = offsetAngle * Math.PI / 180 this.vertices = vertices.map(v => v.clone()) @@ -75,8 +75,8 @@ class Shape { * Returns the normals of the faces when rotated. * * @param {Shape} shape - * @param { Vec2[]} [target=[]] An array where results are stored. - * @returns { Vec2[]} + * @param { Vector2[]} [target=[]] An array where results are stored. + * @returns { Vector2[]} */ getNormals(shape, target) { return this.geometry.getNormals(this.angle, target) @@ -84,7 +84,7 @@ class Shape { /** * Transforms the local coordinates of the vertices to world coordinates. * - * @param { Vec2} position the world position of the body + * @param { Vector2} position the world position of the body * @param {number} angle the orientation of body * @param {number} scale the scale of the body */ @@ -96,9 +96,9 @@ class Shape { /** * Returns the world coordinates of the vertices. * - * @param { Vec2} axis - * @param { Vec2[]} target - * @returns { Vec2[]} + * @param { Vector2} axis + * @param { Vector2[]} target + * @returns { Vector2[]} */ getVertices(axis, target) { return this.vertices diff --git a/src/physics/shapes/triangle.js b/src/physics/shapes/triangle.js index 8bba419b..e7ed8577 100644 --- a/src/physics/shapes/triangle.js +++ b/src/physics/shapes/triangle.js @@ -1,7 +1,7 @@ import { Shape } from "./shape.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" -let tmp1 = new Vec2() +let tmp1 = new Vector2() /** * A triangular shape. @@ -13,16 +13,16 @@ class Triangle extends Shape { * @param {number} base Length of one side. * @param {number} height Length of a second side. * @param {number} angle The angle between the two sides. - * @param { Vec2} offset Positional offset from the body center. + * @param { Vector2} offset Positional offset from the body center. * @param {number} offsetAngle Angular offset from the body center. * */ constructor(base, height, angle, offset, offsetAngle) { - let l1 = new Vec2().set(1, 0).multiply(base) - let l2 = Vec2.fromRad(angle).multiply(height/Math.sin(angle)) + let l1 = new Vector2().set(1, 0).multiply(base) + let l2 = Vector2.fromRad(angle).multiply(height/Math.sin(angle)) let center = tmp1.set((l1.x + l2.x) / 3, l2.y / 3) super([ - new Vec2().sub(center), + new Vector2().sub(center), l1.sub(center), l2.sub(center) ], offset, offsetAngle) diff --git a/src/physics/solvers/frictionSolver.js b/src/physics/solvers/frictionSolver.js index cd4d3421..fe72bfd3 100644 --- a/src/physics/solvers/frictionSolver.js +++ b/src/physics/solvers/frictionSolver.js @@ -1,10 +1,10 @@ -import { Vec2, sq }from "../../math/index.js" +import { Vector2, sq }from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2(), - tmp3 = new Vec2(), - tmp4 = new Vec2(), - tmp5 = new Vec2() +let tmp1 = new Vector2(), + tmp2 = new Vector2(), + tmp3 = new Vector2(), + tmp4 = new Vector2(), + tmp5 = new Vector2() /** * Solves for impulse along collision tangent for a given body pair. diff --git a/src/physics/solvers/impulseSolver.js b/src/physics/solvers/impulseSolver.js index 730d519e..931d418c 100644 --- a/src/physics/solvers/impulseSolver.js +++ b/src/physics/solvers/impulseSolver.js @@ -1,8 +1,8 @@ -import { Vec2, sq }from "../../math/index.js" -let tmp1 = new Vec2(), - tmp2 = new Vec2(), - tmp3 = new Vec2(), - tmp4 = new Vec2() +import { Vector2, sq }from "../../math/index.js" +let tmp1 = new Vector2(), + tmp2 = new Vector2(), + tmp3 = new Vector2(), + tmp4 = new Vector2() /** * Solves for the collision normal impulse of a given body pair. diff --git a/src/physics/solvers/penetrationSolver.js b/src/physics/solvers/penetrationSolver.js index 98f5acdd..d2695cfa 100644 --- a/src/physics/solvers/penetrationSolver.js +++ b/src/physics/solvers/penetrationSolver.js @@ -1,7 +1,7 @@ -import { Vec2, sq }from "../../math/index.js" +import { Vector2, sq }from "../../math/index.js" import { Settings } from "../settings.js" -const tmp1 = new Vec2(), - tmp2 = new Vec2() +const tmp1 = new Vector2(), + tmp2 = new Vector2() let dampen = Settings.posDampen /** diff --git a/src/physics/world/index.js b/src/physics/world/index.js index bfd4d68c..396149fc 100644 --- a/src/physics/world/index.js +++ b/src/physics/world/index.js @@ -1,6 +1,6 @@ import { VerletSolver } from "../integrators/index.js"; import { PenetrationSolver, FrictionSolver, ImpulseSolver, ContactSolver } from "../solvers/index.js"; -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" import { Utils } from "../../utils/index.js" import { ObjType } from "../settings.js" import { NaiveBroadphase } from "../broadphases/index.js" @@ -81,9 +81,9 @@ export class World { /** * The gravitational pull of the world. * - * @type Vec2 + * @type Vector2 */ - gravitationalAcceleration = new Vec2(0, 0) + gravitationalAcceleration = new Vector2(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -136,7 +136,7 @@ export class World { /** * Gravitational pull of the world,will affect all bodies except static bodies. * - * @type { Vec2 } + * @type { Vector2 } */ get gravity() { return this.gravitationalAcceleration diff --git a/src/render/camController.js b/src/render/camController.js index 135aad31..082dab5c 100644 --- a/src/render/camController.js +++ b/src/render/camController.js @@ -1,22 +1,22 @@ -import { Vec2 } from '../math/index.js' +import { Vector2 } from '../math/index.js' export class CamController { /** * @readonly - * @type Vec2 + * @type Vector2 */ - offset = new Vec2() + offset = new Vector2() /** * @param {Camera} camera */ constructor(camera) { this.transform = camera.transform - this.offset = new Vec2() + this.offset = new Vector2() this.targetPosition = null this.targetOrientation = null } /** - * @param { Vec2} position + * @param { Vector2} position * @param {Angle} orientation */ follow(position, orientation = null) { diff --git a/src/render/camera.js b/src/render/camera.js index 672ee890..ba0e2ca1 100644 --- a/src/render/camera.js +++ b/src/render/camera.js @@ -8,7 +8,7 @@ class Camera { constructor() { } /** - * @type Vec2 + * @type Vector2 */ get position() { return this.transform.position diff --git a/src/render/geometry/geometry.js b/src/render/geometry/geometry.js index 17a365af..3e60dd18 100644 --- a/src/render/geometry/geometry.js +++ b/src/render/geometry/geometry.js @@ -1,10 +1,10 @@ -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" import { vertices } from "../utils/index.js" export class BufferGeometry { /** * @readonly - * @type Vec2[] + * @type Vector2[] */ vertices = null /** @@ -13,7 +13,7 @@ export class BufferGeometry { */ drawable = null /** - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices */ constructor(vertices) { this.vertices = vertices || [] diff --git a/src/render/sprites/AgentSprite.js b/src/render/sprites/AgentSprite.js index 6b32d2cb..b0cefde8 100644 --- a/src/render/sprites/AgentSprite.js +++ b/src/render/sprites/AgentSprite.js @@ -1,12 +1,12 @@ import { Sprite } from "./sprite.js" import { BufferGeometry } from "../geometry/index.js" import { BasicMaterial } from "../material/index.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" let geometry = new BufferGeometry([ - new Vec2(-10, -10), - new Vec2(-10, 10), - new Vec2(20, 0) + new Vector2(-10, -10), + new Vector2(-10, 10), + new Vector2(20, 0) ]) let material = new BasicMaterial() material.fill = "purple" diff --git a/src/render/sprites/bodysprite.js b/src/render/sprites/bodysprite.js index eedd6dcb..49d5ea34 100644 --- a/src/render/sprites/bodysprite.js +++ b/src/render/sprites/bodysprite.js @@ -1,5 +1,5 @@ import { Sprite } from "./sprite.js" -import { Vec2 } from "../../math/index.js" +import { Vector2 } from "../../math/index.js" import { Shape } from "../../physics/index.js" import { BasicMaterial } from "../material/index.js" import { ObjType } from "../../physics/settings.js" @@ -7,7 +7,7 @@ import { circle, rect, vertices, stroke, fill, line } from "../utils/index.js" -let r = new Vec2() +let r = new Vector2() let material = new BasicMaterial() material.wireframe = true /** @@ -135,7 +135,7 @@ class BodySprite extends Sprite { shape.position.x, shape.position.y, shape.radius) - Vec2.fromRad(shape.angle, r).multiply(shape.radius) + Vector2.fromRad(shape.angle, r).multiply(shape.radius) line(ctx, ...shape.position, shape.position.x + r.x, shape.position.y + r.y) diff --git a/src/render/sprites/particleSystem.js b/src/render/sprites/particleSystem.js index f1e2ac93..0b3118ba 100644 --- a/src/render/sprites/particleSystem.js +++ b/src/render/sprites/particleSystem.js @@ -1,5 +1,5 @@ import { Sprite } from "./sprite.js" -import { Vec2, rand } from "../../math/index.js" +import { Vector2, rand } from "../../math/index.js" import { circle, fill } from "../utils/index.js" /** @@ -8,12 +8,12 @@ import { circle, fill } from "../utils/index.js" class Particle { /** * @readonly - * @type Vec2 + * @type Vector2 */ position = null /** * @readonly - * @type Vec2 + * @type Vector2 */ velocity = null /** @@ -39,13 +39,13 @@ class Particle { */ lifespan = 0 /** - * @param { Vec2} pos + * @param { Vector2} pos * @param {number} radius * @param {number} [lifespan=5] In seconds */ constructor(pos, radius, lifespan = 5) { this.position = pos - this.velocity = new Vec2() + this.velocity = new Vector2() this.radius = radius this.color = { r: 100, @@ -133,7 +133,7 @@ class ParticleSystemSprite extends Sprite { */ create() { return new Particle( - new Vec2(...this.position), + new Vector2(...this.position), rand(1, 10), rand(1, 6) ) diff --git a/src/render/sprites/sprite.js b/src/render/sprites/sprite.js index 70297a50..640397ad 100644 --- a/src/render/sprites/sprite.js +++ b/src/render/sprites/sprite.js @@ -1,5 +1,5 @@ -import { Vec2, Angle } from "../../math/index.js" -import { Utils } from "../../utils/index.js" +import { Vector2, Angle } from "../../math/index.js" +import { Component } from "../../ecs/index.js" /** * This is the base class used to render images and paths onto the renderer. @@ -55,7 +55,7 @@ class Sprite { /** * World space position. * - * @type Vec2 + * @type Vector2 */ get position() { return this._position @@ -89,9 +89,9 @@ class Sprite { */ init(entity) { if(!entity){ - this._position = new Vec2() + this._position = new Vector2() this._orientation = new Angle() - this._scale = new Vec2(1,1) + this._scale = new Vector2(1,1) return } this.entity = entity @@ -100,7 +100,7 @@ class Sprite { this._position = transform.position this._orientation = transform.orientation //TODO - Correct this later - this._scale = new Vec2(1,1) + this._scale = new Vector2(1,1) return this } toJson(){ @@ -121,7 +121,7 @@ class Sprite { this.parent = renderer.getById(obj.parent) } } -Utils.inheritComponent(Sprite) +Component.implement(Sprite) export { Sprite } \ No newline at end of file diff --git a/src/render/utils/canvasfunc.js b/src/render/utils/canvasfunc.js index 9c64ec97..b3ae438f 100644 --- a/src/render/utils/canvasfunc.js +++ b/src/render/utils/canvasfunc.js @@ -30,7 +30,7 @@ export function circle(ctx, x, y, r) { } /** * @param {CanvasRenderingContext2D} ctx - * @param { Vec2[]} vertices + * @param { Vector2[]} vertices * @param {boolean} [close=true] */ export function vertices(ctx, vertices, close = true) { diff --git a/src/typedef/manifold.js b/src/typedef/manifold.js index 793a4288..9ed559e6 100644 --- a/src/typedef/manifold.js +++ b/src/typedef/manifold.js @@ -12,13 +12,13 @@ * @property {number} stmp * @property {number} impulse * @property {boolean} persistent - * @property { Vec2} ca1 - * @property { Vec2} ca2 + * @property { Vector2} ca1 + * @property { Vector2} ca2 * @property {number} restitution * @property {number} staticFriction * @property {number} kineticFriction - * @property { Vec2} velA - * @property { Vec2} velB + * @property { Vector2} velA + * @property { Vector2} velB * @property {number} rotA * @property {number} rotB */ @@ -28,9 +28,9 @@ * @property {number} lastOverlap * @property {number} overlap=-Infinity * @property {boolean} done=false - * @property { Vec2} axis - * @property { Vec2[]} verticesA - * @property { Vec2[]} verticesB + * @property { Vector2} axis + * @property { Vector2[]} verticesA + * @property { Vector2[]} verticesB * @property {Shape} vertShapeA * @property {Shape} vertShapeB * @property {number} contactNo diff --git a/src/utils/common.js b/src/utils/common.js index a1511a08..5bd26ca4 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -145,35 +145,23 @@ Utils.inheritComponent = function(component, overrideInit = true, overrideUpdate }) } /** - * Mixes the functions required by a system into a class. + * Mixes the functions required by an object into another object. * * @memberof Utils - * @param {Function} system the class constructor function to add methods to. + * @param {Object} from the object constructor function to add methods from. + * @param {Object} to the object constructor function to add methods to. */ -Utils.inheritSystem = function(system) { - if (system == void 0 || typeof system !== "function") return - let proto = system.prototype - if (!proto.init) { - proto.init = function() { - Err.warnOnce("Please override the init method in the system " + proto.constructor.name) - } - } - if (!proto.update) { - proto.update = function() { - Err.warnOnce("Please override the update method in the system " + proto.constructor.name) - - } - } - if (!proto.add) { - proto.add = function(component) { - this.objects.push(component) - } - } - - if (!proto.remove) { - proto.remove = function(component) { - let index = this.objects.indexOf(component) - Utils.removeElement(this.objects, index) - } +export function mixin(from, to,props = []) { + let proto = from.prototype + let proto2 = to.prototype + console.log(proto2); + Object.assign(proto,from) + for (let name of props) { + let methodName = props[name] + //if(!(methodName in proto))continue + //if (methodName in proto2) continue + + proto2[name] = proto[name] } + //console.log(new to()); } \ No newline at end of file