Added setup to house and WIP Furniture tiles

This commit is contained in:
Glaeder 2024-07-07 10:04:29 +02:00
parent 9f78a94c8d
commit 1cdb6156f8
6 changed files with 84 additions and 56 deletions

View file

@ -1,8 +1,10 @@
use comfy::*;
use super::grid::Grid;
use super::{furniture::Furniture, grid::Grid};
#[derive(Debug)]
pub const SCALE: f32 = 4.0;
#[derive(Debug, PartialEq)]
enum RoomType {
Kitchen,
Bath,
@ -15,7 +17,14 @@ enum RoomType {
pub struct Room {
room_type: RoomType,
pub size: (u8, u8), //(width, height)
pub grid: Grid
pub grid: Grid,
tiles: Vec<Tile>
}
#[derive(Debug)]
enum Tile {
Single(Furniture),
Double(Furniture, Furniture)
}
impl RoomType {
@ -31,18 +40,19 @@ impl RoomType {
}
}
impl Default for Room {
fn default() -> Self {
Room::load() //Just for testing purposes
}
}
impl Room {
pub fn load() -> Self {
pub fn new(ctx: &mut EngineContext<'_>) -> Self {
let room_type = RoomType::random();
let size = Self::random_size(&room_type);
Room { room_type, size, grid: Self::create_grid(size.0, size.1)}
let mut tiles = Vec::new();
if room_type == RoomType::Kitchen {
tiles.push(Tile::Single(Furniture::new("kitchen", "fridge", ctx)));
}
Room { room_type, size, grid: Self::create_grid(size.0, size.1), tiles}
}
fn random_size(room_type: &RoomType) -> (u8, u8) {
@ -63,7 +73,7 @@ impl Room {
error!("START GRID CREATION!");
let left_border = width as f32 / 2.0;
let lower_border = height as f32 / 2.0;
let scale = 4.0;
//Lower Cable
let lower_cable_y = height as f32 / 6.0;
@ -73,11 +83,11 @@ impl Room {
let max_offset = ((width / 2) as i32).max(1);
while current_x < width as f32 {
nodes.push(vec2((current_x - left_border) * scale, (lower_cable_y - lower_border) * scale));
nodes.push(vec2((current_x - left_border) * SCALE, (lower_cable_y - lower_border) * SCALE));
current_x += random_i32(1, max_offset) as f32;
}
current_x = width as f32 + 0.5;
nodes.push(vec2((current_x - left_border) * scale, (lower_cable_y - lower_border) * scale));
nodes.push(vec2((current_x - left_border) * SCALE, (lower_cable_y - lower_border) * SCALE));
let mut connections = Vec::new();
for i in 1..nodes.len() {
@ -92,7 +102,7 @@ impl Room {
let last_lower_node_index = nodes.len();
for (i, index) in node_indices.iter().enumerate() {
nodes.push(vec2(nodes.get(*index).unwrap().x,(upper_cable_y - lower_border) * scale));
nodes.push(vec2(nodes.get(*index).unwrap().x,(upper_cable_y - lower_border) * SCALE));
connections.push((*index, last_lower_node_index + i));
}
@ -100,9 +110,9 @@ impl Room {
}
pub fn draw(&self) {
let scale = 4.0;
let (width, height) = self.size;
let (width, height) = (width as f32 * scale, height as f32 * scale);
let (width, height) = (width as f32 * SCALE, height as f32 * SCALE);
draw_rect_outline(vec2(0.0, 0.0), vec2(width, height), 0.3, RED, 0);