Improve gameplay
This commit is contained in:
parent
e02a5b264c
commit
7c76b16d13
53 changed files with 1084 additions and 404 deletions
|
|
@ -30,10 +30,6 @@ export class CirclePhysical implements Circle, DynamicPhysical, ReactsToCollisio
|
|||
this.recalculateBoundingBox();
|
||||
}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
public get boundingBox(): BoundingBoxBase {
|
||||
return this._boundingBox;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,23 +9,28 @@ import {
|
|||
serializesTo,
|
||||
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';
|
||||
|
||||
@serializesTo(PlanetBase)
|
||||
export class PlanetPhysical extends PlanetBase implements StaticPhysical {
|
||||
public readonly canCollide = true;
|
||||
public readonly canMove = false;
|
||||
private center: vec2;
|
||||
|
||||
public static neutralPlanetCount = 0;
|
||||
public static declaPlanetCount = 0;
|
||||
public static redPlanetCount = 0;
|
||||
|
||||
private _boundingBox?: ImmutableBoundingBox;
|
||||
|
||||
constructor(vertices: Array<vec2>) {
|
||||
super(id(), vertices);
|
||||
this.center = vertices.reduce((sum, v) => vec2.add(sum, sum, v), vec2.create());
|
||||
vec2.scale(this.center, this.center, 1 / vertices.length);
|
||||
PlanetPhysical.neutralPlanetCount++;
|
||||
}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
|
|
@ -62,6 +67,47 @@ export class PlanetPhysical extends PlanetBase implements StaticPhysical {
|
|||
return sign * d;
|
||||
}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage {
|
||||
return new UpdateGameObjectMessage(this, ['ownership']);
|
||||
}
|
||||
|
||||
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 {
|
||||
this.ownership += (0.5 / settings.takeControlTimeInSeconds) * deltaTime;
|
||||
if (
|
||||
previousOwnership < 0.5 + settings.planetControlThreshold &&
|
||||
this.ownership >= 0.5 + settings.planetControlThreshold
|
||||
) {
|
||||
PlanetPhysical.redPlanetCount++;
|
||||
PlanetPhysical.neutralPlanetCount--;
|
||||
} else if (
|
||||
previousOwnership <= 0.5 - settings.planetControlThreshold &&
|
||||
previousOwnership > 0.5 + settings.planetControlThreshold
|
||||
) {
|
||||
PlanetPhysical.declaPlanetCount--;
|
||||
PlanetPhysical.neutralPlanetCount++;
|
||||
}
|
||||
}
|
||||
|
||||
this.ownership = clamp01(this.ownership);
|
||||
}
|
||||
|
||||
public get boundingBox(): ImmutableBoundingBox {
|
||||
if (!this._boundingBox) {
|
||||
const { xMin, xMax, yMin, yMax } = this.vertices.reduce(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
GameObject,
|
||||
Circle,
|
||||
PlayerCharacterBase,
|
||||
CharacterTeam,
|
||||
} from 'shared';
|
||||
import { DynamicPhysical } from '../physics/physicals/dynamic-physical';
|
||||
import { CirclePhysical } from './circle-physical';
|
||||
|
|
@ -32,6 +33,8 @@ export class PlayerCharacterPhysical
|
|||
|
||||
private static readonly headRadius = 50;
|
||||
private static readonly feetRadius = 20;
|
||||
private projectileStrength = settings.playerMaxStrength;
|
||||
|
||||
// offsets are meassured from (0, 0)
|
||||
private static readonly desiredHeadOffset = vec2.fromValues(0, 65);
|
||||
private static readonly desiredLeftFootOffset = vec2.fromValues(-20, 0);
|
||||
|
|
@ -93,10 +96,11 @@ export class PlayerCharacterPhysical
|
|||
constructor(
|
||||
name: string,
|
||||
public readonly colorIndex: number,
|
||||
team: CharacterTeam,
|
||||
private readonly container: PhysicalContainer,
|
||||
startPosition: vec2,
|
||||
) {
|
||||
super(id(), name, colorIndex);
|
||||
super(id(), name, colorIndex, team, settings.playerMaxHealth);
|
||||
|
||||
this.head = new CirclePhysical(
|
||||
vec2.add(vec2.create(), startPosition, PlayerCharacterPhysical.headOffset),
|
||||
|
|
@ -129,7 +133,7 @@ export class PlayerCharacterPhysical
|
|||
}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage {
|
||||
return new UpdateGameObjectMessage(this, ['head', 'leftFoot', 'rightFoot']);
|
||||
return new UpdateGameObjectMessage(this, ['head', 'leftFoot', 'rightFoot', 'health']);
|
||||
}
|
||||
|
||||
public handleMovementAction(c: MoveActionCommand) {
|
||||
|
|
@ -137,12 +141,44 @@ export class PlayerCharacterPhysical
|
|||
}
|
||||
|
||||
public onCollision(other: GameObject) {
|
||||
if (other instanceof ProjectilePhysical) {
|
||||
if (other instanceof ProjectilePhysical && other.team !== this.team) {
|
||||
other.destroy();
|
||||
this.destroy();
|
||||
this.health -= other.strength;
|
||||
if (this.health <= 0) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public shootTowards(position: vec2) {
|
||||
if (!this.isAlive) {
|
||||
return;
|
||||
}
|
||||
|
||||
const start = vec2.clone(this.center);
|
||||
const direction = vec2.subtract(vec2.create(), position, start);
|
||||
vec2.normalize(direction, direction);
|
||||
vec2.add(
|
||||
start,
|
||||
start,
|
||||
vec2.scale(vec2.create(), direction, settings.projectileStartOffset),
|
||||
);
|
||||
const velocity = vec2.scale(direction, direction, settings.projectileSpeed);
|
||||
vec2.add(velocity, velocity, this.velocity);
|
||||
const strength = this.projectileStrength / 2;
|
||||
this.projectileStrength -= strength;
|
||||
const projectile = new ProjectilePhysical(
|
||||
start,
|
||||
20,
|
||||
this.colorIndex,
|
||||
strength,
|
||||
this.team,
|
||||
velocity,
|
||||
this.container,
|
||||
);
|
||||
this.container.addObject(projectile);
|
||||
}
|
||||
|
||||
public get boundingBox(): BoundingBoxBase {
|
||||
this.bound.center = this.head.center;
|
||||
return this.bound.boundingBox;
|
||||
|
|
@ -197,6 +233,13 @@ export class PlayerCharacterPhysical
|
|||
this.currentPlanet = undefined;
|
||||
}
|
||||
|
||||
this.projectileStrength = Math.min(
|
||||
settings.playerMaxStrength,
|
||||
this.projectileStrength + settings.playerStrengthRegenerationPerSeconds * deltaTime,
|
||||
);
|
||||
|
||||
this.currentPlanet?.takeControl(this.team, deltaTime);
|
||||
|
||||
const intersectingWithForcefield = this.container.findIntersecting(
|
||||
getBoundingBoxOfCircle(
|
||||
new Circle(
|
||||
|
|
@ -205,7 +248,13 @@ export class PlayerCharacterPhysical
|
|||
),
|
||||
),
|
||||
);
|
||||
const actualGravity = forceAtPosition(this.center, intersectingWithForcefield);
|
||||
const feetCenter = vec2.add(
|
||||
vec2.create(),
|
||||
this.leftFoot.center,
|
||||
this.rightFoot.center,
|
||||
);
|
||||
vec2.scale(feetCenter, feetCenter, 0.5);
|
||||
const actualGravity = forceAtPosition(feetCenter, intersectingWithForcefield);
|
||||
|
||||
const direction = this.averageAndResetMovementActions();
|
||||
const movementForce = vec2.scale(direction, direction, settings.maxAcceleration);
|
||||
|
|
@ -269,7 +318,7 @@ export class PlayerCharacterPhysical
|
|||
|
||||
private springMove(object: CirclePhysical, center: vec2, offset: vec2) {
|
||||
// todo: make time-independent
|
||||
const springConstant = 0.35;
|
||||
const springConstant = 0.55;
|
||||
|
||||
const desiredPosition = vec2.add(vec2.create(), center, offset);
|
||||
vec2.rotate(desiredPosition, desiredPosition, center, this.direction);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { id, settings, serializesTo, ProjectileBase, GameObject } from 'shared';
|
||||
import {
|
||||
id,
|
||||
settings,
|
||||
serializesTo,
|
||||
ProjectileBase,
|
||||
GameObject,
|
||||
CharacterTeam,
|
||||
} from 'shared';
|
||||
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
|
||||
import { CirclePhysical } from './circle-physical';
|
||||
import { DynamicPhysical } from '../physics/physicals/dynamic-physical';
|
||||
|
|
@ -8,6 +15,7 @@ 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';
|
||||
|
||||
@serializesTo(ProjectileBase)
|
||||
export class ProjectilePhysical
|
||||
|
|
@ -15,6 +23,7 @@ export class ProjectilePhysical
|
|||
implements DynamicPhysical, ReactsToCollision {
|
||||
public readonly canCollide = true;
|
||||
public readonly canMove = true;
|
||||
|
||||
private isDestroyed = false;
|
||||
private bounceCount = 0;
|
||||
private _boundingBox?: ImmutableBoundingBox;
|
||||
|
|
@ -24,15 +33,18 @@ export class ProjectilePhysical
|
|||
constructor(
|
||||
center: vec2,
|
||||
radius: number,
|
||||
colorIndex: number,
|
||||
public strength: number,
|
||||
public team: CharacterTeam,
|
||||
private velocity: vec2,
|
||||
readonly container: PhysicalContainer,
|
||||
) {
|
||||
super(id(), center, radius);
|
||||
super(id(), center, radius, colorIndex, strength);
|
||||
this.object = new CirclePhysical(center, radius, this, container, 0.9);
|
||||
}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage {
|
||||
return new UpdateGameObjectMessage(this, ['center']);
|
||||
return new UpdateGameObjectMessage(this, ['center', 'strength']);
|
||||
}
|
||||
|
||||
public get boundingBox(): ImmutableBoundingBox {
|
||||
|
|
@ -59,12 +71,20 @@ export class ProjectilePhysical
|
|||
}
|
||||
|
||||
public onCollision(other: GameObject) {
|
||||
if (this.bounceCount++ === settings.projectileMaxBounceCount) {
|
||||
if (
|
||||
!(other instanceof PlayerCharacterPhysical && other.team === this.team) &&
|
||||
this.bounceCount++ === settings.projectileMaxBounceCount
|
||||
) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public step(deltaTime: number) {
|
||||
if ((this.strength -= settings.projectileFadeSpeed * deltaTime) < 0) {
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
const gravity = vec2.create();
|
||||
const intersecting = this.container.findIntersecting(this.boundingBox);
|
||||
intersecting.forEach((i) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue