Change gameplay

This commit is contained in:
schmelczerandras 2020-10-24 22:24:27 +02:00
parent d79900e3ea
commit 34dae300da
56 changed files with 906 additions and 400 deletions

View file

@ -1,5 +1,5 @@
import { vec2 } from 'gl-matrix';
import { Circle, GameObject, serializesTo, settings, UpdateObjectMessage } from 'shared';
import { Circle, GameObject, serializesTo, settings } from 'shared';
import { PhysicalBase } from '../physics/physicals/physical-base';
import { BoundingBox } from '../physics/bounding-boxes/bounding-box';
import { BoundingBoxBase } from '../physics/bounding-boxes/bounding-box-base';

View file

@ -0,0 +1,8 @@
export interface GeneratesPoints {
getPoints(): {
decla: number;
red: number;
};
}
export const generatesPoints = (a: any): a is GeneratesPoints => a && 'getPoints' in a;

View file

@ -36,6 +36,8 @@ export class LampPhysical extends LampBase implements StaticPhysical {
return vec2.create();
}
public step(deltaTime: number): void {}
public distance(target: vec2): number {
return vec2.distance(this.center, target);
}

View file

@ -10,15 +10,16 @@ import {
settings,
PlanetBase,
CharacterTeam,
UpdateObjectMessage,
} from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
import { StaticPhysical } from '../physics/physicals/static-physical';
import { UpdateGameObjectMessage } from '../update-game-object-message';
import { GeneratesPoints } from './generates-points';
@serializesTo(PlanetBase)
export class PlanetPhysical extends PlanetBase implements StaticPhysical {
export class PlanetPhysical
extends PlanetBase
implements StaticPhysical, GeneratesPoints {
public readonly canCollide = true;
public readonly canMove = false;
@ -67,41 +68,62 @@ export class PlanetPhysical extends PlanetBase implements StaticPhysical {
return sign * d;
}
public calculateUpdates(): UpdateObjectMessage {
return new UpdateGameObjectMessage(this, ['ownership']);
public get team(): CharacterTeam {
return this.ownership === 0.5
? CharacterTeam.neutral
: this.ownership < 0.5
? CharacterTeam.decla
: CharacterTeam.red;
}
private timeSinceLastPointGeneration = 0;
public getPoints(): {
decla: number;
red: number;
} {
if (this.timeSinceLastPointGeneration > settings.planetPointGenerationInterval) {
this.timeSinceLastPointGeneration = 0;
if (this.team !== CharacterTeam.neutral) {
this.remoteCall('generatedPoints', settings.planetPointGenerationValue);
}
return {
decla:
this.team === CharacterTeam.decla ? settings.planetPointGenerationValue : 0,
red: this.team === CharacterTeam.red ? settings.planetPointGenerationValue : 0,
};
}
return {
decla: 0,
red: 0,
};
}
public step(deltaTime: number): void {
this.timeSinceLastPointGeneration += deltaTime;
// In reverse order, so that teams can achieve a 100% control.
this.remoteCall('setOwnership', this.ownership);
this.takeControl(CharacterTeam.neutral, deltaTime);
}
public takeControl(team: CharacterTeam, deltaTime: number) {
const previousOwnership = this.ownership;
if (team === CharacterTeam.decla) {
this.ownership -= (0.5 / settings.takeControlTimeInSeconds) * deltaTime;
if (
previousOwnership >= 0.5 - settings.planetControlThreshold &&
this.ownership < 0.5 - settings.planetControlThreshold
) {
PlanetPhysical.declaPlanetCount++;
PlanetPhysical.neutralPlanetCount--;
} else if (
previousOwnership > 0.5 + settings.planetControlThreshold &&
previousOwnership <= 0.5 + settings.planetControlThreshold
) {
PlanetPhysical.redPlanetCount--;
PlanetPhysical.neutralPlanetCount++;
}
} else {
} else if (team === CharacterTeam.red) {
this.ownership += (0.5 / settings.takeControlTimeInSeconds) * deltaTime;
} else {
const previous = this.ownership;
this.ownership +=
-Math.sign(this.ownership - 0.5) *
(0.5 / settings.loseControlTimeInSeconds) *
deltaTime;
if (
previousOwnership < 0.5 + settings.planetControlThreshold &&
this.ownership >= 0.5 + settings.planetControlThreshold
(previous < 0.5 && this.ownership > 0.5) ||
(previous > 0.5 && this.ownership < 0.5)
) {
PlanetPhysical.redPlanetCount++;
PlanetPhysical.neutralPlanetCount--;
} else if (
previousOwnership <= 0.5 - settings.planetControlThreshold &&
previousOwnership > 0.5 + settings.planetControlThreshold
) {
PlanetPhysical.declaPlanetCount--;
PlanetPhysical.neutralPlanetCount++;
this.ownership = 0.5;
}
}

View file

@ -21,8 +21,6 @@ import { forceAtPosition } from '../physics/functions/force-at-position';
import { getBoundingBoxOfCircle } from '../physics/functions/get-bounding-box-of-circle';
import { PlanetPhysical } from './planet-physical';
import { ReactsToCollision } from '../physics/physicals/reacts-to-collision';
import { UpdateObjectMessage } from 'shared/lib/src/objects/update-object-message';
import { UpdateGameObjectMessage } from '../update-game-object-message';
@serializesTo(PlayerCharacterBase)
export class PlayerCharacterPhysical
@ -133,20 +131,15 @@ export class PlayerCharacterPhysical
);
}
public calculateUpdates(): UpdateObjectMessage {
return new UpdateGameObjectMessage(this, [
'head',
'leftFoot',
'rightFoot',
'health',
'killCount',
]);
}
public handleMovementAction(c: MoveActionCommand) {
this.movementActions.push(c);
}
private addKill() {
this.killCount++;
this.remoteCall('setKillCount', this.killCount);
}
public onCollision(other: GameObject) {
if (
other instanceof ProjectilePhysical &&
@ -155,9 +148,10 @@ export class PlayerCharacterPhysical
) {
other.destroy();
this.health -= other.strength;
this.remoteCall('setHealth', this.health);
if (this.health <= 0) {
this.destroy();
other.originator.killCount++;
other.originator.addKill();
}
}
}
@ -182,6 +176,8 @@ export class PlayerCharacterPhysical
this.container,
);
this.container.addObject(projectile);
this.remoteCall('onShoot', strength);
}
public get boundingBox(): BoundingBoxBase {
@ -299,6 +295,7 @@ export class PlayerCharacterPhysical
this.stepBodyPart(this.leftFoot, deltaTime);
this.stepBodyPart(this.rightFoot, deltaTime);
this.keepPosture();
this.remoteCall('updateCircles', this.head, this.leftFoot, this.rightFoot);
}
private setDirection(direction: vec2, deltaTime: number) {

View file

@ -13,8 +13,6 @@ import { DynamicPhysical } from '../physics/physicals/dynamic-physical';
import { PhysicalContainer } from '../physics/containers/physical-container';
import { PlanetPhysical } from './planet-physical';
import { ReactsToCollision } from '../physics/physicals/reacts-to-collision';
import { UpdateObjectMessage } from 'shared/lib/src/objects/update-object-message';
import { UpdateGameObjectMessage } from '../update-game-object-message';
import { PlayerCharacterPhysical } from './player-character-physical';
import { moveCircle } from '../physics/functions/move-circle';
@ -68,10 +66,6 @@ export class ProjectilePhysical
vec2.add(this.center, this.center, delta);
}
public calculateUpdates(): UpdateObjectMessage {
return new UpdateGameObjectMessage(this, ['center', 'strength']);
}
public get boundingBox(): ImmutableBoundingBox {
if (!this._boundingBox) {
this._boundingBox = (this.object as CirclePhysical).boundingBox;
@ -105,7 +99,9 @@ export class ProjectilePhysical
}
public step(deltaTime: number) {
if ((this.strength -= settings.projectileFadeSpeed * deltaTime) < 0) {
super.step(deltaTime);
if (this.strength <= 0) {
this.destroy();
return;
}
@ -122,5 +118,7 @@ export class ProjectilePhysical
this.object.velocity = this.velocity;
this.object.step2(deltaTime);
this.remoteCall('setCenter', this.center);
}
}