Add basic multiplayer

This commit is contained in:
schmelczerandras 2020-10-05 19:07:17 +02:00
commit 46a48e7c15
5 changed files with 1361 additions and 753 deletions

View file

@ -0,0 +1,26 @@
import { CreatePlayerCommand } from '../commands/types/create-player';
import { MoveActionCommand } from '../commands/types/move-action';
import { PrimaryActionCommand } from '../commands/types/primary-action';
import { SecondaryActionCommand } from '../commands/types/secondary-action';
import { SetViewAreaActionCommand } from '../commands/types/set-view-area-action';
import { TernaryActionCommand } from '../commands/types/ternary-action';
import { UpdateObjectsCommand } from '../commands/types/update-objects';
import { Command, CreateObjectsCommand, DeleteObjectsCommand } from '../main';
export const commandConstructors: {
[type: string]: new (...values: Array<any>) => any;
} = {
[CreateObjectsCommand.type]: CreateObjectsCommand,
[DeleteObjectsCommand.type]: DeleteObjectsCommand,
[CreatePlayerCommand.type]: CreatePlayerCommand,
[MoveActionCommand.type]: MoveActionCommand,
[PrimaryActionCommand.type]: PrimaryActionCommand,
[SecondaryActionCommand.type]: SecondaryActionCommand,
[TernaryActionCommand.type]: TernaryActionCommand,
[SetViewAreaActionCommand.type]: SetViewAreaActionCommand,
[UpdateObjectsCommand.type]: UpdateObjectsCommand,
};
export const deserializeCommand = ([type, ...values]: [string, Array<any>]): Command => {
return new commandConstructors[type](...values);
};

View file

@ -0,0 +1,12 @@
import { CommandReceiver } from '../commands/command-receiver';
import { Id } from '../transport/identity';
export abstract class GameObject extends CommandReceiver {
public get type(): string {
return (this as any).constructor.type;
}
constructor(public readonly id: Id) {
super();
}
}

View file

@ -0,0 +1,17 @@
import { vec2 } from 'gl-matrix';
import { Circle } from '../../helper/circle';
import { Id } from '../../main';
import { GameObject } from '../game-object';
export abstract class CharacterBase extends GameObject {
public static readonly type = 'Character';
constructor(
id: Id,
public head: Circle,
public leftFoot: Circle,
public rightFoot: Circle
) {
super(id);
}
}

View file

@ -0,0 +1,11 @@
import { vec2, vec3 } from 'gl-matrix';
import { Id } from '../../main';
import { GameObject } from '../game-object';
export abstract class LampBase extends GameObject {
public static readonly type = 'Lamp';
constructor(id: Id, public center: vec2, public color: vec3, public lightness: number) {
super(id);
}
}

View file

@ -0,0 +1,17 @@
import { vec2 } from 'gl-matrix';
import { GameObject, Id } from '../../main';
import { typed } from '../../transport/typed';
export abstract class TunnelBase extends GameObject {
public static readonly type = 'Tunnel';
constructor(
id: Id,
public readonly from: vec2,
public readonly to: vec2,
public readonly fromRadius: number,
public readonly toRadius: number
) {
super(id);
}
}