blob: 76ee2c0ce0a915c6ce631036a3251a82985bdd6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
Hurry Curry! - a game about cooking
Copyright (C) 2026 Hurry Curry! Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { camera } from "../main.ts";
import { ceil_v2, floor_v2 } from "../util.ts";
export interface MapLayer {
draw_map_layer(ctx: CanvasRenderingContext2D): void
}
export class GridLayer implements MapLayer {
draw_map_layer(ctx: CanvasRenderingContext2D): void {
ctx.strokeStyle = "#333"
ctx.lineWidth = 0.01
ctx.beginPath()
const min = floor_v2(camera.screen_to_world({ x: 0, y: 0 }))
const max = ceil_v2(camera.screen_to_world({ x: ctx.canvas.width, y: ctx.canvas.height }))
for (let x = min.x; x < max.x; x++) {
ctx.moveTo(x, min.y)
ctx.lineTo(x, max.y)
}
for (let y = min.y; y < max.y; y++) {
ctx.moveTo(min.x, y)
ctx.lineTo(max.x, y)
}
ctx.stroke()
}
}
|