Improve gameplay and design
This commit is contained in:
parent
af616042f3
commit
1d1bc6655c
15 changed files with 163 additions and 74 deletions
|
|
@ -155,20 +155,13 @@ export class PlayerCharacterPhysical
|
|||
return;
|
||||
}
|
||||
|
||||
const start = vec2.clone(this.center);
|
||||
const direction = vec2.subtract(vec2.create(), position, start);
|
||||
const direction = vec2.subtract(vec2.create(), position, this.center);
|
||||
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,
|
||||
vec2.clone(this.center),
|
||||
20,
|
||||
this.colorIndex,
|
||||
strength,
|
||||
|
|
@ -192,10 +185,6 @@ export class PlayerCharacterPhysical
|
|||
return this.head.center;
|
||||
}
|
||||
|
||||
public get velocity(): vec2 {
|
||||
return this.head.velocity;
|
||||
}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return (
|
||||
Math.min(
|
||||
|
|
@ -272,17 +261,18 @@ export class PlayerCharacterPhysical
|
|||
} else {
|
||||
const leftFootGravity = this.currentPlanet!.getForce(this.leftFoot.center);
|
||||
const rightFootGravity = this.currentPlanet!.getForce(this.rightFoot.center);
|
||||
if (movementForce.y > settings.maxAcceleration / 4) {
|
||||
|
||||
if (this.lastMovementWasRelative) {
|
||||
vec2.rotate(movementForce, movementForce, vec2.create(), this.direction);
|
||||
}
|
||||
|
||||
if (vec2.dot(movementForce, actualGravity) < -vec2.length(movementForce) * 0.8) {
|
||||
vec2.scale(leftFootGravity, leftFootGravity, 0.35);
|
||||
vec2.scale(rightFootGravity, rightFootGravity, 0.35);
|
||||
}
|
||||
this.applyForce(this.leftFoot, leftFootGravity, deltaTime);
|
||||
this.applyForce(this.rightFoot, rightFootGravity, deltaTime);
|
||||
|
||||
if (this.lastMovementWasRelative) {
|
||||
vec2.rotate(movementForce, movementForce, vec2.create(), this.direction);
|
||||
}
|
||||
|
||||
const headGravity = this.currentPlanet!.getForce(this.head.center);
|
||||
|
||||
if (vec2.length(headGravity) < vec2.length(actualGravity) / 2) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ 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';
|
||||
|
||||
@serializesTo(ProjectileBase)
|
||||
export class ProjectilePhysical
|
||||
|
|
@ -41,6 +42,26 @@ export class ProjectilePhysical
|
|||
) {
|
||||
super(id(), center, radius, colorIndex, strength);
|
||||
this.object = new CirclePhysical(center, radius, this, container, 0.9);
|
||||
|
||||
this.moveOutsideOfObject();
|
||||
}
|
||||
|
||||
private moveOutsideOfObject() {
|
||||
let wasCollision = true;
|
||||
const delta = vec2.scale(
|
||||
vec2.create(),
|
||||
vec2.normalize(vec2.create(), this.velocity),
|
||||
10,
|
||||
);
|
||||
while (wasCollision) {
|
||||
const intersecting = this.container
|
||||
.findIntersecting(this.boundingBox)
|
||||
.filter((g) => g instanceof PlayerCharacterPhysical && g.team === this.team);
|
||||
const { hitSurface } = moveCircle(this.object, delta, intersecting, true);
|
||||
wasCollision = hitSurface;
|
||||
}
|
||||
vec2.add(this.center, this.center, delta);
|
||||
vec2.add(this.center, this.center, delta);
|
||||
}
|
||||
|
||||
public calculateUpdates(): UpdateObjectMessage {
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@ import { PhysicalBase } from '../physicals/physical-base';
|
|||
export const evaluateSdf = (target: vec2, objects: Array<PhysicalBase>) =>
|
||||
objects
|
||||
.filter((i) => i.canCollide)
|
||||
.reduce((min, i) => (min = Math.min(min, i.distance(target))), 1000);
|
||||
.reduce((min, i) => (min = Math.min(min, i.distance(target))), 1000000);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const moveCircle = (
|
|||
circle: CirclePhysical,
|
||||
delta: vec2,
|
||||
possibleIntersectors: Array<Physical>,
|
||||
ignoreCollision = false,
|
||||
): {
|
||||
realDelta: vec2;
|
||||
hitSurface: boolean;
|
||||
|
|
@ -38,12 +39,16 @@ export const moveCircle = (
|
|||
(i) => i.distance(nextCircle.center) <= circle.radius,
|
||||
)!;
|
||||
|
||||
if (reactsToCollision(intersecting)) {
|
||||
intersecting.onCollision(circle.gameObject);
|
||||
}
|
||||
if (ignoreCollision) {
|
||||
circle.center = vec2.add(circle.center, circle.center, delta);
|
||||
} else {
|
||||
if (reactsToCollision(intersecting)) {
|
||||
intersecting.onCollision(circle.gameObject);
|
||||
}
|
||||
|
||||
if (reactsToCollision(circle)) {
|
||||
circle.onCollision(intersecting.gameObject);
|
||||
if (reactsToCollision(circle)) {
|
||||
circle.onCollision(intersecting.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
const dx =
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import { PhysicalContainer } from '../physics/containers/physical-container';
|
|||
import { getBoundingBoxOfCircle } from '../physics/functions/get-bounding-box-of-circle';
|
||||
import { isCircleIntersecting } from '../physics/functions/is-circle-intersecting';
|
||||
import { PlayerCharacterPhysical } from '../objects/player-character-physical';
|
||||
import { Physical } from '../physics/physicals/physical';
|
||||
import { freeTeam, requestTeam } from './player-team-service';
|
||||
import { PlanetPhysical } from '../objects/planet-physical';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue