rustaceanmark/
rustaceanmark.rs

1use macroquad::prelude::*;
2
3struct Rustaceane {
4    pos: Vec2,
5    speed: Vec2,
6    color: Color,
7}
8
9#[macroquad::main("Rustaceanmark")]
10async fn main() {
11    let mut rustaceanes: Vec<Rustaceane> = Vec::new();
12    let rustacean_tex = load_texture("examples/rustacean_happy.png").await.unwrap();
13    rustacean_tex.set_filter(FilterMode::Nearest);
14
15    loop {
16        clear_background(Color::default());
17
18        if macroquad::input::is_mouse_button_down(MouseButton::Left) {
19            for _i in 0..100 {
20                rustaceanes.push(Rustaceane {
21                    pos: Vec2::from(macroquad::input::mouse_position()),
22                    speed: Vec2::new(
23                        rand::gen_range(-250., 250.) / 60.,
24                        rand::gen_range(-250., 250.) / 60.,
25                    ),
26                    color: Color::from_rgba(
27                        rand::gen_range(50, 240),
28                        rand::gen_range(80, 240),
29                        rand::gen_range(100, 240),
30                        255,
31                    ),
32                })
33            }
34        }
35
36        for rustaceane in &mut rustaceanes {
37            rustaceane.pos += rustaceane.speed;
38
39            if ((rustaceane.pos.x + rustacean_tex.width() / 2.) > screen_width())
40                || ((rustaceane.pos.x + rustacean_tex.width() / 2.) < 0.)
41            {
42                rustaceane.speed.x *= -1.;
43            }
44            if ((rustaceane.pos.y + rustacean_tex.height() / 2.) > screen_height())
45                || ((rustaceane.pos.y + rustacean_tex.height() / 2.) < 0.)
46            {
47                rustaceane.speed.y *= -1.;
48            }
49
50            draw_texture(
51                &rustacean_tex,
52                rustaceane.pos.x,
53                rustaceane.pos.y,
54                rustaceane.color,
55            );
56        }
57
58        draw_fps();
59        draw_text(
60            format!("Rustaceanes: {}", rustaceanes.len()).as_str(),
61            0.,
62            32.,
63            32.,
64            WHITE,
65        );
66
67        next_frame().await
68    }
69}