multi_movement/
multi-movement.rs

1//! An example of [`fps_gameloop!`] in action
2
3use std::{thread, time::Duration};
4
5use gemini_engine::{
6    core::{ColChar, Vec2D},
7    primitives::Rect,
8    view::{View, WrappingMode},
9};
10
11const BLOCK_SIZE: Vec2D = Vec2D::new(4, 2);
12const FILL_CHAR: ColChar = ColChar::SOLID;
13
14fn main() {
15    let mut view = View::new(50, 12, ColChar::BACKGROUND).with_wrapping_mode(WrappingMode::Wrap);
16
17    let mut blocks: Vec<Rect> = (0..=5)
18        .map(|offset| Rect::new(Vec2D::new(0, offset * 2), BLOCK_SIZE, FILL_CHAR))
19        .collect();
20
21    let mut i = 0;
22    loop {
23        if blocks.iter().all(|b| b.pos.x % view.width as i64 == 0) {
24            thread::sleep(Duration::from_secs(2));
25        };
26
27        i += 1;
28        for (j, block) in (0u32..).zip(blocks.iter_mut()) {
29            if i % 2_u32.pow(j) == 0 {
30                block.pos.x += 1;
31            }
32        }
33
34        view.clear();
35        for block in &blocks {
36            view.draw(block);
37        }
38        let _ = view.display_render();
39
40        thread::sleep(Duration::from_secs_f32(1.0 / 60.0));
41    }
42}