Add basic multiplayer
This commit is contained in:
parent
0f0a1eaf67
commit
46a48e7c15
1 changed files with 1361 additions and 753 deletions
36
frontend/src/scripts/objects/camera.ts
Normal file
36
frontend/src/scripts/objects/camera.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { CommandExecutors, GameObject, Rectangle, settings } from 'shared';
|
||||
import { RenderCommand } from '../commands/types/render';
|
||||
|
||||
export class Camera extends GameObject {
|
||||
private static readonly inViewAreaSize = settings.inViewAreaSize;
|
||||
private _viewArea = new Rectangle();
|
||||
|
||||
protected commandExecutors: CommandExecutors = {
|
||||
[RenderCommand.type]: this.draw.bind(this),
|
||||
};
|
||||
|
||||
constructor(public center: vec2 = vec2.create()) {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public get viewArea(): Rectangle {
|
||||
return this._viewArea;
|
||||
}
|
||||
|
||||
private draw(c: RenderCommand) {
|
||||
const canvasAspectRatio = c.renderer.canvasSize.x / c.renderer.canvasSize.y;
|
||||
|
||||
this._viewArea.topLeft = vec2.fromValues(
|
||||
this.center.x - this._viewArea.size.x / 2,
|
||||
this.center.y + this._viewArea.size.y / 2
|
||||
);
|
||||
|
||||
this._viewArea.size = vec2.fromValues(
|
||||
Math.sqrt(Camera.inViewAreaSize * canvasAspectRatio),
|
||||
Math.sqrt(Camera.inViewAreaSize / canvasAspectRatio)
|
||||
);
|
||||
|
||||
c.renderer.setViewArea(this._viewArea.topLeft, this._viewArea.size);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue