-
Notifications
You must be signed in to change notification settings - Fork 6
/
rendering.rs
61 lines (53 loc) · 1.74 KB
/
rendering.rs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Draws a clock in the corner of the screen.
#![warn(future_incompatible, rust_2018_compatibility, rust_2018_idioms, unused)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![warn(clippy::all)]
use std::{error::Error, f32::consts::PI};
fn main() -> Result<(), Box<dyn Error>> {
let rlbot = rlbot::init()?;
rlbot.start_match(&rlbot::MatchSettings::allstar_vs_allstar(
"Leonardo",
"Michelangelo",
))?;
rlbot.wait_for_match_start()?;
let mut packets = rlbot.packeteer();
loop {
let packet = packets.next()?;
let mut total_ms = (packet.game_info.seconds_elapsed * 1000.0) as i32;
let ms = total_ms % 1000;
total_ms -= ms;
let sec = total_ms / 1000 % 60;
total_ms -= sec * 1000;
let min = total_ms / 1000 / 60;
let center_x = 100.0;
let center_y = 150.0;
let clock_hand = |fraction: f32, radius: f32| {
let t = fraction * 2.0 * PI - PI / 2.0;
(center_x + t.cos() * radius, center_y + t.sin() * radius)
};
let mut group = rlbot.begin_render_group(0);
let green = group.color_rgb(0, 255, 0);
group.draw_string_2d(
(40.0, 20.0),
(2, 2),
format!("{}:{:02}.{:03}", min, sec, ms),
green,
);
group.draw_line_2d(
(center_x, center_y),
clock_hand(min as f32 / 60.0, 60.0),
green,
);
group.draw_line_2d(
(center_x, center_y),
clock_hand(sec as f32 / 60.0, 80.0),
green,
);
group.draw_line_2d(
(center_x, center_y),
clock_hand(ms as f32 / 1000.0, 40.0),
green,
);
group.render()?;
}
}