implement grid offset

This commit is contained in:
zapashcanon 2023-01-15 00:48:47 +01:00
parent 2945e7d478
commit feebcd3841
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1
5 changed files with 141 additions and 53 deletions

View file

@ -53,17 +53,15 @@ let init () =
let get_tile_kind ~x ~y map =
try map.tiles.(x).(y) with Invalid_argument _ -> Black
let check_move map ({ x; y; dir } as pos) movement_dir =
if dir <> movement_dir then Ok { pos with dir = movement_dir }
else
let x, y =
match movement_dir with
| Left -> (x - 1, y)
| Right -> (x + 1, y)
| Down -> (x, y + 1)
| Up -> (x, y - 1)
in
match get_tile_kind ~x ~y map with
| (Black | Water) as bg ->
Error (Format.asprintf "can't move on %a" pp_background bg)
| Grass -> Ok { pos with x; y }
let check_move map ({ x; y; _ } as pos) movement_dir =
let x, y =
match movement_dir with
| Left -> (x - 1, y)
| Right -> (x + 1, y)
| Down -> (x, y + 1)
| Up -> (x, y - 1)
in
match get_tile_kind ~x ~y map with
| (Black | Water) as bg ->
Error (Format.asprintf "can't move on %a" pp_background bg)
| Grass -> Ok { pos with x; y }