Improve gameplay
This commit is contained in:
parent
7412bc8af5
commit
793d9a81e8
27 changed files with 275 additions and 226 deletions
|
|
@ -1,18 +1,36 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { CircleLight } from 'sdf-2d';
|
||||
import { CommandExecutors, Id, LampBase } from 'shared';
|
||||
import { CommandExecutors, Id, LampBase, mixRgb, settings } from 'shared';
|
||||
import { RenderCommand } from '../../commands/types/render';
|
||||
import { StepCommand } from '../../commands/types/step';
|
||||
|
||||
export class LampView extends LampBase {
|
||||
private light: CircleLight;
|
||||
|
||||
private targetColor: vec3;
|
||||
private targetLightness: number;
|
||||
|
||||
protected commandExecutors: CommandExecutors = {
|
||||
[RenderCommand.type]: this.draw.bind(this),
|
||||
[StepCommand.type]: this.step.bind(this),
|
||||
};
|
||||
|
||||
constructor(id: Id, center: vec2, color: vec3, lightness: number) {
|
||||
super(id, center, color, lightness);
|
||||
this.light = new CircleLight(center, color, lightness);
|
||||
this.light = new CircleLight(vec2.clone(center), vec3.clone(color), lightness);
|
||||
this.targetColor = vec3.clone(color);
|
||||
this.targetLightness = lightness;
|
||||
}
|
||||
|
||||
public setLight(color: vec3, lightness: number) {
|
||||
this.targetColor = vec3.clone(color);
|
||||
this.targetLightness = lightness;
|
||||
}
|
||||
|
||||
private step({ deltaTimeInSeconds }: StepCommand): void {
|
||||
const t = 1 - Math.exp(-deltaTimeInSeconds / settings.lampLerpSeconds);
|
||||
this.light.color = mixRgb(this.light.color, this.targetColor, t);
|
||||
this.light.intensity += (this.targetLightness - this.light.intensity) * t;
|
||||
}
|
||||
|
||||
private draw({ renderer }: RenderCommand): void {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,10 @@ export class ProjectileView extends ProjectileBase {
|
|||
|
||||
this.center = this.centerExtrapolator.getValue(deltaTimeInSeconds);
|
||||
this.light.center = this.center;
|
||||
this.light.intensity = (0.15 * this.strength) / settings.projectileMaxStrength;
|
||||
this.light.intensity = Math.min(
|
||||
0.1,
|
||||
(0.15 * this.strength) / settings.projectileMaxStrength,
|
||||
);
|
||||
}
|
||||
|
||||
private draw({ renderer }: RenderCommand): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue