diff options
| author | LLLL Colonq <llll@colonq> | 2026-08-17 20:14:16 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-08-17 20:14:16 -0400 |
| commit | de99c5f7636a952025ea13de02bafd25bcb6bdec (patch) | |
| tree | be359424af4f6717103e3b667b6529ae5a4b4e6a /2026/games_submissions/crm148/view.js | |
| parent | 4d4d1f24721f27fbf37e1070be6414de130ace61 (diff) | |
Fix broken
Diffstat (limited to '2026/games_submissions/crm148/view.js')
| -rw-r--r-- | 2026/games_submissions/crm148/view.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/2026/games_submissions/crm148/view.js b/2026/games_submissions/crm148/view.js new file mode 100644 index 0000000..1d2fb5c --- /dev/null +++ b/2026/games_submissions/crm148/view.js @@ -0,0 +1,32 @@ + +import Vec2 from './vec2.js'; + +class View { + center = Vec2.zero(); + zoom = 1.0; + + // Convert game coordinate to canvas coordinate + project(vec2) { + return new Vec2( + (gameCanvas.width / 2) + ((vec2.x - this.center.x) * this.zoom), + (gameCanvas.height / 2) - ((vec2.y - this.center.y) * this.zoom)); + } + // Covert canvas coordinate to game coordinate + unproject(vec2) { + return new Vec2( + this.center.x + (vec2.x - (gameCanvas.width / 2)) / this.zoom, + this.center.y - (vec2.y - (gameCanvas.height/2)) / this.zoom); + } +} + +function globalView() { + return gView; +} + +var gView = new View(); +window.view = gView; + +export { + View, + globalView, +} |
