diff --git a/src/activities/house/magnet-shader.wgsl b/src/activities/house/magnet-shader.wgsl new file mode 100644 index 0000000..b52d1c3 --- /dev/null +++ b/src/activities/house/magnet-shader.wgsl @@ -0,0 +1,7 @@ +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4 { + let global_coord: vec3 = in.world_position; + let tex = textureSample(t_diffuse, s_diffuse, in.tex_coords); + var final_color: vec4 = tex * in.color; + return vec4(global_coord, final_color.a); +} \ No newline at end of file diff --git a/src/activities/house/mod.rs b/src/activities/house/mod.rs index 5a25152..d2cfb91 100644 --- a/src/activities/house/mod.rs +++ b/src/activities/house/mod.rs @@ -50,18 +50,19 @@ impl HouseState { } } -pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) { +pub fn draw(state: &crate::State, _ctx: &mut comfy::EngineContext<'_>) { let Some(house) = state.house() else { error!("How can I render a house when I'm not in one?!?"); return; }; //Draw House - house - .rooms - .get(house.current_room_id) - .unwrap() - .draw(house.human_layer, house.player.can_see_metal(0.1)); + house.rooms.get(house.current_room_id).unwrap().draw( + house.human_layer, + house.player.can_see_metal(0.1), + house.player.get_position(), + _ctx + ); //Draw Grid //state.house.grid.draw(); diff --git a/src/activities/house/player.rs b/src/activities/house/player.rs index d78cfbb..5d18043 100644 --- a/src/activities/house/player.rs +++ b/src/activities/house/player.rs @@ -32,6 +32,9 @@ impl Player { } } + pub fn get_position(&self) -> Vec2 { + self.position + } pub fn draw(&self) { draw_circle(self.position, 0.5, RED, 0); } diff --git a/src/activities/house/room.rs b/src/activities/house/room.rs index f25ae5d..daac405 100644 --- a/src/activities/house/room.rs +++ b/src/activities/house/room.rs @@ -1,8 +1,7 @@ use super::{furniture::Furniture, grid::Grid}; use crate::game; use comfy::{ - draw_rect, draw_rect_outline, draw_sprite, error, random_i32, vec2, EngineContext, - HashSet, Index, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE + create_reloadable_sprite_shader, draw_rect, draw_rect_outline, draw_sprite, error, hashmap, random_i32, set_uniform_f32, use_default_shader, use_shader, vec2, EngineContext, HashSet, Index, RandomRange as _, ReloadableShaderSource, UniformDef, Vec2, GREEN, PURPLE, RED, WHITE }; use indexmap::IndexSet; @@ -285,7 +284,8 @@ impl Room { } }, - RoomType::LivingRoom => { + _ => { + //RoomType::LivingRoom => { let has_couch = match u8::gen_range(0, 2) { 0 => false, 1 => true, @@ -319,9 +319,8 @@ impl Room { z: 0 }); } - }, - - _ => {} + } + //_ => {} } furnitures @@ -377,7 +376,13 @@ impl Room { Grid::new(nodes, connections) } - pub fn draw(&self, human_layer: bool, magnet_layer: bool) { + pub fn draw( + &self, + human_layer: bool, + magnet_layer: bool, + position: Vec2, + _ctx: &mut comfy::EngineContext<'_> + ) { let (width, height) = self.size; draw_rect( @@ -418,7 +423,27 @@ impl Room { } } - if magnet_layer { + if true { + let magnet_shader_id = Some( + create_reloadable_sprite_shader( + &mut _ctx.renderer.shaders.borrow_mut(), + "magnet-shader", + ReloadableShaderSource { + static_source: include_str!("magnet-shader.wgsl").to_string(), + path: "src/activities/house/magnet-shader.wgsl".to_string() + }, + hashmap! { + // "px".to_string() => UniformDef::F32(None), + // "py".to_string() => UniformDef::F32(None), + } + ) + .unwrap() + ).unwrap(); + + use_shader(magnet_shader_id); + // set_uniform_f32("px", position.x); + // set_uniform_f32("py", position.y); + if let Some(texture) = tile.f.get_magnet_texture_handle() { draw_sprite( texture, @@ -428,6 +453,7 @@ impl Room { tile.size * SCALE ); } + use_default_shader(); } if tile.f.is_on() { diff --git a/src/game.rs b/src/game.rs index d7aaad3..6182cc5 100644 --- a/src/game.rs +++ b/src/game.rs @@ -157,7 +157,7 @@ pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) { state.ghost.charge = state.ghost.charge.max(0.0); } -pub fn draw(state: &State, engine: &EngineContext<'_>) { +pub fn draw(state: &State, engine: &mut EngineContext<'_>) { match state.activity { Activity::House(_) => house::draw(state, engine), Activity::Overworld => overworld::draw(state, engine)