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 2498152b21 - Show all commits

View file

@ -17,7 +17,13 @@ enum RoomType {
SleepingRoom SleepingRoom
} }
type Tile = (Vec2, Vec2, Furniture); //(pos, size, furniture) #[derive(Debug)]
struct Tile {
pos: Vec2,
size: Vec2,
f: Furniture,
z: i32
}
#[derive(Debug)] #[derive(Debug)]
pub struct Room { pub struct Room {
@ -94,57 +100,64 @@ impl Room {
// in a kitchen, we always add a fridge // in a kitchen, we always add a fridge
let fridge_pos = u8::gen_range(0, 2) * (width - 1); let fridge_pos = u8::gen_range(0, 2) * (width - 1);
empty_spots.swap_remove(&fridge_pos); empty_spots.swap_remove(&fridge_pos);
furnitures.push(( furnitures.push(Tile {
vec2(fridge_pos as f32, 0.0), pos: vec2(fridge_pos as f32, 0.0),
vec2(1.0, 2.0), size: vec2(1.0, 2.0),
Furniture::new("kitchen", "fridge", ctx) f: Furniture::new("kitchen", "fridge", ctx),
)); z: 0
});
// and we always add an oven // and we always add an oven
let Some(oven_pos) = random_empty_spot(&mut empty_spots) else { let Some(oven_pos) = random_empty_spot(&mut empty_spots) else {
error!("How can I not fit an oven in a kitchen?!?"); error!("How can I not fit an oven in a kitchen?!?");
return furnitures; return furnitures;
}; };
furnitures.push(( furnitures.push(Tile {
vec2(oven_pos as f32, 0.0), pos: vec2(oven_pos as f32, 0.0),
vec2(1.0, 1.0), size: vec2(1.0, 1.0),
Furniture::new("kitchen", "oven", ctx) f: Furniture::new("kitchen", "oven", ctx),
)); z: 0
});
// there's always sideboard above the oven with a stove // there's always sideboard above the oven with a stove
furnitures.push(( furnitures.push(Tile {
vec2(oven_pos as f32, 1.0), pos: vec2(oven_pos as f32, 1.0),
vec2(1.0, SIDEBOARD_HEIGHT), size: vec2(1.0, SIDEBOARD_HEIGHT),
Furniture::new("kitchen", "sideboard_1", ctx) f: Furniture::new("kitchen", "sideboard_1", ctx),
)); z: 1
furnitures.push(( });
vec2(oven_pos as f32, 1.0 + SIDEBOARD_HEIGHT), furnitures.push(Tile {
vec2(1.0, STOVE_HEIGHT), pos: vec2(oven_pos as f32, 1.0 + SIDEBOARD_HEIGHT),
Furniture::new("kitchen", "stove", ctx) size: vec2(1.0, STOVE_HEIGHT),
)); f: Furniture::new("kitchen", "stove", ctx),
z: 0
});
// and we always add a drawer that houses a sink // and we always add a drawer that houses a sink
let Some(sink_pos) = random_empty_spot(&mut empty_spots) else { let Some(sink_pos) = random_empty_spot(&mut empty_spots) else {
error!("How can I not fit a sink in a kitchen?!?"); error!("How can I not fit a sink in a kitchen?!?");
return furnitures; return furnitures;
}; };
furnitures.push(( furnitures.push(Tile {
vec2(sink_pos as f32, 0.0), pos: vec2(sink_pos as f32, 0.0),
vec2(1.0, 1.0), size: vec2(1.0, 1.0),
Furniture::new("kitchen", "drawer_cupboard", ctx) f: Furniture::new("kitchen", "drawer_cupboard", ctx),
)); z: 0
});
// there's always sideboard above that drawer with a sink **behind** it // there's always sideboard above that drawer with a sink **behind** it
furnitures.push(( furnitures.push(Tile {
vec2(sink_pos as f32, 1.0), pos: vec2(sink_pos as f32, 1.0),
vec2(1.0, SINK_HEIGHT), size: vec2(1.0, SINK_HEIGHT),
Furniture::new("kitchen", "sink", ctx) f: Furniture::new("kitchen", "sink", ctx),
)); z: 0
furnitures.push(( });
vec2(sink_pos as f32, 1.0), furnitures.push(Tile {
vec2(1.0, SIDEBOARD_HEIGHT), pos: vec2(sink_pos as f32, 1.0),
Furniture::new("kitchen", "sideboard_1", ctx) size: vec2(1.0, SIDEBOARD_HEIGHT),
)); f: Furniture::new("kitchen", "sideboard_1", ctx),
z: 1
});
// let's add half of the remaining positions as drawers // let's add half of the remaining positions as drawers
for _ in 0 .. empty_spots.len() / 2 { for _ in 0 .. empty_spots.len() / 2 {
@ -157,16 +170,18 @@ impl Room {
error!("WTF I shouldn't've used more than half of the available spots"); error!("WTF I shouldn't've used more than half of the available spots");
return furnitures; return furnitures;
}; };
furnitures.push(( furnitures.push(Tile {
vec2(spot as f32, 0.0), pos: vec2(spot as f32, 0.0),
vec2(1.0, 1.0), size: vec2(1.0, 1.0),
Furniture::new("kitchen", asset, ctx) f: Furniture::new("kitchen", asset, ctx),
)); z: 0
furnitures.push(( });
vec2(spot as f32, 1.0), furnitures.push(Tile {
vec2(1.0, SIDEBOARD_HEIGHT), pos: vec2(spot as f32, 1.0),
Furniture::new("kitchen", "sideboard_1", ctx) size: vec2(1.0, SIDEBOARD_HEIGHT),
)); f: Furniture::new("kitchen", "sideboard_1", ctx),
z: 1
});
} }
}, },
@ -243,25 +258,25 @@ impl Room {
game::ZLayer::MapMax as i32 - 1 game::ZLayer::MapMax as i32 - 1
); );
for (pos, size, furniture) in &self.furnitures { for tile in &self.furnitures {
let mut pos = *pos - vec2(width as f32 / 2.0, height as f32 / 2.0); let mut pos = tile.pos - vec2(width as f32 / 2.0, height as f32 / 2.0);
pos += *size * 0.5; pos += tile.size * 0.5;
if let Some(texture) = furniture.get_human_texture_handle() { if let Some(texture) = tile.f.get_human_texture_handle() {
draw_sprite( draw_sprite(
texture, texture,
pos * SCALE, pos * SCALE,
WHITE, WHITE,
game::ZLayer::MapMax.into(), game::ZLayer::MapMax as i32 + tile.z,
*size * SCALE tile.size * SCALE
); );
} else { } else {
draw_rect_outline( draw_rect_outline(
pos * SCALE, pos * SCALE,
*size * SCALE, tile.size * SCALE,
0.3, 0.3,
GREEN, GREEN,
game::ZLayer::MapMax.into() game::ZLayer::MapMax as i32 + tile.z
); );
} }
} }