aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIago Garrido <iago086@gmail.com>2019-11-12 16:11:21 +0100
committerIago Garrido <iago086@gmail.com>2019-11-12 16:11:21 +0100
commit34bdb3387e2cd4228aef39620be4d68ef3d7434b (patch)
treebfcbc38ebe6cf8e155fe29efa0176f0aebef8612
parent897efb3c736bac223df8c23722222797f65a33f9 (diff)
parentd249f7a63f007fcc494e4c446c4845e4f9d0a523 (diff)
Merge remote-tracking branch 'upstream/master'
-rw-r--r--src/entities.rs41
-rw-r--r--src/main.rs16
-rw-r--r--src/state.rs15
-rw-r--r--src/tiling.rs21
-rw-r--r--src/world.rs37
5 files changed, 65 insertions, 65 deletions
diff --git a/src/entities.rs b/src/entities.rs
index 145741c..a01d86a 100644
--- a/src/entities.rs
+++ b/src/entities.rs
@@ -1,6 +1,7 @@
use std::cmp;
-use crate::world::{Point, Direction};
+use pancurses::{Window};
+use crate::world::{Point};
use crate::tiling::TileType;
pub trait Entity {
@@ -13,15 +14,20 @@ pub struct Character {
pub name: String,
pub class: String,
pub health: i32,
+ pub level: i32,
+ pub location: Point,
max_health: i32,
attack: i32,
dodge: i32,
luck: i32,
xp: i32,
- location: Point,
tile_type: TileType
}
+pub trait Render {
+ fn render(&self, window: &Window);
+}
+
pub trait Enemy {
fn new(
class: String,
@@ -43,6 +49,7 @@ pub trait Player {
attack: i32,
dodge: i32,
luck: i32,
+ level: i32,
location: Point
) -> Self;
fn damage(&mut self, damage_amount: i32);
@@ -50,7 +57,23 @@ pub trait Player {
fn attack(&self) -> i32;
fn dodge(&self) -> i32;
fn stats(&self) -> String;
- fn walk(&mut self, dir: Direction);
+}
+
+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 {
@@ -83,6 +106,7 @@ impl Enemy for Character {
attack,
dodge,
luck,
+ level: 0,
xp: 0,
location: location,
tile_type: TileType::Character
@@ -102,6 +126,7 @@ impl Player for Character {
attack: i32,
dodge: i32,
luck: i32,
+ level: i32,
location: Point
) -> Character {
Character {
@@ -113,20 +138,12 @@ impl Player for Character {
dodge: dodge,
luck: luck,
xp: 0,
+ level: 0,
location: location,
tile_type: TileType::Player
}
}
- fn walk(&mut self, dir: Direction) {
- match dir {
- Direction::North => { (); },
- Direction::South => { (); },
- Direction::East => { (); },
- Direction::West => { (); }
- }
- }
-
fn damage(&mut self, damage_amount: i32) {
self.health = cmp::max(0, self.health - damage_amount);
self.xp += 2;
diff --git a/src/main.rs b/src/main.rs
index 12e92c9..b59d587 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,7 +17,7 @@ use pancurses::{
noecho
};
use state::State;
-use world::Dungeon;
+use world::{Dungeon};
fn main() {
@@ -31,6 +31,7 @@ fn main() {
10,
10,
20,
+ 1,
(0, 0)
),
Dungeon::new(window.get_max_x() as usize, window.get_max_y() as usize, 5),
@@ -38,18 +39,16 @@ fn main() {
state.init();
- // Dump the whole dungeon structure in terminal for debugging
- state.debug();
-
- state.render_level(&window);
-
window.keypad(true);
noecho();
-
+
loop {
// update actors
+
+ state.render_level(&window);
+
// update character
- window.refresh();
+ state.show_character(&window);
// get input and execute it
match window.getch() {
@@ -63,6 +62,7 @@ fn main() {
Some(_) => (),
None => (),
}
+ // actors actions (normally attack / interact if on same location as the character)
}
endwin();
}
diff --git a/src/state.rs b/src/state.rs
index f2ec249..8d0b164 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,19 +27,14 @@ impl State {
self.player.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);
+ }
+
fn current_level(&self) -> &Level {
&self.dungeon.levels[self.level]
}
diff --git a/src/tiling.rs b/src/tiling.rs
index 9684302..fbaae40 100644
--- a/src/tiling.rs
+++ b/src/tiling.rs
@@ -1,3 +1,8 @@
+extern crate pancurses;
+
+use pancurses::{Window};
+
+
pub struct TileGrid {
grid: Vec<Vec<TileType>>
}
@@ -36,6 +41,22 @@ impl TileGrid {
}
}
+fn tile_to_str(tile: &TileType) -> &str {
+ match tile {
+ TileType::Floor => ".",
+ TileType::Wall => "#",
+ TileType::Empty => " ",
+ TileType::StairsDown => ">",
+ TileType::StairsUp => "<",
+ TileType::Player => "@",
+ _ => "?"
+ }
+}
+
+pub fn draw_block(window: &Window, block: &TileType) {
+ window.printw(tile_to_str(block));
+}
+
pub trait Tileable {
fn tile(&self, grid: &mut TileGrid) -> Result<(), String>;
}
diff --git a/src/world.rs b/src/world.rs
index bf8b498..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,39 +187,6 @@ impl Dungeon {
levels: vec![]
}
}
-
- pub fn debug_levels(&self) {
- for l in &self.levels {
- Dungeon::debug_level(l);
- }
- }
-
- fn draw_block(window: &Window, block: &TileType) {
- window.printw(Dungeon::tile_to_str(block));
- }
-
- 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");
- }
- }
-
- fn tile_to_str(tile: &TileType) -> &str {
- match tile {
- TileType::Floor => ".",
- TileType::Wall => "#",
- TileType::Empty => " ",
- TileType::StairsDown => ">",
- TileType::StairsUp => "<",
- TileType::Player => "@",
- _ => "?"
- }
- }
}
impl Generatable for Dungeon {
@@ -286,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);
}