Improve multiplayer

This commit is contained in:
schmelczerandras 2020-10-08 13:16:05 +02:00 committed by Schmelczer András
parent 220b20476f
commit 37954e2ef1
29 changed files with 321 additions and 267 deletions

View file

@ -0,0 +1,22 @@
import { vec2 } from 'gl-matrix';
import { Rectangle, settings } from '../main';
export const calculateViewArea = (
center: vec2,
aspectRatio: number,
oversizeRatio = 1,
): Rectangle => {
const viewArea = new Rectangle();
viewArea.size = vec2.fromValues(
Math.sqrt(settings.inViewAreaSize * oversizeRatio * aspectRatio),
Math.sqrt((settings.inViewAreaSize * oversizeRatio) / aspectRatio),
);
viewArea.topLeft = vec2.fromValues(
center.x - viewArea.size.x / 2,
center.y + viewArea.size.y / 2,
);
return viewArea;
};

View file

@ -9,6 +9,10 @@ export class Circle {
return vec2.distance(this.center, target) - this.radius;
}
public distanceBetween(target: Circle): number {
return vec2.distance(target.center, this.center) - this.radius - target.radius;
}
public toArray(): Array<any> {
return [this.center, this.radius];
}