room-creation #15

Merged
Glaeder merged 18 commits from room-creation into main 2024-07-07 14:13:52 +00:00
Showing only changes of commit a614cd0644 - Show all commits

View file

@ -18,12 +18,14 @@ enum RoomType {
SleepingRoom
}
type Tile = (Vec2, Vec2, Furniture); //(pos, size, furniture)
#[derive(Debug)]
pub struct Room {
room_type: RoomType,
pub size: (u8, u8), //(width, height)
pub grid: Grid,
furnitures: Vec<(Vec2, Vec2, Furniture)> //(pos, size, furniture)
furnitures: Vec<Tile>
}
impl RoomType {
@ -44,25 +46,7 @@ impl Room {
let room_type = RoomType::random();
let size = Self::random_size(&room_type);
let mut furnitures = Vec::new();
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)
));
}
let furnitures = Self::random_room_furniture(&room_type, size, ctx);
Room {
room_type,
@ -73,6 +57,9 @@ impl Room {
}
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),
@ -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 {
error!("START GRID CREATION!");
let left_border = width as f32 / 2.0;