Improve multiplayer
This commit is contained in:
parent
220b20476f
commit
37954e2ef1
29 changed files with 321 additions and 267 deletions
22
shared/src/helper/calculate-view-area.ts
Normal file
22
shared/src/helper/calculate-view-area.ts
Normal 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;
|
||||
};
|
||||
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue