Change gameplay
This commit is contained in:
parent
d79900e3ea
commit
34dae300da
5 changed files with 901 additions and 395 deletions
|
|
@ -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;
|
||||
public toArray(): Array<any> {
|
||||
return [this.functionName, this.args];
|
||||
}
|
||||
}
|
||||
|
||||
update(updates: Array<UpdateMessage>): void {
|
||||
updates.forEach((u) => ((this as any)[u.key] = u.value));
|
||||
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];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue