Improve gameplay
This commit is contained in:
parent
e02a5b264c
commit
7c76b16d13
53 changed files with 1084 additions and 404 deletions
14
shared/src/commands/types/player-died.ts
Normal file
14
shared/src/commands/types/player-died.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class PlayerDiedCommand extends Command {
|
||||
public constructor(public readonly timeout: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.timeout];
|
||||
}
|
||||
}
|
||||
17
shared/src/commands/types/update-planet-ownership.ts
Normal file
17
shared/src/commands/types/update-planet-ownership.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class UpdatePlanetOwnershipCommand extends Command {
|
||||
public constructor(
|
||||
public readonly declaCount: number,
|
||||
public readonly redCount: number,
|
||||
public readonly neutralCount: number,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.declaCount, this.redCount, this.neutralCount];
|
||||
}
|
||||
}
|
||||
34
shared/src/helper/hsl.ts
Normal file
34
shared/src/helper/hsl.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { vec3 } from 'gl-matrix';
|
||||
import { rgb } from './rgb';
|
||||
|
||||
export const hsl = (hue: number, saturation: number, lightness: number): vec3 => {
|
||||
hue /= 360;
|
||||
saturation /= 100;
|
||||
lightness /= 100;
|
||||
let r, g, b;
|
||||
|
||||
if (saturation == 0) {
|
||||
r = g = b = lightness;
|
||||
} else {
|
||||
const hue2rgb = (p: number, q: number, t: number) => {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1 / 2) return q;
|
||||
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
||||
return p;
|
||||
};
|
||||
|
||||
const q =
|
||||
lightness < 0.5
|
||||
? lightness * (1 + saturation)
|
||||
: lightness + saturation - lightness * saturation;
|
||||
const p = 2 * lightness - q;
|
||||
|
||||
r = hue2rgb(p, q, hue + 1 / 3);
|
||||
g = hue2rgb(p, q, hue);
|
||||
b = hue2rgb(p, q, hue - 1 / 3);
|
||||
}
|
||||
|
||||
return rgb(r, g, b);
|
||||
};
|
||||
|
|
@ -5,7 +5,9 @@ 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/player-died';
|
||||
export * from './commands/types/update-objects';
|
||||
export * from './commands/types/update-planet-ownership';
|
||||
export * from './commands/types/secondary-action';
|
||||
export * from './commands/command-receiver';
|
||||
export * from './commands/command-executors';
|
||||
|
|
@ -15,6 +17,7 @@ export * from './commands/types/set-aspect-ratio-action';
|
|||
export * from './helper/array';
|
||||
export * from './helper/last';
|
||||
export * from './helper/rgb';
|
||||
export * from './helper/hsl';
|
||||
export * from './helper/rgb255';
|
||||
export * from './helper/mix-rgb';
|
||||
export * from './helper/clamp';
|
||||
|
|
@ -36,6 +39,7 @@ export * from './transport/serialization/serializes-to';
|
|||
export * from './transport/serialization/serializable';
|
||||
export * from './transport/serialization/override-deserialization';
|
||||
export * from './objects/types/character-base';
|
||||
export * from './objects/types/character-team';
|
||||
export * from './objects/update-message';
|
||||
export * from './objects/types/player-character-base';
|
||||
export * from './objects/types/lamp-base';
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +1,47 @@
|
|||
import { rgb } from './helper/rgb';
|
||||
import { rgb255 } from './helper/rgb255';
|
||||
|
||||
const declaColor = rgb255(181, 138, 255);
|
||||
const redColor = rgb255(255, 138, 138);
|
||||
const declaPlanetColor = rgb(0, 0, 3);
|
||||
const redPlanetColor = rgb(3, 0, 0);
|
||||
|
||||
export const settings = {
|
||||
lightCutoffDistance: 600,
|
||||
physicsMaxStep: 2,
|
||||
maxVelocityX: 1000,
|
||||
maxVelocityY: 1000,
|
||||
polygonEdgeCount: 7,
|
||||
planetEdgeCount: 7,
|
||||
takeControlTimeInSeconds: 10,
|
||||
maxGravityDistance: 700,
|
||||
maxGravityQ: 180,
|
||||
planetControlThreshold: 0.2,
|
||||
playerMaxHealth: 100,
|
||||
maxGravityStrength: 10000,
|
||||
maxAcceleration: 10000,
|
||||
playerMaxStrength: 80,
|
||||
playerDiedTimeout: 5,
|
||||
playerStrengthRegenerationPerSeconds: 40,
|
||||
projectileMaxStrength: 40,
|
||||
projectileSpeed: 4000,
|
||||
projectileMaxBounceCount: 1,
|
||||
projectileStartOffset: 250,
|
||||
projectileTimeout: 3,
|
||||
projectileFadeSpeed: 20,
|
||||
projectileStartOffset: 150,
|
||||
projectileCreationInterval: 0.1,
|
||||
playerColorIndexOffset: 3,
|
||||
worldTopEdge: 10000,
|
||||
worldRightEdge: 10000,
|
||||
worldLeftEdge: -10000,
|
||||
worldBottomEdge: -10000,
|
||||
worldTopEdge: 3000,
|
||||
worldRightEdge: 3000,
|
||||
worldLeftEdge: -3000,
|
||||
worldBottomEdge: -3000,
|
||||
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
|
||||
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),
|
||||
],
|
||||
declaColor,
|
||||
declaPlanetColor,
|
||||
redColor,
|
||||
redPlanetColor,
|
||||
declaIndex: 0,
|
||||
redIndex: 1,
|
||||
palette: [declaColor, redColor],
|
||||
targetPhysicsDeltaTimeInMilliseconds: 20,
|
||||
minPhysicsSleepTime: 4,
|
||||
velocityAttenuation: 0.25,
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@
|
|||
"module": "commonjs",
|
||||
"composite": true,
|
||||
"lib": ["dom", "es2017"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/*.ts"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue