Re-draw entities when you walk over them

This also required making the noodles character not actually the emoji,
since the emoji being double-width means it still gets overwritten when
you walk to the right of it (D:)
This commit is contained in:
Griffin Smith 2019-07-28 21:32:24 -04:00
parent 10fb09eca2
commit ba7bec9a3e
4 changed files with 15 additions and 3 deletions

View file

@ -50,6 +50,6 @@ entity!(Character);
impl display::Draw for Character {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
write!(out, "@{}", cursor::Left(1),)
write!(out, "@")
}
}

View file

@ -2,7 +2,8 @@
"Item": {
"name": "noodles",
"char": {
"char": "🍜"
"char": "n",
"color": "yellow"
},
"description": "You know exactly what kind of noodles",
"edible_item": {

View file

@ -227,6 +227,17 @@ impl<'a> Game<'a> {
Ok(())
}
/// Draw all the game entities to the screen
fn draw_entities_at(&mut self, pos: Position) -> io::Result<()> {
for entity in self.entities.at(pos) {
self.viewport.draw(
entity,
&self.entities.neighbor_entities(entity.position()),
)?;
}
Ok(())
}
/// Draw the game entity with the given ID, if any, to the screen
fn draw_entity(&mut self, entity_id: EntityID) -> io::Result<bool> {
if let Some(entity) = self.entities.get(entity_id) {
@ -438,6 +449,7 @@ impl<'a> Game<'a> {
self.viewport.game_cursor_position =
character.position;
self.viewport.clear(old_pos)?;
self.draw_entities_at(old_pos)?;
self.draw_entity(self.character_entity_id)?;
self.tick(
self.character().speed().tiles_to_ticks(

View file

@ -153,7 +153,6 @@ impl<'a, Env> Promises<'a, Env> {
}
pub fn give_all(&mut self, env: &mut Env) {
debug!("promises: {}", self.ps.len());
self.ps.retain(|p| !p.give(env));
}
}