Skip to main content

custom_init/
custom_init.rs

1use sge::prelude::*;
2
3struct PhysicsCircle {
4    circle: Circle,
5    velocity: Vec2,
6}
7
8fn main() -> anyhow::Result<()> {
9    let opts = EngineCreationOptions::builder()
10        .window_transparent(true)
11        .opengl_debug(true)
12        .dithering(false)
13        .opengl_profile(GlProfile::Core)
14        .default_magnify_filter(MagnifySamplerFilter::Nearest)
15        .log_verbosity(Verbosity::Medium)
16        .window_blur(true)
17        // .swap_interval(SwapInterval::DontWait)
18        .title("Custom init".to_string())
19        .build();
20
21    init_custom(opts)?;
22
23    let mut obj = PhysicsCircle {
24        circle: Circle {
25            center: Vec2::splat(300.0),
26            radius: Vec2::splat(100.0),
27            color: Color::RED_400,
28        },
29        velocity: vec2(100.0, 200.0),
30    };
31
32    run_async(async move {
33        loop {
34            clear_screen(Color::TRANSPARENT);
35
36            if obj.circle.center.x >= window_width() - obj.circle.radius.x
37                || obj.circle.center.x <= obj.circle.radius.x
38            {
39                obj.velocity.x = -obj.velocity.x;
40            }
41
42            if obj.circle.center.y >= window_height() - obj.circle.radius.y
43                || obj.circle.center.y <= obj.circle.radius.y
44            {
45                obj.velocity.y = -obj.velocity.y;
46            }
47
48            obj.circle.center += obj.velocity * physics_delta_time();
49            dbg!(obj.circle.center);
50
51            draw(&obj.circle);
52            draw_fps();
53
54            if should_quit() {
55                break;
56            }
57
58            next_frame().await;
59        }
60    });
61
62    Ok(())
63}