diff --git a/src/data/collision/body.ts b/src/data/collision/body.ts index 11676df..fbada22 100644 --- a/src/data/collision/body.ts +++ b/src/data/collision/body.ts @@ -1,3 +1,4 @@ +import { PhysicsBody } from "."; import { CollisionMask } from "./collisionMask"; // Random value that determines how much gravity a body must receive before something is considered a collision with the ground/ceiling @@ -22,7 +23,7 @@ interface Config { roundness?: number; } -export class Body { +export class Body implements PhysicsBody { public active = 1; private xVelocity = 0; diff --git a/src/data/collision/index.ts b/src/data/collision/index.ts new file mode 100644 index 0000000..2859afd --- /dev/null +++ b/src/data/collision/index.ts @@ -0,0 +1,5 @@ +export interface PhysicsBody { + addVelocity(x: number, y: number): void; + addAngularVelocity(power: number, direction: number): void; + tick(dt: number): boolean; +} diff --git a/src/data/collision/simpleBody.ts b/src/data/collision/simpleBody.ts index 104160d..07e4e0f 100644 --- a/src/data/collision/simpleBody.ts +++ b/src/data/collision/simpleBody.ts @@ -1,3 +1,4 @@ +import { PhysicsBody } from "."; import { CollisionMask } from "./collisionMask"; const GRAVITY = 0.3; @@ -12,7 +13,7 @@ interface Config { onCollide?: (x: number, y: number) => void; } -export class SimpleBody { +export class SimpleBody implements PhysicsBody { private xVelocity = 0; private yVelocity = 0; @@ -105,6 +106,8 @@ export class SimpleBody { ) { this.onCollide(xCollision || x, yCollision || y); } + + return true; } get velocity() {