common.rs 888 B

1234567891011121314151617181920212223242526272829
  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. map.tiles[idx] = TileType::Floor;
  8. }
  9. }
  10. }
  11. pub fn apply_horizontal_tunnel(map : &mut Map, x1:i32, x2:i32, y:i32) {
  12. for x in min(x1,x2) ..= max(x1,x2) {
  13. let idx = map.xy_idx(x, y);
  14. if idx > 0 && idx < map.width as usize * map.height as usize {
  15. map.tiles[idx as usize] = TileType::Floor;
  16. }
  17. }
  18. }
  19. pub fn apply_vertical_tunnel(map : &mut Map, y1:i32, y2:i32, x:i32) {
  20. for y in min(y1,y2) ..= max(y1,y2) {
  21. let idx = map.xy_idx(x, y);
  22. if idx > 0 && idx < map.width as usize * map.height as usize {
  23. map.tiles[idx as usize] = TileType::Floor;
  24. }
  25. }
  26. }