-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.ml
More file actions
32 lines (26 loc) · 784 Bytes
/
animation.ml
File metadata and controls
32 lines (26 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
type kind =
| Title
| Wait
| Pawn_moving of (Game.Logic.pawn * Game.Logic.move)
| Menu_move of (int * int)
| Cannot_choose of (int * int * int * int)
| Victory
| Score_up of Game.playerNo
| Choice
| Sound of Themes.sound_type
type t = {id: int; length: float; start: float; kind: kind}
let is_active t =
let now = Unix.gettimeofday () in
now -. t.start <= t.length
let new_id = ref 0
let create ?(delay = 0.) ?(speed = 1.) length kind =
let id = !new_id in
incr new_id ;
let start = Unix.gettimeofday () +. delay in
{id; length= length /. speed; start; kind}
let progress t =
let now = Unix.gettimeofday () in
if now < t.start then 0.
else if now > t.start +. t.length then 1.
else (now -. t.start) /. t.length
let eq t1 t2 = t1.id = t2.id