Random furnitur skeleton

This commit is contained in:
Glaeder 2024-07-07 11:50:35 +02:00
parent c5ac0b39b2
commit a614cd0644

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,9 +46,33 @@ 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 { Room {
room_type,
size,
grid: Self::create_grid(size.0, size.1),
furnitures
}
}
fn random_size(room_type: &RoomType) -> (u8, u8) {
//Kitchen + Living Room 5-8
//Bath + sleepingroom 4-6
//Toilet 2-3
match room_type {
RoomType::Kitchen | RoomType::LivingRoom => (random_i32(5, 8) as u8, 3),
RoomType::Bath | RoomType::SleepingRoom => (random_i32(4, 6) as u8, 3),
RoomType::Toilett => (random_i32(2, 3) as u8, 3)
}
}
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(( furnitures.push((
vec2(0.0, 0.0), vec2(0.0, 0.0),
vec2(1.0, 2.0), vec2(1.0, 2.0),
@ -63,22 +89,11 @@ impl Room {
Furniture::new("kitchen", "blender", ctx) Furniture::new("kitchen", "blender", ctx)
)); ));
} }
_ => {}
}
Room {
room_type,
size,
grid: Self::create_grid(size.0, size.1),
furnitures furnitures
} }
}
fn random_size(room_type: &RoomType) -> (u8, u8) {
match room_type {
RoomType::Kitchen | RoomType::LivingRoom => (random_i32(5, 8) as u8, 3),
RoomType::Bath | RoomType::SleepingRoom => (random_i32(4, 6) as u8, 3),
RoomType::Toilett => (random_i32(2, 3) as u8, 3)
}
}
fn create_grid(width: u8, height: u8) -> Grid { fn create_grid(width: u8, height: u8) -> Grid {
error!("START GRID CREATION!"); error!("START GRID CREATION!");