Setup formatting
This commit is contained in:
parent
d34f25295c
commit
dd850d11d1
45 changed files with 230 additions and 190 deletions
|
|
@ -40,16 +40,18 @@ app.use(
|
|||
callback(null, true);
|
||||
},
|
||||
credentials: true,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
const port = 3000;
|
||||
const server = new Server(app);
|
||||
const io = ioserver(server);
|
||||
|
||||
/*
|
||||
const log = (text: string) => {
|
||||
io.to('insights').emit('insights', text + '\n');
|
||||
};
|
||||
*/
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.sendFile('dist/index.html', { root: '.' });
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const createDungeon = (objects: PhysicalContainer) => {
|
|||
previousEnd,
|
||||
currentEnd,
|
||||
previousRadius,
|
||||
currentToRadius
|
||||
currentToRadius,
|
||||
);
|
||||
|
||||
objects.addObject(tunnel);
|
||||
|
|
@ -31,10 +31,10 @@ export const createDungeon = (objects: PhysicalContainer) => {
|
|||
currentEnd,
|
||||
vec3.normalize(
|
||||
vec3.create(),
|
||||
vec3.fromValues(Random.getRandom(), 0, Random.getRandom())
|
||||
vec3.fromValues(Random.getRandom(), 0, Random.getRandom()),
|
||||
),
|
||||
0.5
|
||||
)
|
||||
0.5,
|
||||
),
|
||||
);
|
||||
tunnelsCountSinceLastLight = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,14 +44,14 @@ export class CharacterPhysical extends CharacterBase implements Physical {
|
|||
vec2.clone(CharacterPhysical.leftFootOffset),
|
||||
20,
|
||||
null,
|
||||
container
|
||||
container,
|
||||
),
|
||||
new CirclePhysical(
|
||||
vec2.clone(CharacterPhysical.rightFootOffset),
|
||||
20,
|
||||
null,
|
||||
container
|
||||
)
|
||||
container,
|
||||
),
|
||||
);
|
||||
|
||||
this.head.owner = this;
|
||||
|
|
@ -89,7 +89,7 @@ export class CharacterPhysical extends CharacterBase implements Physical {
|
|||
|
||||
const movementForce = this.movementActions.reduce(
|
||||
(sum, current) => vec2.add(sum, sum, current.delta),
|
||||
vec2.create()
|
||||
vec2.create(),
|
||||
);
|
||||
|
||||
vec2.scale(movementForce, movementForce, 1 / this.movementActions.length);
|
||||
|
|
@ -113,25 +113,25 @@ export class CharacterPhysical extends CharacterBase implements Physical {
|
|||
const bodyCenter = vec2.sub(
|
||||
vec2.create(),
|
||||
this.head.center,
|
||||
CharacterPhysical.headOffset
|
||||
CharacterPhysical.headOffset,
|
||||
);
|
||||
|
||||
const leftFootPositon = vec2.add(
|
||||
vec2.create(),
|
||||
bodyCenter,
|
||||
CharacterPhysical.leftFootOffset
|
||||
CharacterPhysical.leftFootOffset,
|
||||
);
|
||||
const rightFootPositon = vec2.add(
|
||||
vec2.create(),
|
||||
bodyCenter,
|
||||
CharacterPhysical.rightFootOffset
|
||||
CharacterPhysical.rightFootOffset,
|
||||
);
|
||||
|
||||
const leftFootDelta = vec2.sub(vec2.create(), this.leftFoot.center, leftFootPositon);
|
||||
const rightFootDelta = vec2.sub(
|
||||
vec2.create(),
|
||||
this.rightFoot.center,
|
||||
rightFootPositon
|
||||
rightFootPositon,
|
||||
);
|
||||
|
||||
vec2.scale(leftFootDelta, leftFootDelta, 0.0006);
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ export class CirclePhysical implements Circle, Physical {
|
|||
private _center: vec2,
|
||||
private _radius: number,
|
||||
public owner: GameObject,
|
||||
private readonly container: PhysicalContainer
|
||||
private readonly container: PhysicalContainer,
|
||||
) {
|
||||
this._boundingBox = new BoundingBox(null);
|
||||
this._boundingBox = new BoundingBox();
|
||||
this.recalculateBoundingBox();
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +93,8 @@ export class CirclePhysical implements Circle, Physical {
|
|||
result.push(
|
||||
vec2.fromValues(
|
||||
Math.cos((2 * Math.PI * i) / count) * this.radius + this.center.x,
|
||||
Math.sin((2 * Math.PI * i) / count) * this.radius + this.center.y
|
||||
)
|
||||
Math.sin((2 * Math.PI * i) / count) * this.radius + this.center.y,
|
||||
),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
|
|
@ -111,13 +111,13 @@ export class CirclePhysical implements Circle, Physical {
|
|||
vec2.add(
|
||||
this.velocity,
|
||||
this.velocity,
|
||||
vec2.scale(vec2.create(), force, timeInMilliseconds)
|
||||
vec2.scale(vec2.create(), force, timeInMilliseconds),
|
||||
);
|
||||
|
||||
vec2.set(
|
||||
this.velocity,
|
||||
clamp(this.velocity.x, -settings.maxVelocityX, settings.maxVelocityX),
|
||||
clamp(this.velocity.y, -settings.maxVelocityY, settings.maxVelocityY)
|
||||
clamp(this.velocity.y, -settings.maxVelocityY, settings.maxVelocityY),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ export class CirclePhysical implements Circle, Physical {
|
|||
vec2.scale(
|
||||
this.velocity,
|
||||
this.velocity,
|
||||
Math.pow(settings.velocityAttenuation, timeInMilliseconds)
|
||||
Math.pow(settings.velocityAttenuation, timeInMilliseconds),
|
||||
);
|
||||
|
||||
const distance = vec2.scale(vec2.create(), this.velocity, timeInMilliseconds);
|
||||
|
|
@ -140,13 +140,13 @@ export class CirclePhysical implements Circle, Physical {
|
|||
let wasHit = false;
|
||||
|
||||
for (let i = 0; i < stepCount; i++) {
|
||||
const { normal, tangent, hitSurface } = moveCircle(
|
||||
const { tangent, hitSurface } = moveCircle(
|
||||
this,
|
||||
distance,
|
||||
this.container.findIntersecting(this.boundingBox)
|
||||
this.container.findIntersecting(this.boundingBox),
|
||||
);
|
||||
if (hitSurface) {
|
||||
vec2.scale(this.velocity, tangent, vec2.dot(tangent, this.velocity));
|
||||
vec2.scale(this.velocity, tangent!, vec2.dot(tangent!, this.velocity));
|
||||
wasHit = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export class LampPhysical extends LampBase implements Physical {
|
|||
this.center.x - settings.lightCutoffDistance,
|
||||
this.center.x + settings.lightCutoffDistance,
|
||||
this.center.y - settings.lightCutoffDistance,
|
||||
this.center.y + settings.lightCutoffDistance
|
||||
this.center.y + settings.lightCutoffDistance,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export class TunnelPhysical extends TunnelBase implements StaticPhysical {
|
|||
const targetFromDelta = vec2.subtract(vec2.create(), target, this.from);
|
||||
|
||||
const h = clamp01(
|
||||
vec2.dot(targetFromDelta, toFromDelta) / vec2.dot(toFromDelta, toFromDelta)
|
||||
vec2.dot(targetFromDelta, toFromDelta) / vec2.dot(toFromDelta, toFromDelta),
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
|
||||
export abstract class BoundingBoxBase {
|
||||
export class BoundingBoxBase {
|
||||
constructor(
|
||||
protected _xMin: number = 0,
|
||||
protected _xMax: number = 0,
|
||||
protected _yMin: number = 0,
|
||||
protected _yMax: number = 0
|
||||
protected _yMax: number = 0,
|
||||
) {}
|
||||
|
||||
public get 0(): number {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Physical } from '../physical';
|
|||
import { BoundingBoxBase } from '../bounding-boxes/bounding-box-base';
|
||||
|
||||
export class BoundingBoxList {
|
||||
constructor(private objects: Array<Physical> = []) { }
|
||||
constructor(private objects: Array<Physical> = []) {}
|
||||
|
||||
public insert(object: Physical) {
|
||||
this.objects.push(object);
|
||||
|
|
@ -11,7 +11,7 @@ export class BoundingBoxList {
|
|||
public remove(object: Physical) {
|
||||
this.objects.splice(
|
||||
this.objects.findIndex((i) => i === object),
|
||||
1
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export class BoundingBoxTree {
|
|||
private buildRecursive(
|
||||
objects: Array<StaticPhysical>,
|
||||
depth: number,
|
||||
parent: Node
|
||||
parent: Node,
|
||||
): Node {
|
||||
if (objects.length === 0) {
|
||||
return null;
|
||||
|
|
@ -71,7 +71,7 @@ export class BoundingBoxTree {
|
|||
private findMaybeIntersecting(
|
||||
boundingBox: BoundingBoxBase,
|
||||
node: Node,
|
||||
depth: number
|
||||
depth: number,
|
||||
): Array<StaticPhysical> {
|
||||
if (node === null) {
|
||||
return [];
|
||||
|
|
@ -104,7 +104,7 @@ export class BoundingBoxTree {
|
|||
object: StaticPhysical,
|
||||
node: Node,
|
||||
depth: number,
|
||||
parent: Node
|
||||
parent: Node,
|
||||
): [Node, number] {
|
||||
if (node === null) {
|
||||
return [parent, depth - 1];
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export class PhysicalContainer {
|
|||
const array = this.objectsGroupedByAbilities.get(command);
|
||||
array.splice(
|
||||
array.findIndex((i) => i.id == object.gameObject.id),
|
||||
1
|
||||
1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { Physical } from './physical';
|
|||
export const moveCircle = (
|
||||
circle: CirclePhysical,
|
||||
delta: vec2,
|
||||
possibleIntersectors: Array<Physical>
|
||||
possibleIntersectors: Array<Physical>,
|
||||
): {
|
||||
realDelta: vec2;
|
||||
hitSurface: boolean;
|
||||
|
|
@ -16,7 +16,8 @@ export const moveCircle = (
|
|||
circle.center = vec2.add(circle.center, circle.center, delta);
|
||||
|
||||
const intersecting = possibleIntersectors.filter(
|
||||
(b) => b.gameObject !== circle.gameObject && circle.areIntersecting(b) && b.canCollide
|
||||
(b) =>
|
||||
b.gameObject !== circle.gameObject && circle.areIntersecting(b) && b.canCollide,
|
||||
);
|
||||
|
||||
if (intersecting.length === 0) {
|
||||
|
|
@ -43,7 +44,7 @@ export const moveCircle = (
|
|||
const distancesOfIntersectingPoints = distancesOfPoints.filter(
|
||||
(d) =>
|
||||
(d.closest.distance > 0 && d.closest.inverted) ||
|
||||
(d.closest.distance < 0 && !d.closest.inverted)
|
||||
(d.closest.distance < 0 && !d.closest.inverted),
|
||||
);
|
||||
|
||||
if (distancesOfIntersectingPoints.length === 0) {
|
||||
|
|
@ -59,14 +60,14 @@ export const moveCircle = (
|
|||
vec2.scale(
|
||||
pointDistance.point,
|
||||
pointDistance.point,
|
||||
(pointDistance.closest.inverted ? 1 : -1) * pointDistance.closest.distance
|
||||
(pointDistance.closest.inverted ? 1 : -1) * pointDistance.closest.distance,
|
||||
);
|
||||
return pointDistance.point;
|
||||
});
|
||||
|
||||
const approxNormal = deltas.reduce(
|
||||
(sum, current) => vec2.add(sum, sum, current),
|
||||
vec2.create()
|
||||
vec2.create(),
|
||||
);
|
||||
vec2.scale(approxNormal, approxNormal, 1 / deltas.length);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import {
|
||||
Command,
|
||||
CommandExecutors,
|
||||
CommandReceiver,
|
||||
CreateObjectsCommand,
|
||||
|
|
@ -35,11 +34,9 @@ export class Player extends CommandReceiver {
|
|||
},
|
||||
};
|
||||
|
||||
protected defaultCommandExecutor(command: Command) { }
|
||||
|
||||
constructor(
|
||||
private readonly objects: PhysicalContainer,
|
||||
private readonly socket: SocketIO.Socket
|
||||
private readonly socket: SocketIO.Socket,
|
||||
) {
|
||||
super();
|
||||
this.character = new CharacterPhysical(objects);
|
||||
|
|
@ -50,7 +47,7 @@ export class Player extends CommandReceiver {
|
|||
|
||||
socket.emit(
|
||||
TransportEvents.ServerToPlayer,
|
||||
serialize(new CreatePlayerCommand(this.character))
|
||||
serialize(new CreatePlayerCommand(this.character)),
|
||||
);
|
||||
|
||||
this.sendObjects();
|
||||
|
|
@ -66,11 +63,11 @@ export class Player extends CommandReceiver {
|
|||
|
||||
public sendObjects() {
|
||||
const newlyIntersecting = this.objectsInViewArea.filter(
|
||||
(o) => !this.objectsPreviouslyInViewArea.includes(o)
|
||||
(o) => !this.objectsPreviouslyInViewArea.includes(o),
|
||||
);
|
||||
|
||||
const noLongerIntersecting = this.objectsPreviouslyInViewArea.filter(
|
||||
(o) => !this.objectsInViewArea.includes(o)
|
||||
(o) => !this.objectsInViewArea.includes(o),
|
||||
);
|
||||
this.objectsPreviouslyInViewArea = this.objectsInViewArea;
|
||||
|
||||
|
|
@ -80,8 +77,8 @@ export class Player extends CommandReceiver {
|
|||
serialize(
|
||||
new DeleteObjectsCommand([
|
||||
...new Set(noLongerIntersecting.map((p) => p.gameObject.id)),
|
||||
])
|
||||
)
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -91,8 +88,8 @@ export class Player extends CommandReceiver {
|
|||
serialize(
|
||||
new CreateObjectsCommand([
|
||||
...new Set(newlyIntersecting.map((p) => p.gameObject)),
|
||||
])
|
||||
)
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +98,10 @@ export class Player extends CommandReceiver {
|
|||
serialize(
|
||||
new UpdateObjectsCommand([
|
||||
...new Set(
|
||||
this.objectsInViewArea.filter((p) => p.canMove).map((p) => p.gameObject)
|
||||
this.objectsInViewArea.filter((p) => p.canMove).map((p) => p.gameObject),
|
||||
),
|
||||
])
|
||||
)
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
if (this.isActive) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue