Room Creating: Place Kitchen Furniture #11

Merged
msrd0 merged 19 commits from room-creation-placing-furniture into main 2024-07-07 11:54:43 +00:00
Showing only changes of commit a614cd0644 - Show all commits

View file

@ -18,12 +18,14 @@ enum RoomType {
SleepingRoom SleepingRoom
} }
type Tile = (Vec2, Vec2, Furniture); //(pos, size, furniture)
#[derive(Debug)] #[derive(Debug)]
pub struct Room { pub struct Room {
room_type: RoomType, room_type: RoomType,
pub size: (u8, u8), //(width, height) pub size: (u8, u8), //(width, height)
pub grid: Grid, pub grid: Grid,
furnitures: Vec<(Vec2, Vec2, Furniture)> //(pos, size, furniture) furnitures: Vec<Tile>
} }
impl RoomType { impl RoomType {
@ -44,25 +46,7 @@ impl Room {
let room_type = RoomType::random(); let room_type = RoomType::random();
let size = Self::random_size(&room_type); let size = Self::random_size(&room_type);
let mut furnitures = Vec::new(); let furnitures = Self::random_room_furniture(&room_type, size, ctx);
if room_type == RoomType::Kitchen {
furnitures.push((
vec2(0.0, 0.0),
vec2(1.0, 2.0),
Furniture::new("kitchen", "fridge", ctx)
));
furnitures.push((
vec2(1.0, 0.0),
vec2(1.0, 1.0),
Furniture::new("kitchen", "dishwasher", ctx)
));
furnitures.push((
vec2(1.0, 1.0),
vec2(0.75, 0.75),
Furniture::new("kitchen", "blender", ctx)
));
}
Room { Room {
room_type, room_type,
@ -73,6 +57,9 @@ impl Room {
} }
fn random_size(room_type: &RoomType) -> (u8, u8) { fn random_size(room_type: &RoomType) -> (u8, u8) {
//Kitchen + Living Room 5-8
//Bath + sleepingroom 4-6
//Toilet 2-3
match room_type { match room_type {
RoomType::Kitchen | RoomType::LivingRoom => (random_i32(5, 8) as u8, 3), RoomType::Kitchen | RoomType::LivingRoom => (random_i32(5, 8) as u8, 3),
RoomType::Bath | RoomType::SleepingRoom => (random_i32(4, 6) as u8, 3), RoomType::Bath | RoomType::SleepingRoom => (random_i32(4, 6) as u8, 3),
@ -80,6 +67,34 @@ impl Room {
} }
} }
fn random_room_furniture(room_type: &RoomType, size: (u8, u8), ctx: &mut EngineContext<'_>) -> Vec<Tile> {
let mut furnitures = Vec::new();
let width = size.0;
match room_type {
RoomType::Kitchen => {
furnitures.push((
vec2(0.0, 0.0),
vec2(1.0, 2.0),
Furniture::new("kitchen", "fridge", ctx)
));
furnitures.push((
vec2(1.0, 0.0),
vec2(1.0, 1.0),
Furniture::new("kitchen", "dishwasher", ctx)
));
furnitures.push((
vec2(1.0, 1.0),
vec2(0.75, 0.75),
Furniture::new("kitchen", "blender", ctx)
));
}
_ => {}
}
furnitures
}
fn create_grid(width: u8, height: u8) -> Grid { fn create_grid(width: u8, height: u8) -> Grid {
error!("START GRID CREATION!"); error!("START GRID CREATION!");
let left_border = width as f32 / 2.0; let left_border = width as f32 / 2.0;