diff options
author | Luis Ferro <luis.ferro@eggplant.io> | 2019-11-12 14:23:00 +0100 |
---|---|---|
committer | Luis Ferro <luis.ferro@eggplant.io> | 2019-11-12 14:23:00 +0100 |
commit | e7b227ed268e8570518f9d1452b5e7d0d0a0ee32 (patch) | |
tree | 6b61750aa70389030a0c45edb596a06d4d2760a2 | |
parent | ec671aa9b56c53d76ce310f0772ee05c97064d3f (diff) |
Add player character in the map
-rw-r--r-- | src/character.rs | 9 | ||||
-rw-r--r-- | src/main.rs | 19 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/character.rs b/src/character.rs index 3e6c4a7..a62c51f 100644 --- a/src/character.rs +++ b/src/character.rs @@ -6,12 +6,13 @@ 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
}
pub trait Player {
@@ -22,6 +23,7 @@ pub trait Player { attack: i32,
dodge: i32,
luck: i32,
+ level: i32,
location: Point
) -> Character;
@@ -59,6 +61,7 @@ impl Player for Character { attack: i32,
dodge: i32,
luck: i32,
+ level: i32,
location: Point
) -> Character {
Character {
@@ -70,6 +73,7 @@ impl Player for Character { dodge: dodge,
luck: luck,
xp: 0,
+ level: 0,
location: location
}
}
@@ -86,6 +90,7 @@ impl Player for Character { self.attack,
self.dodge,
self.luck + player_luck,
+ 0,
(0,0)
)
}
@@ -139,7 +144,7 @@ mod tests { use super::*;
fn test_attack() {
- let player = Character::new("".to_string(), "Rogue".to_string(), 1, 4, 1, 4, (0,0));
+ let player = Character::new("".to_string(), "Rogue".to_string(), 1, 4, 1, 4, 0,(0,0));
assert_eq!(player.attack(), 6);
}
diff --git a/src/main.rs b/src/main.rs index c4c6f4f..08e1b25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,9 +60,10 @@ fn main() { let mut dungeon = Dungeon::new( window.get_max_x() as usize, - window.get_max_y() as usize - 2, + window.get_max_y() as usize - 2, // allow 2 lines for game stats 5 ); + dungeon.generate(); let start_location = dungeon.levels[0].get_start_point(); @@ -74,9 +75,9 @@ fn main() { 10, 10, 20, + 0, start_location ); - character.place(start_location); render_level(&window, &dungeon.levels[0]); @@ -85,7 +86,20 @@ fn main() { loop { // update actors + + // update character + window.mv(window.get_max_y() - 2, 0); + window.clrtoeol(); + + window.refresh(); + + window.addstr(character.stats() + "\n"); + window.addstr(character.info() + "\n"); + + window.mv(character.location.1 as i32,character.location.0 as i32); + window.refresh(); + draw_block(&window, &world::TileType::Character); window.refresh(); // get input and execute it @@ -100,6 +114,7 @@ fn main() { Some(_) => (), None => (), } + // actors actions (normally attack / interact if on same location as the character) } endwin(); } |