Browse Source

Made camera follow player

master
Graham Northup 3 years ago
parent
commit
ad63cfeeb1
Signed by: grissess GPG Key ID: 5D000E6F539376FB
  1. 4
      src/main.rs
  2. 8
      src/world/mod.rs

4
src/main.rs

@ -33,10 +33,10 @@ fn main() -> io::Result<()>
w.player_mut().set_pos(ppos);
let (width, height) = termion::terminal_size()?;
let rs = world::render::RenderState::new(V2i(width as isize, height as isize));
let mut rs = world::render::RenderState::new(V2i(width as isize, height as isize));
loop {
w.render(&rs, &mut stdout);
w.render(&mut rs, &mut stdout);
stdout.flush();
w.step();
}

8
src/world/mod.rs

@ -102,7 +102,13 @@ impl World {
self.entities.push(RefCell::new(ent));
}
pub fn render<W: Write>(&self, rs: &render::RenderState, mut out: &mut W) -> io::Result<()> {
pub fn render<W: Write>(&self, rs: &mut render::RenderState, mut out: &mut W) -> io::Result<()> {
let ppos = self.player().pos();
let center = rs.center();
if (ppos - center).l2_sq() > 225 {
rs.recenter(ppos);
}
rs.render(&self.region(), &mut render::InvertRenderer, &mut out)?;
let sr = rs.screen_rect();
for eref in self.entities() {

Loading…
Cancel
Save