implement grid offset
This commit is contained in:
parent
2945e7d478
commit
feebcd3841
5 changed files with 141 additions and 53 deletions
26
src/map.ml
26
src/map.ml
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue