common.rs 978 B

12345678910111213141516171819202122232425262728293031
  1. use super::{Map, Rect, TileType};
  2. use std::cmp::{max, min};
  3. pub fn apply_room_to_map(map : &mut Map, room : &Rect) {
  4. for y in room.y1 +1 ..= room.y2 {
  5. for x in room.x1 + 1 ..= room.x2 {
  6. let idx = map.xy_idx(x, y);
  7. if idx > 0 && idx < ((map.width * map.height)-1) as usize {
  8. map.tiles[idx] = TileType::Floor;
  9. }
  10. }
  11. }
  12. }
  13. pub fn apply_horizontal_tunnel(map : &mut Map, x1:i32, x2:i32, y:i32) {
  14. for x in min(x1,x2) ..= max(x1,x2) {
  15. let idx = map.xy_idx(x, y);
  16. if idx > 0 && idx < map.width as usize * map.height as usize {
  17. map.tiles[idx as usize] = TileType::Floor;
  18. }
  19. }
  20. }
  21. pub fn apply_vertical_tunnel(map : &mut Map, y1:i32, y2:i32, x:i32) {
  22. for y in min(y1,y2) ..= max(y1,y2) {
  23. let idx = map.xy_idx(x, y);
  24. if idx > 0 && idx < map.width as usize * map.height as usize {
  25. map.tiles[idx as usize] = TileType::Floor;
  26. }
  27. }
  28. }