clean map
This commit is contained in:
parent
91cff202f6
commit
753a50bf85
3 changed files with 46 additions and 45 deletions
46
src/map.ml
46
src/map.ml
|
|
@ -9,19 +9,39 @@ type background =
|
|||
| Water
|
||||
| Black
|
||||
|
||||
type t = background array array
|
||||
|
||||
let width = 1000
|
||||
|
||||
let height = 1000
|
||||
|
||||
let player_pos = ref (20, 3)
|
||||
|
||||
let player_dir = ref Down
|
||||
type t =
|
||||
{ tiles : background array array
|
||||
; mutable player_pos : int * int
|
||||
; mutable player_dir : dir
|
||||
; width : int
|
||||
; height : int
|
||||
}
|
||||
|
||||
let init () =
|
||||
Array.init width (fun _x ->
|
||||
Array.init height (fun _y ->
|
||||
if Random.int 1000 <= 42 then Water else Grass ) )
|
||||
let width = 1000 in
|
||||
let height = 1000 in
|
||||
let tiles =
|
||||
Array.init width (fun _x ->
|
||||
Array.init height (fun _y ->
|
||||
if Random.int 1000 <= 42 then Water else Grass ) )
|
||||
in
|
||||
{ tiles; player_pos = (20, 3); player_dir = Down; width; height }
|
||||
|
||||
let get_tile_kind ~x ~y map = try map.(x).(y) with Invalid_argument _ -> Black
|
||||
let get_tile_kind ~x ~y map =
|
||||
try map.tiles.(x).(y) with Invalid_argument _ -> Black
|
||||
|
||||
let move map dir =
|
||||
if map.player_dir = dir then begin
|
||||
let x, y = map.player_pos in
|
||||
let x, y =
|
||||
match 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 -> ()
|
||||
| Grass -> map.player_pos <- (x, y)
|
||||
end
|
||||
else map.player_dir <- dir
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue