Fix physics
This commit is contained in:
parent
37954e2ef1
commit
f9f6825776
51 changed files with 832 additions and 541 deletions
|
|
@ -1,7 +0,0 @@
|
|||
import { Command } from '../command';
|
||||
|
||||
export class StepCommand extends Command {
|
||||
public constructor(public readonly deltaTimeInMiliseconds: number) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
12
shared/src/helper/mix-rgb.ts
Normal file
12
shared/src/helper/mix-rgb.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { vec3 } from 'gl-matrix';
|
||||
import { clamp01 } from './clamp';
|
||||
import { mix } from './mix';
|
||||
|
||||
export const mixRgb = (a: vec3, b: vec3, q: number): vec3 => {
|
||||
const clampedQ = clamp01(q);
|
||||
return vec3.fromValues(
|
||||
mix(a[0], b[0], clampedQ),
|
||||
mix(a[1], b[1], clampedQ),
|
||||
mix(a[2], b[2], clampedQ),
|
||||
);
|
||||
};
|
||||
|
|
@ -9,6 +9,19 @@ export abstract class Random {
|
|||
Random._seed = value;
|
||||
}
|
||||
|
||||
public static choose<T>(values: Array<T>): T | undefined {
|
||||
const to = values.length;
|
||||
if (to === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return values[Math.floor(this.getRandomInRange(0, to))];
|
||||
}
|
||||
|
||||
public static getRandomInRange(from: number, to: number): number {
|
||||
return from + this.getRandom() * (to - from);
|
||||
}
|
||||
|
||||
public static getRandom(): number {
|
||||
let t = (Random._seed += 0x6d2b79f5);
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
|
|
|
|||
3
shared/src/helper/rgb.ts
Normal file
3
shared/src/helper/rgb.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { vec3 } from 'gl-matrix';
|
||||
|
||||
export const rgb = (r: number, g: number, b: number): vec3 => vec3.fromValues(r, g, b);
|
||||
4
shared/src/helper/rgb255.ts
Normal file
4
shared/src/helper/rgb255.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { vec3 } from 'gl-matrix';
|
||||
|
||||
export const rgb255 = (r: number, g: number, b: number): vec3 =>
|
||||
vec3.fromValues(r / 255, g / 255, b / 255);
|
||||
|
|
@ -3,10 +3,8 @@ export * from './commands/types/create-objects';
|
|||
export * from './commands/types/create-player';
|
||||
export * from './commands/types/delete-objects';
|
||||
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-aspect-ratio-action';
|
||||
export * from './commands/types/primary-action';
|
||||
export * from './commands/types/secondary-action';
|
||||
export * from './commands/command-receiver';
|
||||
|
|
@ -16,6 +14,9 @@ export * from './commands/broadcast-commands';
|
|||
export * from './commands/types/set-aspect-ratio-action';
|
||||
export * from './helper/array';
|
||||
export * from './helper/last';
|
||||
export * from './helper/rgb';
|
||||
export * from './helper/rgb255';
|
||||
export * from './helper/mix-rgb';
|
||||
export * from './helper/clamp';
|
||||
export * from './helper/calculate-view-area';
|
||||
export * from './helper/pretty-print';
|
||||
|
|
@ -33,7 +34,8 @@ export * from './transport/serialization/serializable';
|
|||
export * from './transport/serialization/override-deserialization';
|
||||
export * from './objects/types/character-base';
|
||||
export * from './objects/types/lamp-base';
|
||||
export * from './objects/types/tunnel-base';
|
||||
export * from './objects/types/stone-base';
|
||||
export * from './objects/types/projectile-base';
|
||||
export * from './settings';
|
||||
export * from './transport/transport-events';
|
||||
export * from './transport/identity';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
import { CommandReceiver } from '../commands/command-receiver';
|
||||
import { Id } from '../transport/identity';
|
||||
|
||||
export abstract class GameObject extends CommandReceiver {
|
||||
constructor(public readonly id: Id) {
|
||||
super();
|
||||
}
|
||||
export abstract class GameObject {
|
||||
constructor(public readonly id: Id) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { GameObject } from '../game-object';
|
|||
export class CharacterBase extends GameObject {
|
||||
constructor(
|
||||
id: Id,
|
||||
public colorIndex: number,
|
||||
public head?: Circle,
|
||||
public leftFoot?: Circle,
|
||||
public rightFoot?: Circle,
|
||||
|
|
@ -15,7 +16,7 @@ export class CharacterBase extends GameObject {
|
|||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
const { id, head, leftFoot, rightFoot } = this as any;
|
||||
return [id, head, leftFoot, rightFoot];
|
||||
const { id, colorIndex, head, leftFoot, rightFoot } = this;
|
||||
return [id, colorIndex, head, leftFoot, rightFoot];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export class LampBase extends GameObject {
|
|||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
const { id, center, color, lightness } = this as any;
|
||||
const { id, center, color, lightness } = this;
|
||||
return [id, center, color, lightness];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
shared/src/objects/types/projectile-base.ts
Normal file
15
shared/src/objects/types/projectile-base.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
@serializable
|
||||
export class ProjectileBase extends GameObject {
|
||||
constructor(id: Id, public center: vec2, public radius: number) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.center, this.radius];
|
||||
}
|
||||
}
|
||||
15
shared/src/objects/types/stone-base.ts
Normal file
15
shared/src/objects/types/stone-base.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
@serializable
|
||||
export class StoneBase extends GameObject {
|
||||
constructor(id: Id, public readonly vertices: Array<vec2>) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.vertices];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
@serializable
|
||||
export class TunnelBase extends GameObject {
|
||||
constructor(
|
||||
id: Id,
|
||||
public readonly from: vec2,
|
||||
public readonly to: vec2,
|
||||
public readonly fromRadius: number,
|
||||
public readonly toRadius: number,
|
||||
) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
const { id, from, to, fromRadius, toRadius } = this as any;
|
||||
return [id, from, to, fromRadius, toRadius];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,54 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { rgb255 } from './helper/rgb255';
|
||||
|
||||
export const settings = {
|
||||
lightCutoffDistance: 600,
|
||||
hitDetectionCirclePointCount: 32,
|
||||
hitDetectionMaxOverlap: 0.01,
|
||||
physicsMaxStep: 5,
|
||||
gravitationalForce: vec2.fromValues(0, -200),
|
||||
maxVelocityX: 500,
|
||||
maxVelocityY: 750,
|
||||
maxAccelerationX: 16000,
|
||||
maxAccelerationY: 5500,
|
||||
targetPhysicsDeltaTimeInMilliseconds: 15,
|
||||
gravitationalForce: vec2.fromValues(0, -3000),
|
||||
maxVelocityX: 4800,
|
||||
maxVelocityY: 3650,
|
||||
polygonEdgeCount: 8,
|
||||
projectileSpeed: 2000,
|
||||
projectileStartOffset: 150,
|
||||
playerColorIndexOffset: 3,
|
||||
worldLeftEdge: -5000,
|
||||
worldRightEdge: 5000,
|
||||
backgroundGradient: [rgb255(255, 117, 129), rgb255(136, 117, 255)],
|
||||
playerColors: [
|
||||
rgb255(107, 48, 188),
|
||||
rgb255(56, 254, 220),
|
||||
rgb255(197, 17, 17),
|
||||
rgb255(24, 24, 24),
|
||||
rgb255(245, 245, 88),
|
||||
rgb255(80, 239, 58),
|
||||
rgb255(18, 127, 45),
|
||||
rgb255(240, 125, 13),
|
||||
rgb255(214, 227, 241),
|
||||
rgb255(0, 161, 161),
|
||||
rgb255(250, 161, 151),
|
||||
rgb255(235, 84, 185),
|
||||
rgb255(114, 73, 30),
|
||||
rgb255(75, 75, 75),
|
||||
rgb255(107, 48, 188),
|
||||
rgb255(56, 254, 220),
|
||||
rgb255(197, 17, 17),
|
||||
rgb255(24, 24, 24),
|
||||
rgb255(245, 245, 88),
|
||||
rgb255(80, 239, 58),
|
||||
rgb255(18, 127, 45),
|
||||
rgb255(240, 125, 13),
|
||||
rgb255(214, 227, 241),
|
||||
rgb255(0, 161, 161),
|
||||
rgb255(250, 161, 151),
|
||||
rgb255(235, 84, 185),
|
||||
rgb255(114, 73, 30),
|
||||
rgb255(75, 75, 75),
|
||||
],
|
||||
maxAccelerationX: 200000,
|
||||
maxAccelerationY: 20500,
|
||||
targetPhysicsDeltaTimeInMilliseconds: 20,
|
||||
minPhysicsSleepTime: 4,
|
||||
velocityAttenuation: 0.5,
|
||||
frictionMinVelocity: 400,
|
||||
velocityAttenuation: 0.33,
|
||||
inViewAreaSize: 1920 * 1080 * 3,
|
||||
defaultJumpEnergy: 0.75,
|
||||
defaultJumpEnergy: 0.25,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue