optim
This commit is contained in:
parent
161273e33b
commit
009a6e8ad5
1 changed files with 4 additions and 8 deletions
|
|
@ -94,16 +94,12 @@ let kb_handler ev =
|
||||||
let x, y = !Map.player_pos in
|
let x, y = !Map.player_pos in
|
||||||
let x, y =
|
let x, y =
|
||||||
match ev |> Ev.as_type |> Ev.Keyboard.code |> Jstr.to_string with
|
match ev |> Ev.as_type |> Ev.Keyboard.code |> Jstr.to_string with
|
||||||
| "KeyW" | "ArrowUp" -> (x, y - 1)
|
| "KeyW" | "ArrowUp" -> (x, max 0 (y - 1))
|
||||||
| "KeyA" | "ArrowLeft" -> (x - 1, y)
|
| "KeyA" | "ArrowLeft" -> (max 0 (x - 1), y)
|
||||||
| "KeyS" | "ArrowDown" -> (x, y + 1)
|
| "KeyS" | "ArrowDown" -> (x, min (Map.height - 1) y + 1)
|
||||||
| "KeyD" | "ArrowRight" -> (x + 1, y)
|
| "KeyD" | "ArrowRight" -> (min (Map.width - 1) x + 1, y)
|
||||||
| _s -> (x, y)
|
| _s -> (x, y)
|
||||||
in
|
in
|
||||||
let x = max 0 x in
|
|
||||||
let x = min (Map.width - 1) x in
|
|
||||||
let y = max 0 y in
|
|
||||||
let y = min (Map.height - 1) y in
|
|
||||||
Map.player_pos := (x, y)
|
Map.player_pos := (x, y)
|
||||||
|
|
||||||
let rec game_loop state _timestamp =
|
let rec game_loop state _timestamp =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue