Improve gameplay
This commit is contained in:
parent
e02a5b264c
commit
7c76b16d13
6 changed files with 1080 additions and 400 deletions
|
|
@ -1,5 +1,14 @@
|
|||
import { UpdateMessage, UpdateObjectMessage } from '../main';
|
||||
import { Id } from '../transport/identity';
|
||||
|
||||
export abstract class GameObject {
|
||||
constructor(public readonly id: Id) {}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage | undefined {
|
||||
return;
|
||||
}
|
||||
|
||||
update(updates: Array<UpdateMessage>): void {
|
||||
updates.forEach((u) => ((this as any)[u.key] = u.value));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@ import { Circle } from '../../helper/circle';
|
|||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { GameObject } from '../game-object';
|
||||
import { CharacterTeam } from './character-team';
|
||||
|
||||
@serializable
|
||||
export class CharacterBase extends GameObject {
|
||||
constructor(
|
||||
id: Id,
|
||||
public colorIndex: number,
|
||||
public team: CharacterTeam,
|
||||
public health: number,
|
||||
public head?: Circle,
|
||||
public leftFoot?: Circle,
|
||||
public rightFoot?: Circle,
|
||||
|
|
@ -16,7 +19,7 @@ export class CharacterBase extends GameObject {
|
|||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
const { id, colorIndex, head, leftFoot, rightFoot } = this;
|
||||
return [id, colorIndex, head, leftFoot, rightFoot];
|
||||
const { id, colorIndex, team, health, head, leftFoot, rightFoot } = this;
|
||||
return [id, colorIndex, team, health, head, leftFoot, rightFoot];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
shared/src/objects/types/character-team.ts
Normal file
4
shared/src/objects/types/character-team.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export enum CharacterTeam {
|
||||
decla = 'decla',
|
||||
red = 'red',
|
||||
}
|
||||
|
|
@ -7,8 +7,16 @@ import { GameObject } from '../game-object';
|
|||
|
||||
@serializable
|
||||
export class PlanetBase extends GameObject {
|
||||
constructor(id: Id, public readonly vertices: Array<vec2>) {
|
||||
public readonly center: vec2;
|
||||
|
||||
constructor(
|
||||
id: Id,
|
||||
public readonly vertices: Array<vec2>,
|
||||
public ownership: number = 0.5,
|
||||
) {
|
||||
super(id);
|
||||
this.center = vertices.reduce((sum, v) => vec2.add(sum, sum, v), vec2.create());
|
||||
vec2.scale(this.center, this.center, 1 / vertices.length);
|
||||
}
|
||||
|
||||
public static createPlanetVertices(
|
||||
|
|
@ -16,7 +24,7 @@ export class PlanetBase extends GameObject {
|
|||
width: number,
|
||||
height: number,
|
||||
randomness: number,
|
||||
vertexCount = settings.polygonEdgeCount,
|
||||
vertexCount = settings.planetEdgeCount,
|
||||
): Array<vec2> {
|
||||
const vertices = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { CharacterBase } from './character-base';
|
|||
import { Circle } from '../../helper/circle';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { CharacterTeam } from './character-team';
|
||||
|
||||
@serializable
|
||||
export class PlayerCharacterBase extends CharacterBase {
|
||||
|
|
@ -9,15 +10,17 @@ export class PlayerCharacterBase extends CharacterBase {
|
|||
id: Id,
|
||||
public name: string,
|
||||
colorIndex: number,
|
||||
team: CharacterTeam,
|
||||
health: number,
|
||||
head?: Circle,
|
||||
leftFoot?: Circle,
|
||||
rightFoot?: Circle,
|
||||
) {
|
||||
super(id, colorIndex, head, leftFoot, rightFoot);
|
||||
super(id, colorIndex, team, health, head, leftFoot, rightFoot);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
const { id, name, colorIndex, head, leftFoot, rightFoot } = this;
|
||||
return [id, name, colorIndex, head, leftFoot, rightFoot];
|
||||
const { id, name, colorIndex, team, health, head, leftFoot, rightFoot } = this;
|
||||
return [id, name, colorIndex, team, health, head, leftFoot, rightFoot];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,17 @@ import { GameObject } from '../game-object';
|
|||
|
||||
@serializable
|
||||
export class ProjectileBase extends GameObject {
|
||||
constructor(id: Id, public center: vec2, public radius: number) {
|
||||
constructor(
|
||||
id: Id,
|
||||
public center: vec2,
|
||||
public radius: number,
|
||||
public colorIndex: number,
|
||||
public strength: number,
|
||||
) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.center, this.radius];
|
||||
return [this.id, this.center, this.radius, this.colorIndex, this.strength];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue