diff --git a/game/game_logic/src/model/world_object.rs b/game/game_logic/src/model/world_object.rs index 15f14555..ffad27a3 100644 --- a/game/game_logic/src/model/world_object.rs +++ b/game/game_logic/src/model/world_object.rs @@ -42,6 +42,8 @@ pub struct WorldObject { pub physics_colliders: Vec, /// Temperature pub temperature: Option, + /// Friction + pub friction: Option, } /// Used to reference an object in the world definition diff --git a/game/game_logic/src/rendering/utilities/map_render.rs b/game/game_logic/src/rendering/utilities/map_render.rs index b9822917..c89c70e4 100644 --- a/game/game_logic/src/rendering/utilities/map_render.rs +++ b/game/game_logic/src/rendering/utilities/map_render.rs @@ -1,6 +1,9 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc}; -use crate::asset_manager::{load_texture_from_internal_data, InternalData}; +use crate::{ + asset_manager::{load_texture_from_internal_data, InternalData}, + model::world_object_package::WorldObjectPackage, +}; use nalgebra as na; use raylib::{ camera::Camera2D, @@ -75,12 +78,14 @@ impl ResourceCache for ProgramDataTileCache { pub struct MapRenderer { map: Map, tile_textures: HashMap, + world_objects: WorldObjectPackage, } impl MapRenderer { /// Construct a new MapRenderer. pub fn new( tmx_path: &str, + objects_path: &str, raylib: &mut RaylibHandle, raylib_thread: &RaylibThread, ) -> Result { @@ -116,7 +121,14 @@ impl MapRenderer { } } - Ok(Self { map, tile_textures }) + // Load the world objects + let world_objects = WorldObjectPackage::load(raylib, raylib_thread, objects_path).unwrap(); + + Ok(Self { + map, + tile_textures, + world_objects, + }) } pub fn sample_friction_at(&self, position: na::Vector2) -> f32 { @@ -127,7 +139,12 @@ impl MapRenderer { todo!() } - pub fn render_map(&self, draw_handle: &mut RaylibMode2D, camera: &Camera2D, show_debug_grid:bool) { + pub fn render_map( + &self, + draw_handle: &mut RaylibMode2D, + camera: &Camera2D, + show_debug_grid: bool, + ) { // Get the window corners in world space let screen_width = draw_handle.get_screen_width(); let screen_height = draw_handle.get_screen_height(); @@ -187,8 +204,8 @@ impl MapRenderer { tile_y * tile_height as i32, Color::WHITE, ); - } - + } + if show_debug_grid { draw_handle.draw_rectangle_lines( tile_x * tile_width as i32, diff --git a/game/game_logic/src/scenes/test_fox.rs b/game/game_logic/src/scenes/test_fox.rs index 23a7f257..38bfdb06 100644 --- a/game/game_logic/src/scenes/test_fox.rs +++ b/game/game_logic/src/scenes/test_fox.rs @@ -7,7 +7,6 @@ use raylib::prelude::*; use crate::{ discord::DiscordChannel, global_resource_package::GlobalResources, - model::world_object_package::WorldObjectPackage, rendering::utilities::{anim_texture::AnimatedTexture, map_render::MapRenderer}, }; @@ -16,7 +15,6 @@ pub struct TestFoxScene { fox_animation: AnimatedTexture, world_map: MapRenderer, camera: Camera2D, - objects: WorldObjectPackage, } impl TestFoxScene { @@ -26,9 +24,13 @@ impl TestFoxScene { let fox = AnimatedTexture::new(raylib_handle, thread, "chr", "testFox").unwrap(); // Load the map - let map_renderer = MapRenderer::new("map_gameMap.tmx", raylib_handle, thread).unwrap(); - let objects = - WorldObjectPackage::load(raylib_handle, thread, "map_gameMap.objects.json").unwrap(); + let map_renderer = MapRenderer::new( + "map_gameMap.tmx", + "map_gameMap.objects.json", + raylib_handle, + thread, + ) + .unwrap(); // Create a camera let camera = Camera2D { @@ -45,7 +47,6 @@ impl TestFoxScene { fox_animation: fox, world_map: map_renderer, camera, - objects, } }