diff options
author | Guillaume Pasquet <guillaume.pasquet@eggplant.io> | 2019-11-12 16:47:22 +0100 |
---|---|---|
committer | Guillaume Pasquet <guillaume.pasquet@eggplant.io> | 2019-11-12 16:47:22 +0100 |
commit | 8351d474150215598241b5aabacb4db863d0cd87 (patch) | |
tree | ac5a9f20f2795bca3e5c4208de6d6926bde4eb27 /src/state.rs | |
parent | dbaeddc419c2d070ce175ef2bcda9fa7c98c6941 (diff) |
Some refactor, better render loop
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/state.rs b/src/state.rs index 1f50f1a..afc702d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,38 +1,58 @@ use pancurses::Window; -use std::env; -use crate::entities::{Character, Entity, Render}; +use crate::tiling::{TileType, tile_to_str}; +use crate::entities::{Character, Entity}; use crate::world::{Dungeon, Generatable, Level}; pub struct State { - pub character: Character, + pub player: Character, pub dungeon: Dungeon, pub level: usize, } +pub fn draw_block(window: &Window, block: &TileType) { + window.printw(tile_to_str(block)); +} + impl State { pub fn new( - character: Character, + player: Character, dungeon: Dungeon, ) -> State { State { - character: character, - dungeon: dungeon, + player, + dungeon, level: 0, } } pub fn init(&mut self) { self.dungeon.generate(); - self.character.place(self.current_level().get_start_point()); + self.player.place(self.current_level().get_start_point()); } pub fn render_level(&self, window: &Window) { - self.current_level().render(window); + let grid = self.current_level().to_tilegrid().unwrap(); + + for (linenum, line) in grid.raw_data().iter().enumerate() { + for block in line.iter() { + draw_block(&window, &block); + } + window.mv(linenum as i32, 0); + } + } + + fn render_entity(&self, entity: &dyn Entity, window: &Window) { + window.mv(entity.get_location().1 as i32, entity.get_location().0 as i32); + draw_block(window, entity.get_tiletype()); + } + + pub fn render_entities(&self, window: &Window) { + // TODO } - pub fn show_character(&self, window: &Window) { - self.character.render(window); + pub fn render_player(&self, window: &Window) { + self.render_entity(&self.player, window) } fn current_level(&self) -> &Level { |