pellest/src/island_client.ml
2022-12-06 02:31:33 +01:00

55 lines
1.2 KiB
OCaml

let tile_size = 40
let width = 835
let height = 635
let canvas = Jv.get Jv.global "canvas"
let context = Jv.call canvas "getContext" [| Jv.of_string "2d" |]
let init_bg () =
Jv.set canvas "width" (Jv.of_int width);
Jv.set canvas "height" (Jv.of_int height);
Jv.set context "fillStyle" (Jv.of_string "#FF1188");
Jv.call context "fillRect"
[| Jv.of_int 0; Jv.of_int 0; Jv.of_int width; Jv.of_int height |]
let window = Jv.get Jv.global "window"
let () =
let (_ : Jv.t) =
Jv.call window "addEventListener" [| Jv.of_string "load"; Jv.repr init_bg |]
in
()
let tiles_per_w = width / tile_size
let tiles_per_h = height / tile_size
let orig_x = (width - (tiles_per_w * tile_size)) / 2
let orig_y = (height - (tiles_per_h * tile_size)) / 2
let grass = Jv.get Jv.global "grass"
let draw_background () =
for x = 0 to tiles_per_w - 1 do
for y = 0 to tiles_per_h - 1 do
let (_ : Jv.t) =
Jv.call context "drawImage"
[| grass
; Jv.of_int (orig_x + (x * tile_size))
; Jv.of_int (orig_y + (y * tile_size))
|]
in
()
done
done
let () =
let (_ : Jv.t) =
Jv.call window "addEventListener"
[| Jv.of_string "load"; Jv.repr draw_background |]
in
()