z index
This commit is contained in:
parent
d63c487b9d
commit
2498152b21
1 changed files with 69 additions and 54 deletions
|
@ -17,7 +17,13 @@ enum RoomType {
|
|||
SleepingRoom
|
||||
}
|
||||
|
||||
type Tile = (Vec2, Vec2, Furniture); //(pos, size, furniture)
|
||||
#[derive(Debug)]
|
||||
struct Tile {
|
||||
pos: Vec2,
|
||||
size: Vec2,
|
||||
f: Furniture,
|
||||
z: i32
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Room {
|
||||
|
@ -94,57 +100,64 @@ impl Room {
|
|||
// in a kitchen, we always add a fridge
|
||||
let fridge_pos = u8::gen_range(0, 2) * (width - 1);
|
||||
empty_spots.swap_remove(&fridge_pos);
|
||||
furnitures.push((
|
||||
vec2(fridge_pos as f32, 0.0),
|
||||
vec2(1.0, 2.0),
|
||||
Furniture::new("kitchen", "fridge", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(fridge_pos as f32, 0.0),
|
||||
size: vec2(1.0, 2.0),
|
||||
f: Furniture::new("kitchen", "fridge", ctx),
|
||||
z: 0
|
||||
});
|
||||
|
||||
// and we always add an oven
|
||||
let Some(oven_pos) = random_empty_spot(&mut empty_spots) else {
|
||||
error!("How can I not fit an oven in a kitchen?!?");
|
||||
return furnitures;
|
||||
};
|
||||
furnitures.push((
|
||||
vec2(oven_pos as f32, 0.0),
|
||||
vec2(1.0, 1.0),
|
||||
Furniture::new("kitchen", "oven", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(oven_pos as f32, 0.0),
|
||||
size: vec2(1.0, 1.0),
|
||||
f: Furniture::new("kitchen", "oven", ctx),
|
||||
z: 0
|
||||
});
|
||||
|
||||
// there's always sideboard above the oven with a stove
|
||||
furnitures.push((
|
||||
vec2(oven_pos as f32, 1.0),
|
||||
vec2(1.0, SIDEBOARD_HEIGHT),
|
||||
Furniture::new("kitchen", "sideboard_1", ctx)
|
||||
));
|
||||
furnitures.push((
|
||||
vec2(oven_pos as f32, 1.0 + SIDEBOARD_HEIGHT),
|
||||
vec2(1.0, STOVE_HEIGHT),
|
||||
Furniture::new("kitchen", "stove", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(oven_pos as f32, 1.0),
|
||||
size: vec2(1.0, SIDEBOARD_HEIGHT),
|
||||
f: Furniture::new("kitchen", "sideboard_1", ctx),
|
||||
z: 1
|
||||
});
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(oven_pos as f32, 1.0 + SIDEBOARD_HEIGHT),
|
||||
size: vec2(1.0, STOVE_HEIGHT),
|
||||
f: Furniture::new("kitchen", "stove", ctx),
|
||||
z: 0
|
||||
});
|
||||
|
||||
// and we always add a drawer that houses a sink
|
||||
let Some(sink_pos) = random_empty_spot(&mut empty_spots) else {
|
||||
error!("How can I not fit a sink in a kitchen?!?");
|
||||
return furnitures;
|
||||
};
|
||||
furnitures.push((
|
||||
vec2(sink_pos as f32, 0.0),
|
||||
vec2(1.0, 1.0),
|
||||
Furniture::new("kitchen", "drawer_cupboard", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(sink_pos as f32, 0.0),
|
||||
size: vec2(1.0, 1.0),
|
||||
f: Furniture::new("kitchen", "drawer_cupboard", ctx),
|
||||
z: 0
|
||||
});
|
||||
|
||||
// there's always sideboard above that drawer with a sink **behind** it
|
||||
furnitures.push((
|
||||
vec2(sink_pos as f32, 1.0),
|
||||
vec2(1.0, SINK_HEIGHT),
|
||||
Furniture::new("kitchen", "sink", ctx)
|
||||
));
|
||||
furnitures.push((
|
||||
vec2(sink_pos as f32, 1.0),
|
||||
vec2(1.0, SIDEBOARD_HEIGHT),
|
||||
Furniture::new("kitchen", "sideboard_1", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(sink_pos as f32, 1.0),
|
||||
size: vec2(1.0, SINK_HEIGHT),
|
||||
f: Furniture::new("kitchen", "sink", ctx),
|
||||
z: 0
|
||||
});
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(sink_pos as f32, 1.0),
|
||||
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
|
||||
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");
|
||||
return furnitures;
|
||||
};
|
||||
furnitures.push((
|
||||
vec2(spot as f32, 0.0),
|
||||
vec2(1.0, 1.0),
|
||||
Furniture::new("kitchen", asset, ctx)
|
||||
));
|
||||
furnitures.push((
|
||||
vec2(spot as f32, 1.0),
|
||||
vec2(1.0, SIDEBOARD_HEIGHT),
|
||||
Furniture::new("kitchen", "sideboard_1", ctx)
|
||||
));
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(spot as f32, 0.0),
|
||||
size: vec2(1.0, 1.0),
|
||||
f: Furniture::new("kitchen", asset, ctx),
|
||||
z: 0
|
||||
});
|
||||
furnitures.push(Tile {
|
||||
pos: vec2(spot as f32, 1.0),
|
||||
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
|
||||
);
|
||||
|
||||
for (pos, size, furniture) in &self.furnitures {
|
||||
let mut pos = *pos - vec2(width as f32 / 2.0, height as f32 / 2.0);
|
||||
pos += *size * 0.5;
|
||||
for tile in &self.furnitures {
|
||||
let mut pos = tile.pos - vec2(width as f32 / 2.0, height as f32 / 2.0);
|
||||
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(
|
||||
texture,
|
||||
pos * SCALE,
|
||||
WHITE,
|
||||
game::ZLayer::MapMax.into(),
|
||||
*size * SCALE
|
||||
game::ZLayer::MapMax as i32 + tile.z,
|
||||
tile.size * SCALE
|
||||
);
|
||||
} else {
|
||||
draw_rect_outline(
|
||||
pos * SCALE,
|
||||
*size * SCALE,
|
||||
tile.size * SCALE,
|
||||
0.3,
|
||||
GREEN,
|
||||
game::ZLayer::MapMax.into()
|
||||
game::ZLayer::MapMax as i32 + tile.z
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue