diff --git a/src/game_state/config.rs b/src/game_state/config.rs index 7d3faa87040fa27c983ceed2339a5740f82b1a18..e0857a78e634cf9d47ca37b8a6305a5f3d16a642 100644 --- a/src/game_state/config.rs +++ b/src/game_state/config.rs @@ -5,3 +5,5 @@ pub const BOARD_HEIGHT: usize = 19; pub const PLAYER_STARTING_AP: usize = 1; pub const PLAYER_STARTING_HP: usize = 10; + +pub const ROOM_NUMBER: usize = 20; diff --git a/src/game_state/level.rs b/src/game_state/level.rs index 9ce72954e3317bca32ae7303470503b71df21e50..6d160c94753de41862b96abaa3ea983e03da9204 100644 --- a/src/game_state/level.rs +++ b/src/game_state/level.rs @@ -78,9 +78,17 @@ impl Level { fn add_rooms(board: Board) -> Board{ let mut board = board.clone(); - for n in 0..config::ROOM_NUMBER{ + let mut rooms:Vec<Room> = Vec::new(); + for _n in 0..config::ROOM_NUMBER{ let r = Room::new(); board = r.carve(board); + rooms.push(r); + } + for r in &rooms{ + for r2 in &rooms{ + let p:Path = Path::new(Vec2::new(r.x,r.y), Vec2::new(r2.x,r2.y)); + board = p.carve(board); + } } board } @@ -162,10 +170,25 @@ impl Path{ } fn carve(&self, board: Board)->Board{ - let start: Node = Node::new(board, self.start); - let goal: Node = Node::new(board, self.goal); - let result = astar(&start, |p:Node|p.get_neighbours(), |p:Node|p.distance(&goal), |p:Node|p==goal); - + //let start: Node = Node::new(board, self.start); + //let goal: Node = Node::new(board, self.goal); + //let result = astar(&start, |p:Node|p.get_neighbours(), |p:Node|p.distance(&goal), |p:Node|p*==goal); + //assert_eq!(result.expect("no path found").1, 4); + let mut board = board.clone(); + for pos in self.plot_path().iter(){ + board[pos.x][pos.y] = Tile::Empty; + } + board + } + fn plot_path(&self)->Vec<Vec2<usize>>{ + let mut path: Vec<Vec2<usize>> = Vec::new(); + for x in self.start.x..self.goal.x{ + path.push(Vec2::new(x,self.start.y)); + } + for y in self.start.y..self.goal.y{ + path.push(Vec2::new(self.goal.x,y)); + } + path } } @@ -186,7 +209,7 @@ impl Node{ } fn get_neighbours(&self)->Vec<(Node, usize)>{ - let neighbours:Vec<(Node,usize)> = Vec::new(); + let mut neighbours:Vec<(Node,usize)> = Vec::new(); if self.pos.x>0{ let newpos: Vec2<usize> = Vec2::new(self.pos.x-1,self.pos.y); let tuple:(Node,usize) = (Node::new(self.board, newpos), Node::get_value(self.board, newpos));