File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ let draw_sprite (s : t) (r : Robot.t) =
22
22
| ALIVE ->
23
23
(* draw the scan radar *)
24
24
let res = r.scan_res in
25
- let dir = r.scan_degrees +. 90. in
25
+ let dir = get_screen_degrees r.scan_degrees +. 90. in
26
26
if r.scan_cycles > 0 then (
27
27
draw_circle_sector (V. create x y) scan_height (dir +. res)
28
28
(dir -. res) 1 (fade s.color 0.25 );
Original file line number Diff line number Diff line change 1
1
open Math
2
2
open CCFloat
3
3
4
+ let pr = Printf. printf
5
+ let debug = false
6
+
4
7
let _robot_size = 50.
5
8
let _robot_mass = 50.
6
9
let _max_x = 1000.
@@ -52,19 +55,26 @@ let scan degree resolution =
52
55
! cur_robot.scan_cycles < - _scan_duration;
53
56
! cur_robot.scan_degrees < - degree;
54
57
! cur_robot.scan_res < - res;
58
+ if debug then
59
+ pr " ###### %s is scanning at %f res %f\n " ! cur_robot.name degree resolution;
55
60
Array. iter
56
61
(fun r ->
57
- if Stdlib. (! cur_robot.id <> r.id && r.status <> DEAD ) then
58
- let v1, v2 = (rayvec_of_vector ! cur_robot.p, rayvec_of_vector r.p) in
59
- let d = V. angle v1 v2 * _rad2deg |> round |> normalize_degrees in
62
+ if Stdlib. (! cur_robot.id <> r.id && r.status <> DEAD ) then (
63
+ let x, y = (! cur_robot.p.x - r.p.x, ! cur_robot.p.y - r.p.y) in
64
+ let d =
65
+ (Float. atan2 y x * _rad2deg) + 180. |> round |> normalize_degrees
66
+ in
60
67
let d1, d2 =
61
68
(normalize_degrees (d - res), normalize_degrees (d + res))
62
69
in
70
+ if debug then
71
+ pr " testing %s at angle %f (%f < %f < %f)\n " r.name d d1 degree d2;
63
72
64
- if is_between d1 degree d2 then
65
- let distance = V. distance v1 v2 in
73
+ if is_between d1 degree d2 then (
74
+ if debug then pr " detected %s\n " r.name;
75
+ let distance = Math. distance ! cur_robot.p r.p in
66
76
if (0. < distance && distance < ! close_dist) || ! close_dist = 0. then
67
- close_dist := distance)
77
+ close_dist := distance)))
68
78
! all_robots;
69
79
! close_dist |> round |> to_int
70
80
You can’t perform that action at this time.
0 commit comments