summaryrefslogtreecommitdiff
path: root/engine/systems
diff options
context:
space:
mode:
Diffstat (limited to 'engine/systems')
-rw-r--r--engine/systems/Collision.ts54
-rw-r--r--engine/systems/FacingDirection.ts14
-rw-r--r--engine/systems/Input.ts20
-rw-r--r--engine/systems/NetworkUpdate.ts16
-rw-r--r--engine/systems/Physics.ts32
-rw-r--r--engine/systems/Render.ts16
-rw-r--r--engine/systems/System.ts2
-rw-r--r--engine/systems/WallBounds.ts20
-rw-r--r--engine/systems/index.ts18
-rw-r--r--engine/systems/names.ts14
10 files changed, 101 insertions, 105 deletions
diff --git a/engine/systems/Collision.ts b/engine/systems/Collision.ts
index 2dd920e..4a838dd 100644
--- a/engine/systems/Collision.ts
+++ b/engine/systems/Collision.ts
@@ -1,22 +1,22 @@
-import { SystemNames, System } from ".";
+import { SystemNames, System } from '.';
import {
Mass,
BoundingBox,
ComponentNames,
Jump,
Velocity,
- Forces,
-} from "../components";
-import { Game } from "../Game";
-import { Miscellaneous, PhysicsConstants } from "../config";
-import { Entity } from "../entities";
-import type { Coord2D, Dimension2D, Velocity2D } from "../interfaces";
-import { BoxedEntry, RefreshingCollisionFinderBehavior } from "../structures";
+ Forces
+} from '../components';
+import { Game } from '../Game';
+import { Miscellaneous, PhysicsConstants } from '../config';
+import { Entity } from '../entities';
+import type { Coord2D, Dimension2D, Velocity2D } from '../interfaces';
+import { BoxedEntry, RefreshingCollisionFinderBehavior } from '../structures';
export class Collision extends System {
private static readonly COLLIDABLE_COMPONENT_NAMES = [
ComponentNames.Collide,
- ComponentNames.TopCollidable,
+ ComponentNames.TopCollidable
];
private collisionFinder: RefreshingCollisionFinderBehavior;
@@ -38,7 +38,7 @@ export class Collision extends System {
return;
}
entitiesToAddToCollisionFinder.push(entity);
- }),
+ })
);
this.insertEntitiesAndUpdateBounds(entitiesToAddToCollisionFinder);
@@ -53,7 +53,7 @@ export class Collision extends System {
entities.forEach((entity) => {
const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
let dimension = { ...boundingBox.dimension };
@@ -73,7 +73,7 @@ export class Collision extends System {
collisionFinderInsertions.push({
id: entity.id,
dimension,
- center,
+ center
});
});
@@ -82,13 +82,13 @@ export class Collision extends System {
this.collisionFinder.setTopLeft(topLeft);
this.collisionFinder.setDimension({
width: bottomRight.x - topLeft.x,
- height: bottomRight.y - topLeft.y,
+ height: bottomRight.y - topLeft.y
});
}
// then, begin insertions
collisionFinderInsertions.forEach((boxedEntry: BoxedEntry) =>
- this.collisionFinder.insert(boxedEntry),
+ this.collisionFinder.insert(boxedEntry)
);
}
@@ -97,7 +97,7 @@ export class Collision extends System {
collidingEntities.forEach(([entityAId, entityBId]) => {
const [entityA, entityB] = [entityAId, entityBId].map((id) =>
- game.entities.get(id),
+ game.entities.get(id)
);
if (entityA && entityB) {
this.performCollision(entityA, entityB);
@@ -107,13 +107,13 @@ export class Collision extends System {
private performCollision(entityA: Entity, entityB: Entity) {
const [entityABoundingBox, entityBBoundingBox] = [entityA, entityB].map(
- (entity) => entity.getComponent<BoundingBox>(ComponentNames.BoundingBox),
+ (entity) => entity.getComponent<BoundingBox>(ComponentNames.BoundingBox)
);
let velocity: Velocity2D = { dCartesian: { dx: 0, dy: 0 }, dTheta: 0 };
if (entityA.hasComponent(ComponentNames.Velocity)) {
velocity = entityA.getComponent<Velocity>(
- ComponentNames.Velocity,
+ ComponentNames.Velocity
).velocity;
}
@@ -125,7 +125,7 @@ export class Collision extends System {
) {
if (entityBBoundingBox.rotation != 0) {
throw new Error(
- `entity with id ${entityB.id} has TopCollidable component and a non-zero rotation. that is not (yet) supported.`,
+ `entity with id ${entityB.id} has TopCollidable component and a non-zero rotation. that is not (yet) supported.`
);
}
@@ -139,7 +139,7 @@ export class Collision extends System {
entityA.getComponent<Forces>(ComponentNames.Forces).forces.push({
fCartesian: { fy: F_n, fx: 0 },
- torque: 0,
+ torque: 0
});
}
@@ -157,19 +157,19 @@ export class Collision extends System {
private getCollidingEntities(
collidableEntities: Entity[],
- game: Game,
+ game: Game
): [string, string][] {
const collidingEntityIds: [string, string][] = [];
for (const entity of collidableEntities) {
const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
const neighborIds = this.collisionFinder.getNeighborIds({
id: entity.id,
dimension: boundingBox.dimension,
- center: boundingBox.center,
+ center: boundingBox.center
});
for (const neighborId of neighborIds) {
@@ -177,7 +177,7 @@ export class Collision extends System {
if (!neighbor) return;
const neighborBoundingBox = neighbor.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
if (boundingBox.isCollidingWith(neighborBoundingBox)) {
@@ -192,11 +192,11 @@ export class Collision extends System {
// ramblings: https://excalidraw.com/#json=z-xD86Za4a3duZuV2Oky0,KaGe-5iHJu1Si8inEo4GLQ
private getDyToPushOutOfFloor(
entityBoundingBox: BoundingBox,
- floorBoundingBox: BoundingBox,
+ floorBoundingBox: BoundingBox
): number {
const {
dimension: { width, height },
- center: { x },
+ center: { x }
} = entityBoundingBox;
const outScribedRectangle = entityBoundingBox.getOutscribedBoxDims();
@@ -215,7 +215,7 @@ export class Collision extends System {
if (x >= floorBoundingBox.center.x) {
boundedCollisionX = Math.min(
floorBoundingBox.center.x + floorBoundingBox.dimension.width / 2,
- clippedX,
+ clippedX
);
return (
outScribedRectangle.height / 2 -
@@ -225,7 +225,7 @@ export class Collision extends System {
boundedCollisionX = Math.max(
floorBoundingBox.center.x - floorBoundingBox.dimension.width / 2,
- clippedX,
+ clippedX
);
return (
diff --git a/engine/systems/FacingDirection.ts b/engine/systems/FacingDirection.ts
index daf639f..01f32cf 100644
--- a/engine/systems/FacingDirection.ts
+++ b/engine/systems/FacingDirection.ts
@@ -2,10 +2,10 @@ import {
ComponentNames,
Velocity,
FacingDirection as FacingDirectionComponent,
- Control,
-} from "../components";
-import { Game } from "../Game";
-import { System, SystemNames } from "./";
+ Control
+} from '../components';
+import { Game } from '../Game';
+import { System, SystemNames } from './';
export class FacingDirection extends System {
constructor() {
@@ -23,7 +23,7 @@ export class FacingDirection extends System {
const totalVelocityComponent = new Velocity();
const control = entity.getComponent<Control>(ComponentNames.Control);
const velocity = entity.getComponent<Velocity>(
- ComponentNames.Velocity,
+ ComponentNames.Velocity
).velocity;
totalVelocityComponent.add(velocity);
@@ -32,7 +32,7 @@ export class FacingDirection extends System {
}
const facingDirection = entity.getComponent<FacingDirectionComponent>(
- ComponentNames.FacingDirection,
+ ComponentNames.FacingDirection
);
if (totalVelocityComponent.velocity.dCartesian.dx > 0) {
@@ -40,7 +40,7 @@ export class FacingDirection extends System {
} else if (totalVelocityComponent.velocity.dCartesian.dx < 0) {
entity.addComponent(facingDirection.facingLeftSprite);
}
- },
+ }
);
}
}
diff --git a/engine/systems/Input.ts b/engine/systems/Input.ts
index a32ba9a..4a5a3c3 100644
--- a/engine/systems/Input.ts
+++ b/engine/systems/Input.ts
@@ -4,12 +4,12 @@ import {
ComponentNames,
Velocity,
Mass,
- Control,
-} from "../components";
-import { Game } from "../Game";
-import { KeyConstants, PhysicsConstants } from "../config";
-import { Action } from "../interfaces";
-import { System, SystemNames } from ".";
+ Control
+} from '../components';
+import { Game } from '../Game';
+import { KeyConstants, PhysicsConstants } from '../config';
+import { Action } from '../interfaces';
+import { System, SystemNames } from '.';
export class Input extends System {
public clientId: string;
@@ -42,7 +42,7 @@ export class Input extends System {
public update(_dt: number, game: Game) {
game.forEachEntityWithComponent(ComponentNames.Control, (entity) => {
const controlComponent = entity.getComponent<Control>(
- ComponentNames.Control,
+ ComponentNames.Control
);
if (controlComponent.controllableBy != this.clientId) return;
@@ -58,7 +58,7 @@ export class Input extends System {
if (entity.hasComponent(ComponentNames.Jump)) {
const velocity = entity.getComponent<Velocity>(
- ComponentNames.Velocity,
+ ComponentNames.Velocity
).velocity;
const jump = entity.getComponent<Jump>(ComponentNames.Jump);
@@ -78,9 +78,9 @@ export class Input extends System {
entity.getComponent<Forces>(ComponentNames.Forces)?.forces.push({
fCartesian: {
fy: mass * PhysicsConstants.PLAYER_JUMP_ACC,
- fx: 0,
+ fx: 0
},
- torque: 0,
+ torque: 0
});
}
}
diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts
index 6c1d3e4..bcfb71e 100644
--- a/engine/systems/NetworkUpdate.ts
+++ b/engine/systems/NetworkUpdate.ts
@@ -1,11 +1,11 @@
-import { System, SystemNames } from ".";
-import { Game } from "../Game";
-import { ComponentNames, NetworkUpdateable } from "../components";
+import { System, SystemNames } from '.';
+import { Game } from '../Game';
+import { ComponentNames, NetworkUpdateable } from '../components';
import {
type MessageQueueProvider,
type MessagePublisher,
- type MessageProcessor,
-} from "../network";
+ type MessageProcessor
+} from '../network';
export class NetworkUpdate extends System {
private queueProvider: MessageQueueProvider;
@@ -15,7 +15,7 @@ export class NetworkUpdate extends System {
constructor(
queueProvider: MessageQueueProvider,
publisher: MessagePublisher,
- messageProcessor: MessageProcessor,
+ messageProcessor: MessageProcessor
) {
super(SystemNames.NetworkUpdate);
@@ -34,9 +34,9 @@ export class NetworkUpdate extends System {
ComponentNames.NetworkUpdateable,
(entity) => {
const networkUpdateComponent = entity.getComponent<NetworkUpdateable>(
- ComponentNames.NetworkUpdateable,
+ ComponentNames.NetworkUpdateable
);
- },
+ }
);
this.publisher.publish();
diff --git a/engine/systems/Physics.ts b/engine/systems/Physics.ts
index e324c97..35afb3f 100644
--- a/engine/systems/Physics.ts
+++ b/engine/systems/Physics.ts
@@ -1,4 +1,4 @@
-import { System, SystemNames } from ".";
+import { System, SystemNames } from '.';
import {
BoundingBox,
ComponentNames,
@@ -8,11 +8,11 @@ import {
Mass,
Jump,
Moment,
- Control,
-} from "../components";
-import { PhysicsConstants } from "../config";
-import type { Force2D, Velocity2D } from "../interfaces";
-import { Game } from "../Game";
+ Control
+} from '../components';
+import { PhysicsConstants } from '../config';
+import type { Force2D, Velocity2D } from '../interfaces';
+import { Game } from '../Game';
export class Physics extends System {
constructor() {
@@ -24,10 +24,10 @@ export class Physics extends System {
const mass = entity.getComponent<Mass>(ComponentNames.Mass).mass;
const forces = entity.getComponent<Forces>(ComponentNames.Forces).forces;
const velocity = entity.getComponent<Velocity>(
- ComponentNames.Velocity,
+ ComponentNames.Velocity
).velocity;
const inertia = entity.getComponent<Moment>(
- ComponentNames.Moment,
+ ComponentNames.Moment
).inertia;
// F_g = mg, applied only until terminal velocity is reached
@@ -37,9 +37,9 @@ export class Physics extends System {
forces.push({
fCartesian: {
fy: mass * PhysicsConstants.GRAVITY,
- fx: 0,
+ fx: 0
},
- torque: 0,
+ torque: 0
});
}
}
@@ -49,17 +49,17 @@ export class Physics extends System {
(accum: Force2D, { fCartesian, torque }: Force2D) => ({
fCartesian: {
fx: accum.fCartesian.fx + (fCartesian?.fx ?? 0),
- fy: accum.fCartesian.fy + (fCartesian?.fy ?? 0),
+ fy: accum.fCartesian.fy + (fCartesian?.fy ?? 0)
},
- torque: accum.torque + (torque ?? 0),
+ torque: accum.torque + (torque ?? 0)
}),
- { fCartesian: { fx: 0, fy: 0 }, torque: 0 },
+ { fCartesian: { fx: 0, fy: 0 }, torque: 0 }
);
// integrate accelerations
const [ddy, ddx] = [
sumOfForces.fCartesian.fy,
- sumOfForces.fCartesian.fx,
+ sumOfForces.fCartesian.fx
].map((x) => x / mass);
velocity.dCartesian.dx += ddx * dt;
velocity.dCartesian.dy += ddy * dt;
@@ -79,14 +79,14 @@ export class Physics extends System {
const control = entity.getComponent<Control>(ComponentNames.Control);
velocityComponent.add(
- entity.getComponent<Velocity>(ComponentNames.Velocity).velocity,
+ entity.getComponent<Velocity>(ComponentNames.Velocity).velocity
);
if (control) {
velocityComponent.add(control.controlVelocityComponent.velocity);
}
const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
// integrate velocity
diff --git a/engine/systems/Render.ts b/engine/systems/Render.ts
index 9bb4091..4a4500d 100644
--- a/engine/systems/Render.ts
+++ b/engine/systems/Render.ts
@@ -1,7 +1,7 @@
-import { System, SystemNames } from ".";
-import { BoundingBox, ComponentNames, Sprite } from "../components";
-import { Game } from "../Game";
-import { clamp } from "../utils";
+import { System, SystemNames } from '.';
+import { BoundingBox, ComponentNames, Sprite } from '../components';
+import { Game } from '../Game';
+import { clamp } from '../utils';
export class Render extends System {
private ctx: CanvasRenderingContext2D;
@@ -19,7 +19,7 @@ export class Render extends System {
sprite.update(dt);
const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
// don't render if we're outside the screen
@@ -27,12 +27,12 @@ export class Render extends System {
clamp(
boundingBox.center.y,
-boundingBox.dimension.height / 2,
- this.ctx.canvas.height + boundingBox.dimension.height / 2,
+ this.ctx.canvas.height + boundingBox.dimension.height / 2
) != boundingBox.center.y ||
clamp(
boundingBox.center.x,
-boundingBox.dimension.width / 2,
- this.ctx.canvas.width + boundingBox.dimension.width / 2,
+ this.ctx.canvas.width + boundingBox.dimension.width / 2
) != boundingBox.center.x
) {
return;
@@ -41,7 +41,7 @@ export class Render extends System {
const drawArgs = {
center: boundingBox.center,
dimension: boundingBox.dimension,
- rotation: boundingBox.rotation,
+ rotation: boundingBox.rotation
};
sprite.draw(this.ctx, drawArgs);
diff --git a/engine/systems/System.ts b/engine/systems/System.ts
index 8b00dc5..de41988 100644
--- a/engine/systems/System.ts
+++ b/engine/systems/System.ts
@@ -1,4 +1,4 @@
-import { Game } from "../Game";
+import { Game } from '../Game';
export abstract class System {
public readonly name: string;
diff --git a/engine/systems/WallBounds.ts b/engine/systems/WallBounds.ts
index a0d4a9c..7da84e4 100644
--- a/engine/systems/WallBounds.ts
+++ b/engine/systems/WallBounds.ts
@@ -1,28 +1,24 @@
-import { System, SystemNames } from ".";
-import { BoundingBox, ComponentNames } from "../components";
-import { Game } from "../Game";
-import type { Entity } from "../entities";
-import { clamp } from "../utils";
+import { System, SystemNames } from '.';
+import { BoundingBox, ComponentNames } from '../components';
+import { Game } from '../Game';
+import { clamp } from '../utils';
+import { Miscellaneous } from '../config';
export class WallBounds extends System {
- private screenWidth: number;
-
- constructor(screenWidth: number) {
+ constructor() {
super(SystemNames.WallBounds);
-
- this.screenWidth = screenWidth;
}
public update(_dt: number, game: Game) {
game.forEachEntityWithComponent(ComponentNames.WallBounded, (entity) => {
const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox,
+ ComponentNames.BoundingBox
);
boundingBox.center.x = clamp(
boundingBox.center.x,
boundingBox.dimension.width / 2,
- this.screenWidth - boundingBox.dimension.width / 2,
+ Miscellaneous.WIDTH - boundingBox.dimension.width / 2
);
});
}
diff --git a/engine/systems/index.ts b/engine/systems/index.ts
index 075fc4e..43181e9 100644
--- a/engine/systems/index.ts
+++ b/engine/systems/index.ts
@@ -1,9 +1,9 @@
-export * from "./names";
-export * from "./System";
-export * from "./Render";
-export * from "./Physics";
-export * from "./Input";
-export * from "./FacingDirection";
-export * from "./Collision";
-export * from "./WallBounds";
-export * from "./NetworkUpdate";
+export * from './names';
+export * from './System';
+export * from './Render';
+export * from './Physics';
+export * from './Input';
+export * from './FacingDirection';
+export * from './Collision';
+export * from './WallBounds';
+export * from './NetworkUpdate';
diff --git a/engine/systems/names.ts b/engine/systems/names.ts
index cf66422..ddf6f19 100644
--- a/engine/systems/names.ts
+++ b/engine/systems/names.ts
@@ -1,9 +1,9 @@
export namespace SystemNames {
- export const Render = "Render";
- export const Physics = "Physics";
- export const FacingDirection = "FacingDirection";
- export const Input = "Input";
- export const Collision = "Collision";
- export const WallBounds = "WallBounds";
- export const NetworkUpdate = "NetworkUpdate";
+ export const Render = 'Render';
+ export const Physics = 'Physics';
+ export const FacingDirection = 'FacingDirection';
+ export const Input = 'Input';
+ export const Collision = 'Collision';
+ export const WallBounds = 'WallBounds';
+ export const NetworkUpdate = 'NetworkUpdate';
}