Improve multiplayer
This commit is contained in:
parent
220b20476f
commit
37954e2ef1
29 changed files with 321 additions and 267 deletions
|
|
@ -4,11 +4,11 @@ import { Command } from '../command';
|
|||
|
||||
@serializable
|
||||
export class MoveActionCommand extends Command {
|
||||
public constructor(public readonly delta: vec2) {
|
||||
public constructor(public readonly direction: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.delta];
|
||||
return [this.direction];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
shared/src/commands/types/set-aspect-ratio-action.ts
Normal file
13
shared/src/commands/types/set-aspect-ratio-action.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class SetAspectRatioActionCommand extends Command {
|
||||
public constructor(public readonly aspectRatio: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.aspectRatio];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import { Rectangle } from '../../helper/rectangle';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class SetViewAreaActionCommand extends Command {
|
||||
public constructor(public readonly viewArea: Rectangle) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.viewArea];
|
||||
}
|
||||
}
|
||||
22
shared/src/helper/calculate-view-area.ts
Normal file
22
shared/src/helper/calculate-view-area.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Rectangle, settings } from '../main';
|
||||
|
||||
export const calculateViewArea = (
|
||||
center: vec2,
|
||||
aspectRatio: number,
|
||||
oversizeRatio = 1,
|
||||
): Rectangle => {
|
||||
const viewArea = new Rectangle();
|
||||
|
||||
viewArea.size = vec2.fromValues(
|
||||
Math.sqrt(settings.inViewAreaSize * oversizeRatio * aspectRatio),
|
||||
Math.sqrt((settings.inViewAreaSize * oversizeRatio) / aspectRatio),
|
||||
);
|
||||
|
||||
viewArea.topLeft = vec2.fromValues(
|
||||
center.x - viewArea.size.x / 2,
|
||||
center.y + viewArea.size.y / 2,
|
||||
);
|
||||
|
||||
return viewArea;
|
||||
};
|
||||
|
|
@ -9,6 +9,10 @@ export class Circle {
|
|||
return vec2.distance(this.center, target) - this.radius;
|
||||
}
|
||||
|
||||
public distanceBetween(target: Circle): number {
|
||||
return vec2.distance(target.center, this.center) - this.radius - target.radius;
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.center, this.radius];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,18 @@ export * from './commands/types/update-objects';
|
|||
export * from './commands/types/step';
|
||||
export * from './commands/types/ternary-action';
|
||||
export * from './commands/types/move-action';
|
||||
export * from './commands/types/set-view-area-action';
|
||||
export * from './commands/types/set-aspect-ratio-action';
|
||||
export * from './commands/types/primary-action';
|
||||
export * from './commands/types/secondary-action';
|
||||
export * from './commands/command-receiver';
|
||||
export * from './commands/command-executors';
|
||||
export * from './commands/command-generator';
|
||||
export * from './commands/broadcast-commands';
|
||||
export * from './commands/types/set-aspect-ratio-action';
|
||||
export * from './helper/array';
|
||||
export * from './helper/last';
|
||||
export * from './helper/clamp';
|
||||
export * from './helper/calculate-view-area';
|
||||
export * from './helper/pretty-print';
|
||||
export * from './helper/circle';
|
||||
export * from './helper/rectangle';
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@ export const settings = {
|
|||
hitDetectionCirclePointCount: 32,
|
||||
hitDetectionMaxOverlap: 0.01,
|
||||
physicsMaxStep: 5,
|
||||
gravitationalForce: vec2.fromValues(0, -0.0055),
|
||||
maxVelocityX: 1,
|
||||
maxAccelerationX: 0.005,
|
||||
maxAccelerationY: 0.01,
|
||||
targetPhysicsDeltaTimeInMilliseconds: 10,
|
||||
gravitationalForce: vec2.fromValues(0, -200),
|
||||
maxVelocityX: 500,
|
||||
maxVelocityY: 750,
|
||||
maxAccelerationX: 16000,
|
||||
maxAccelerationY: 5500,
|
||||
targetPhysicsDeltaTimeInMilliseconds: 15,
|
||||
minPhysicsSleepTime: 4,
|
||||
velocityAttenuation: 0.99,
|
||||
velocityAttenuation: 0.5,
|
||||
frictionMinVelocity: 400,
|
||||
inViewAreaSize: 1920 * 1080 * 3,
|
||||
defaultJumpEnergy: 600,
|
||||
defaultJumpEnergy: 0.75,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export type Id = number;
|
||||
export type Id = number | null;
|
||||
|
|
|
|||
|
|
@ -2,4 +2,6 @@ export enum TransportEvents {
|
|||
PlayerJoining = 'PlayerJoining',
|
||||
PlayerToServer = 'PlayerToServer',
|
||||
ServerToPlayer = 'ServerToPlayer',
|
||||
Ping = 'Ping',
|
||||
Pong = 'Pong',
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue