Change gameplay
This commit is contained in:
parent
d79900e3ea
commit
34dae300da
56 changed files with 906 additions and 400 deletions
18
shared/src/commands/types/game-end.ts
Normal file
18
shared/src/commands/types/game-end.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { CharacterTeam } from '../../objects/types/character-team';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class GameEnd extends Command {
|
||||
constructor(
|
||||
public readonly winningTeam: CharacterTeam,
|
||||
public readonly endCardLengthInSeconds: number,
|
||||
public readonly shouldReconnect: boolean,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.winningTeam, this.endCardLengthInSeconds, this.shouldReconnect];
|
||||
}
|
||||
}
|
||||
13
shared/src/commands/types/game-start.ts
Normal file
13
shared/src/commands/types/game-start.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class GameStart extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
14
shared/src/commands/types/remote-calls-for-object.ts
Normal file
14
shared/src/commands/types/remote-calls-for-object.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
import { RemoteCallsForObject } from './remote-calls-for-objects';
|
||||
|
||||
@serializable
|
||||
export class RemoteCallsForObjects extends Command {
|
||||
constructor(public readonly callsForObjects: Array<RemoteCallsForObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.callsForObjects];
|
||||
}
|
||||
}
|
||||
15
shared/src/commands/types/remote-calls-for-objects.ts
Normal file
15
shared/src/commands/types/remote-calls-for-objects.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Id } from '../../main';
|
||||
import { RemoteCall } from '../../objects/game-object';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class RemoteCallsForObject extends Command {
|
||||
constructor(public readonly id: Id, public readonly calls: Array<RemoteCall>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.calls];
|
||||
}
|
||||
}
|
||||
13
shared/src/commands/types/server-announcement.ts
Normal file
13
shared/src/commands/types/server-announcement.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class ServerAnnouncement extends Command {
|
||||
constructor(public readonly text: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.text];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,17 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { CharacterTeam } from '../../objects/types/character-team';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class OtherPlayerDirection {
|
||||
public constructor(
|
||||
public readonly direction: vec2,
|
||||
public readonly team: CharacterTeam,
|
||||
) {}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.direction, this.team];
|
||||
}
|
||||
}
|
||||
|
||||
@serializable
|
||||
export class UpdateGameState extends Command {
|
||||
public constructor(
|
||||
public readonly declaCount: number,
|
||||
public readonly redCount: number,
|
||||
public readonly neutralCount: number,
|
||||
public readonly otherPlayerDirections: Array<OtherPlayerDirection>,
|
||||
public readonly limit: number,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [
|
||||
this.declaCount,
|
||||
this.redCount,
|
||||
this.neutralCount,
|
||||
this.otherPlayerDirections,
|
||||
];
|
||||
return [this.declaCount, this.redCount, this.limit];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { UpdateObjectMessage } from '../../objects/update-object-message';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class UpdateObjectsCommand extends Command {
|
||||
public constructor(public readonly updates: Array<UpdateObjectMessage>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.updates];
|
||||
}
|
||||
}
|
||||
27
shared/src/commands/types/update-other-player-directions.ts
Normal file
27
shared/src/commands/types/update-other-player-directions.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { CharacterTeam } from '../../objects/types/character-team';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class OtherPlayerDirection {
|
||||
public constructor(
|
||||
public readonly direction: vec2,
|
||||
public readonly team: CharacterTeam,
|
||||
) {}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.direction, this.team];
|
||||
}
|
||||
}
|
||||
|
||||
@serializable
|
||||
export class UpdateOtherPlayerDirections extends Command {
|
||||
public constructor(public readonly otherPlayerDirections: Array<OtherPlayerDirection>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.otherPlayerDirections];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ export interface ServerInformation {
|
|||
playerLimit: number;
|
||||
playerCount: number;
|
||||
serverName: string;
|
||||
gameStatePercent: number;
|
||||
}
|
||||
|
||||
export const serverInformationEndpoint = '/stats';
|
||||
export const serverInformationEndpoint = '/state';
|
||||
|
|
|
|||
|
|
@ -5,12 +5,17 @@ export * from './commands/types/delete-objects';
|
|||
export * from './commands/types/ternary-action';
|
||||
export * from './commands/types/move-action';
|
||||
export * from './commands/types/primary-action';
|
||||
export * from './commands/types/remote-calls-for-objects';
|
||||
export * from './commands/types/remote-calls-for-object';
|
||||
export * from './commands/types/player-died';
|
||||
export * from './commands/types/update-objects';
|
||||
export * from './commands/types/update-game-state';
|
||||
export * from './commands/types/server-announcement';
|
||||
export * from './commands/types/game-end';
|
||||
export * from './commands/types/game-start';
|
||||
export * from './commands/types/update-other-player-directions';
|
||||
export * from './commands/types/secondary-action';
|
||||
export * from './commands/command-receiver';
|
||||
export * from './commands/types/update-game-state';
|
||||
export * from './commands/command-receiver';
|
||||
export * from './commands/types/update-other-player-directions';
|
||||
export * from './commands/command-executors';
|
||||
export * from './commands/command-generator';
|
||||
export * from './commands/broadcast-commands';
|
||||
|
|
@ -46,7 +51,6 @@ export * from './objects/types/player-character-base';
|
|||
export * from './objects/types/lamp-base';
|
||||
export * from './objects/types/planet-base';
|
||||
export * from './objects/types/projectile-base';
|
||||
export * from './objects/update-object-message';
|
||||
export * from './settings';
|
||||
export * from './transport/transport-events';
|
||||
export * from './transport/identity';
|
||||
|
|
|
|||
|
|
@ -1,14 +1,37 @@
|
|||
import { UpdateMessage, UpdateObjectMessage } from '../main';
|
||||
import { Id } from '../transport/identity';
|
||||
import { serializable } from '../transport/serialization/serializable';
|
||||
|
||||
export abstract class GameObject {
|
||||
constructor(public readonly id: Id) {}
|
||||
@serializable
|
||||
export class RemoteCall {
|
||||
constructor(public readonly functionName: string, public readonly args: Array<any>) {}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage | undefined {
|
||||
return;
|
||||
}
|
||||
|
||||
update(updates: Array<UpdateMessage>): void {
|
||||
updates.forEach((u) => ((this as any)[u.key] = u.value));
|
||||
public toArray(): Array<any> {
|
||||
return [this.functionName, this.args];
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class GameObject {
|
||||
private remoteCalls: Array<RemoteCall> = [];
|
||||
|
||||
constructor(public readonly id: Id) {}
|
||||
|
||||
public processRemoteCalls(remoteCalls: Array<RemoteCall>) {
|
||||
remoteCalls.forEach((r) =>
|
||||
((this[r.functionName as keyof this] as unknown) as (
|
||||
...args: Array<any>
|
||||
) => unknown)(...r.args),
|
||||
);
|
||||
}
|
||||
|
||||
public getRemoteCalls(): Array<RemoteCall> {
|
||||
return this.remoteCalls;
|
||||
}
|
||||
|
||||
public resetRemoteCalls() {
|
||||
this.remoteCalls = [];
|
||||
}
|
||||
|
||||
protected remoteCall(name: string & keyof this, ...args: Array<any>) {
|
||||
this.remoteCalls.push(new RemoteCall(name, args));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ export class PlanetBase extends GameObject {
|
|||
vec2.scale(this.center, this.center, 1 / vertices.length);
|
||||
}
|
||||
|
||||
public setOwnership(value: number) {
|
||||
this.ownership = value;
|
||||
}
|
||||
|
||||
public generatedPoints(value: number) {}
|
||||
|
||||
public static createPlanetVertices(
|
||||
center: vec2,
|
||||
width: number,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,25 @@ export class PlayerCharacterBase extends CharacterBase {
|
|||
super(id, team, health, head, leftFoot, rightFoot);
|
||||
}
|
||||
|
||||
public onShoot(strength: number) {}
|
||||
|
||||
public updateCircles(head: Circle, leftFoot: Circle, rightFoot: Circle) {
|
||||
this.head!.center = head.center;
|
||||
this.head!.radius = head.radius;
|
||||
this.leftFoot!.center = leftFoot.center;
|
||||
this.leftFoot!.radius = leftFoot.radius;
|
||||
this.rightFoot!.center = rightFoot.center;
|
||||
this.rightFoot!.radius = rightFoot.radius;
|
||||
}
|
||||
|
||||
public setHealth(health: number) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public setKillCount(killCount: number) {
|
||||
this.killCount = killCount;
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [
|
||||
this.id,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { settings } from '../../settings';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { GameObject } from '../game-object';
|
||||
|
|
@ -16,6 +17,15 @@ export class ProjectileBase extends GameObject {
|
|||
super(id);
|
||||
}
|
||||
|
||||
public setCenter(center: vec2) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
public step(deltaTimeInSeconds: number) {
|
||||
this.strength -= settings.projectileFadeSpeed * deltaTimeInSeconds;
|
||||
this.strength = Math.max(0, this.strength);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.center, this.radius, this.team, this.strength];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import { Id } from '../main';
|
||||
import { serializable } from '../transport/serialization/serializable';
|
||||
import { UpdateMessage } from './update-message';
|
||||
|
||||
@serializable
|
||||
export class UpdateObjectMessage {
|
||||
constructor(public id: Id, public updates: Array<UpdateMessage>) {}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.updates];
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,9 @@ export const settings = {
|
|||
objectsOnCircleLength: 0.002,
|
||||
planetEdgeCount: 7,
|
||||
takeControlTimeInSeconds: 4,
|
||||
loseControlTimeInSeconds: 24,
|
||||
planetPointGenerationInterval: 1.5,
|
||||
planetPointGenerationValue: 1,
|
||||
maxGravityDistance: 700,
|
||||
maxGravityQ: 180,
|
||||
planetControlThreshold: 0.2,
|
||||
|
|
@ -28,6 +31,7 @@ export const settings = {
|
|||
maxGravityStrength: 10000,
|
||||
maxAcceleration: 10000,
|
||||
playerMaxStrength: 80,
|
||||
endGameDeltaScaling: 4,
|
||||
playerDiedTimeout: 5,
|
||||
playerStrengthRegenerationPerSeconds: 40,
|
||||
projectileMaxStrength: 40,
|
||||
|
|
@ -37,7 +41,7 @@ export const settings = {
|
|||
projectileFadeSpeed: 20,
|
||||
projectileCreationInterval: 0.1,
|
||||
playerColorIndexOffset: 3,
|
||||
backgroundGradient: [rgb255(90, 38, 43), rgb255(0, 0, 0), rgb255(43, 39, 73)],
|
||||
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
|
||||
declaColor,
|
||||
declaPlanetColor,
|
||||
redColor,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ export enum TransportEvents {
|
|||
PlayerJoining = 'PlayerJoining',
|
||||
PlayerToServer = 'PlayerToServer',
|
||||
ServerToPlayer = 'ServerToPlayer',
|
||||
SubscribeForPlayerCount = 'SubscribeForPlayerCount',
|
||||
PlayerCountUpdate = 'PlayerCountUpdate',
|
||||
SubscribeForServerInfoUpdates = 'SubscribeForServerInfoUpdates',
|
||||
ServerInfoUpdate = 'ServerInfoUpdate',
|
||||
Ping = 'Ping',
|
||||
Pong = 'Pong',
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue