diff --git a/src/activities/house/furniture.rs b/src/activities/house/furniture.rs index f66811e..0377185 100644 --- a/src/activities/house/furniture.rs +++ b/src/activities/house/furniture.rs @@ -23,7 +23,7 @@ impl FurnitureAsset { } fn asset_path_magnet(&self) -> String { - format!("{}/magnet/{}.png", self.folder, self.name) + format!("{}/metal/{}.png", self.folder, self.name) } fn asset_path_elec(&self) -> String { @@ -110,4 +110,8 @@ impl Furniture { pub fn get_magnet_texture_handle(&self) -> Option { self.handles.magnet } + + pub fn is_on(&self) -> bool { + (self.on)() + } } diff --git a/src/activities/house/mod.rs b/src/activities/house/mod.rs index b6f34ed..1141a6c 100644 --- a/src/activities/house/mod.rs +++ b/src/activities/house/mod.rs @@ -12,14 +12,19 @@ use room::Room; pub struct HouseState { room: Room, //grid: Grid, - player: Player + player: Player, + human_layer: bool //Human, magnetic, electric } pub fn setup(state: &mut crate::State, ctx: &mut EngineContext<'_>) { let house = { let room = Room::new(ctx); let player = Player::new(&room); - HouseState { room, player } + HouseState { + room, + player, + human_layer: false + } }; state.house = Some(house); @@ -28,7 +33,9 @@ pub fn setup(state: &mut crate::State, ctx: &mut EngineContext<'_>) { pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) { if let Some(house) = &state.house { //Draw House - house.room.draw(); + house + .room + .draw(house.human_layer, house.player.can_see_metal(0.1)); //Draw Grid //state.house.grid.draw(); diff --git a/src/activities/house/player.rs b/src/activities/house/player.rs index 23389fb..6a0330e 100644 --- a/src/activities/house/player.rs +++ b/src/activities/house/player.rs @@ -9,6 +9,9 @@ use std::collections::HashSet; pub struct Player { position: Vec2, speed: f32, + last_speed: f32, + current_acceleration: f32, + movement_time: f32, connection: usize, next_connections: Vec } @@ -20,7 +23,10 @@ impl Player { ((0.25) - room.size.0 as f32 / 2.0) * SCALE, room.grid.nodes.first().unwrap().y ), - speed: 10.0, + speed: 0.0, + last_speed: 0.0, + current_acceleration: 0.0, + movement_time: 0.0, connection: 0, next_connections: vec![1] } @@ -60,6 +66,10 @@ impl Player { self.connection = 0; self.next_connections = vec![1]; } + + pub fn can_see_metal(&self, threshold: f32) -> bool { + self.current_acceleration > threshold + } } fn move_player(player: &mut Player, allowed_movement: (bool, bool, bool, bool)) { @@ -70,6 +80,22 @@ fn move_player(player: &mut Player, allowed_movement: (bool, bool, bool, bool)) allow_right_movement ) = allowed_movement; + if is_key_down(KeyCode::Up) + || is_key_down(KeyCode::Down) + || is_key_down(KeyCode::Left) + || is_key_down(KeyCode::Right) + { + player.movement_time += delta(); + player.speed = calc_player_speed(player.movement_time); + player.speed = player.speed.clamp(0.0, 10.0); + } else { + player.speed = 0.0; + player.last_speed = 0.0; + player.movement_time = 0.0; + } + + player.current_acceleration = (player.speed - player.last_speed).abs(); + if allow_up_movement && is_key_down(KeyCode::Up) { player.position += vec2(0.0, player.speed) * delta(); } @@ -85,6 +111,14 @@ fn move_player(player: &mut Player, allowed_movement: (bool, bool, bool, bool)) if allow_left_movement && is_key_down(KeyCode::Left) { player.position += vec2(-player.speed, 0.0) * delta(); } + + player.last_speed = player.speed; +} + +fn calc_player_speed(time: f32) -> f32 { + //3x^2-2x^3; x=t + let t = time * 20.0; + 3.0 * t * t - 2.0 * t * t } //(UP, DOWN, LEFT, RIGHT) diff --git a/src/activities/house/room.rs b/src/activities/house/room.rs index 07db950..7dbadd2 100644 --- a/src/activities/house/room.rs +++ b/src/activities/house/room.rs @@ -241,14 +241,15 @@ impl Room { Grid::new(nodes, connections) } - pub fn draw(&self) { + //Human, magnetic, electric + pub fn draw(&self, human_layer: bool, magnet_layer: bool) { let (width, height) = self.size; draw_rect( vec2(0.0, 0.0), vec2(width as f32 * SCALE, height as f32 * SCALE), PURPLE, - game::ZLayer::MapMax as i32 - 2 + game::ZLayer::HumanLayer as i32 - 4 ); draw_rect_outline( vec2(0.0, 0.0), @@ -262,22 +263,48 @@ impl Room { 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) = tile.f.get_human_texture_handle() { - draw_sprite( - texture, - pos * SCALE, - WHITE, - game::ZLayer::MapMax as i32 + tile.z, - tile.size * SCALE - ); - } else { - draw_rect_outline( - pos * SCALE, - tile.size * SCALE, - 0.3, - GREEN, - game::ZLayer::MapMax as i32 + tile.z - ); + if human_layer { + if let Some(texture) = tile.f.get_human_texture_handle() { + draw_sprite( + texture, + pos * SCALE, + WHITE, + game::ZLayer::HumanLayer as i32 + tile.z, + tile.size * SCALE + ); + } else { + draw_rect_outline( + pos * SCALE, + tile.size * SCALE, + 0.3, + GREEN, + game::ZLayer::HumanLayer as i32 + tile.z + ); + } + } + + if magnet_layer { + if let Some(texture) = tile.f.get_magnet_texture_handle() { + draw_sprite( + texture, + pos * SCALE, + WHITE, + game::ZLayer::MagneticLayer as i32 + tile.z, + tile.size * SCALE + ); + } + } + + if tile.f.is_on() { + if let Some(texture) = tile.f.get_elec_texture_handle() { + draw_sprite( + texture, + pos * SCALE, + WHITE, + game::ZLayer::ElectricLayer as i32 + tile.z, + tile.size * SCALE + ); + } } } diff --git a/src/game.rs b/src/game.rs index 1a638c1..4f5c162 100644 --- a/src/game.rs +++ b/src/game.rs @@ -24,6 +24,9 @@ impl Default for Ghost { } #[repr(i32)] pub enum ZLayer { + HumanLayer = -8, + MagneticLayer = -5, + ElectricLayer = -2, MapMax = -1, Human = 0, Ghost = 1