aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Ferro <luis.ferro@eggplant.io>2019-11-12 16:07:29 +0100
committerLuis Ferro <luis.ferro@eggplant.io>2019-11-12 16:07:29 +0100
commit8b11578ed5d2b254c7b0f827170aadac6490434b (patch)
tree4dd84347c10919c29d873210f02cf96b86b3e240
parent44146c74c913a72f79f94280a5daa40f33e6c05b (diff)
Rendering stuff
-rw-r--r--src/entities.rs22
-rw-r--r--src/main.rs5
-rw-r--r--src/state.rs23
-rw-r--r--src/tiling.rs2
-rw-r--r--src/world.rs21
5 files changed, 27 insertions, 46 deletions
diff --git a/src/entities.rs b/src/entities.rs
index 2d3078c..a01d86a 100644
--- a/src/entities.rs
+++ b/src/entities.rs
@@ -1,5 +1,6 @@
use std::cmp;
+use pancurses::{Window};
use crate::world::{Point};
use crate::tiling::TileType;
@@ -23,6 +24,10 @@ pub struct Character {
tile_type: TileType
}
+pub trait Render {
+ fn render(&self, window: &Window);
+}
+
pub trait Enemy {
fn new(
class: String,
@@ -54,6 +59,23 @@ pub trait Player {
fn stats(&self) -> String;
}
+impl Render for Character {
+ fn render(&self, window: &Window) {
+ // window.mv(window.get_max_y() - 2, 0);
+ // window.clrtoeol();
+
+ // window.refresh();
+
+ // window.addstr(self.character.info() + "\n");
+
+ // window.mv(self.character.location.1 as i32,self.character.location.0 as i32);
+ // window.refresh();
+ // draw_block(&window, self.character.tile_type);
+ // window.refresh();
+
+ }
+}
+
impl Entity for Character {
fn place(&mut self, location: Point) {
self.location = location;
diff --git a/src/main.rs b/src/main.rs
index 11cac4d..b59d587 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -39,9 +39,6 @@ fn main() {
state.init();
- // Dump the whole dungeon structure in terminal for debugging
- state.debug();
-
window.keypad(true);
noecho();
@@ -52,7 +49,7 @@ fn main() {
// update character
state.show_character(&window);
-
+
// get input and execute it
match window.getch() {
diff --git a/src/state.rs b/src/state.rs
index 6dad58e..1f50f1a 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -1,7 +1,7 @@
use pancurses::Window;
use std::env;
-use crate::entities::{Character, Entity};
+use crate::entities::{Character, Entity, Render};
use crate::world::{Dungeon, Generatable, Level};
pub struct State {
@@ -27,33 +27,12 @@ impl State {
self.character.place(self.current_level().get_start_point());
}
- pub fn debug(&self) {
- match env::var("DEBUG") {
- Ok(_) => {
- self.dungeon.debug_levels();
- },
- Err(_) => ()
- };
- }
-
pub fn render_level(&self, window: &Window) {
self.current_level().render(window);
}
pub fn show_character(&self, window: &Window) {
self.character.render(window);
-
- // window.mv(window.get_max_y() - 2, 0);
- // window.clrtoeol();
-
- // window.refresh();
-
- // window.addstr(self.character.info() + "\n");
-
- // window.mv(self.character.location.1 as i32,self.character.location.0 as i32);
- // window.refresh();
- // draw_block(&window, self.character.tile_type);
- // window.refresh();
}
fn current_level(&self) -> &Level {
diff --git a/src/tiling.rs b/src/tiling.rs
index 3e33de1..d443fb6 100644
--- a/src/tiling.rs
+++ b/src/tiling.rs
@@ -53,7 +53,7 @@ fn tile_to_str(tile: &TileType) -> &str {
}
}
-fn draw_block(window: &Window, block: &TileType) {
+pub fn draw_block(window: &Window, block: &TileType) {
window.printw(tile_to_str(block));
}
diff --git a/src/world.rs b/src/world.rs
index 42e4d7c..15c77e4 100644
--- a/src/world.rs
+++ b/src/world.rs
@@ -1,7 +1,7 @@
use rand::Rng;
use pancurses::{Window};
use crate::entities::{Entity};
-use crate::tiling::{TileGrid, Tileable, TileType};
+use crate::tiling::{TileGrid, Tileable, TileType, draw_block};
pub type Point = (usize, usize);
@@ -187,23 +187,6 @@ impl Dungeon {
levels: vec![]
}
}
-
- pub fn debug_levels(&self) {
- for l in &self.levels {
- Dungeon::debug_level(l);
- }
- }
-
- fn debug_level(level: &Level) {
- let grid = level.to_tilegrid().unwrap();
-
- for line in grid.raw_data().iter() {
- for block in line.iter() {
- print!("{}", Dungeon::tile_to_str(block));
- }
- print!("\n");
- }
- }
}
impl Generatable for Dungeon {
@@ -270,7 +253,7 @@ impl Level {
for (linenum, line) in grid.raw_data().iter().enumerate() {
for block in line.iter() {
- Dungeon::draw_block(&window, &block);
+ draw_block(&window, &block);
}
window.mv(linenum as i32, 0);
}