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
|
pub use crate::error::{Error, Result};
pub use crate::game::Game;
pub mod entity;
pub mod physics;
pub mod structure;
mod error;
mod game;
pub trait Engine {
fn get_colliders<C: crate::physics::Collider>(&self) -> Vec<C>;
}
pub trait Render {
fn render_map(&self) -> &std::collections::HashMap<crate::physics::Point, char>;
fn render<W: std::io::Write>(&self, w: &mut W) -> crate::Result<()> {
for (p, c) in self.render_map() {
write!(w, "{}{}", termion::cursor::Goto(p.x, p.y), c)?
}
Ok(())
}
}
pub trait Derender {
fn derender_map(&self) -> &std::collections::HashMap<crate::physics::Point, char>;
fn derender<W: std::io::Write>(&self, w: &mut W) -> crate::Result<()> {
for p in self.derender_map().keys() {
write!(w, "{}\x08", termion::cursor::Goto(p.x, p.y))?
}
Ok(())
}
}
impl<T: Render> Derender for T {
fn derender_map(&self) -> &std::collections::HashMap<crate::physics::Point, char> {
self.render_map()
}
}
|