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:
		
							parent
							
								
									10fb09eca2
								
							
						
					
					
						commit
						ba7bec9a3e
					
				
					 4 changed files with 15 additions and 3 deletions
				
			
		| 
						 | 
					@ -50,6 +50,6 @@ entity!(Character);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl display::Draw for Character {
 | 
					impl display::Draw for Character {
 | 
				
			||||||
    fn do_draw(&self, out: &mut Write) -> io::Result<()> {
 | 
					    fn do_draw(&self, out: &mut Write) -> io::Result<()> {
 | 
				
			||||||
        write!(out, "@{}", cursor::Left(1),)
 | 
					        write!(out, "@")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,8 @@
 | 
				
			||||||
  "Item": {
 | 
					  "Item": {
 | 
				
			||||||
    "name": "noodles",
 | 
					    "name": "noodles",
 | 
				
			||||||
    "char": {
 | 
					    "char": {
 | 
				
			||||||
      "char": "🍜"
 | 
					      "char": "n",
 | 
				
			||||||
 | 
					      "color": "yellow"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "description": "You know exactly what kind of noodles",
 | 
					    "description": "You know exactly what kind of noodles",
 | 
				
			||||||
    "edible_item": {
 | 
					    "edible_item": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/game.rs
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/game.rs
									
										
									
									
									
								
							| 
						 | 
					@ -227,6 +227,17 @@ impl<'a> Game<'a> {
 | 
				
			||||||
        Ok(())
 | 
					        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
 | 
					    /// Draw the game entity with the given ID, if any, to the screen
 | 
				
			||||||
    fn draw_entity(&mut self, entity_id: EntityID) -> io::Result<bool> {
 | 
					    fn draw_entity(&mut self, entity_id: EntityID) -> io::Result<bool> {
 | 
				
			||||||
        if let Some(entity) = self.entities.get(entity_id) {
 | 
					        if let Some(entity) = self.entities.get(entity_id) {
 | 
				
			||||||
| 
						 | 
					@ -438,6 +449,7 @@ impl<'a> Game<'a> {
 | 
				
			||||||
                            self.viewport.game_cursor_position =
 | 
					                            self.viewport.game_cursor_position =
 | 
				
			||||||
                                character.position;
 | 
					                                character.position;
 | 
				
			||||||
                            self.viewport.clear(old_pos)?;
 | 
					                            self.viewport.clear(old_pos)?;
 | 
				
			||||||
 | 
					                            self.draw_entities_at(old_pos)?;
 | 
				
			||||||
                            self.draw_entity(self.character_entity_id)?;
 | 
					                            self.draw_entity(self.character_entity_id)?;
 | 
				
			||||||
                            self.tick(
 | 
					                            self.tick(
 | 
				
			||||||
                                self.character().speed().tiles_to_ticks(
 | 
					                                self.character().speed().tiles_to_ticks(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,7 +153,6 @@ impl<'a, Env> Promises<'a, Env> {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn give_all(&mut self, env: &mut Env) {
 | 
					    pub fn give_all(&mut self, env: &mut Env) {
 | 
				
			||||||
        debug!("promises: {}", self.ps.len());
 | 
					 | 
				
			||||||
        self.ps.retain(|p| !p.give(env));
 | 
					        self.ps.retain(|p| !p.give(env));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue