Allow people to use my magic code

This commit is contained in:
Evan Pratten 2022-04-02 20:21:04 -04:00
parent 6429b68654
commit 801dde4c8e
2 changed files with 55 additions and 5 deletions

View File

@ -138,6 +138,26 @@ impl MapRenderer {
(world_position.y / 128.0).floor() as i32,
);
// If there is an object here, let it override the output
for obj_ref in &self.world_objects.object_references {
if obj_ref.position.x == tile_position.x as f32
&& obj_ref.position.y == tile_position.y as f32
{
// Get access to the actual object definition
let object_key = format!("{}:{}", obj_ref.kind, obj_ref.name);
let obj_def = self
.world_objects
.object_definitions
.get(&object_key)
.unwrap();
// Check if there is a friction property
if let Some(friction) = obj_def.friction {
return Some(friction);
}
}
}
// Get the first layer
let layer = self.map.layers().next().unwrap();
@ -173,6 +193,26 @@ impl MapRenderer {
(world_position.y / 128.0).floor() as i32,
);
// If there is an object here, let it override the output
for obj_ref in &self.world_objects.object_references {
if obj_ref.position.x == tile_position.x as f32
&& obj_ref.position.y == tile_position.y as f32
{
// Get access to the actual object definition
let object_key = format!("{}:{}", obj_ref.kind, obj_ref.name);
let obj_def = self
.world_objects
.object_definitions
.get(&object_key)
.unwrap();
// Check if there is a temperature property
if let Some(temperature) = obj_def.temperature {
return Some(temperature);
}
}
}
// Get the first layer
let layer = self.map.layers().next().unwrap();

View File

@ -30,8 +30,13 @@ impl PlayableScene {
thread: &raylib::RaylibThread,
constants: &ProjectConstants,
) -> Self {
let map_renderer = MapRenderer::new("map_gameMap.tmx", "map_gameMap.objects.json", raylib_handle, thread).unwrap();
let map_renderer = MapRenderer::new(
"map_gameMap.tmx",
"map_gameMap.objects.json",
raylib_handle,
thread,
)
.unwrap();
// Load the game music
let game_soundtrack =
@ -105,10 +110,15 @@ impl PlayableScene {
let mut ctx2d = draw.begin_mode2D(self.camera);
// Render the map
self.world_map
.render_map(&mut ctx2d, &self.camera, true, self.player.position);
self.world_map.render_map(&mut ctx2d, &self.camera, true, self.player.position);
let player_size = (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32;
// NOTE: This is how to check friction and temperature
let current_friction = self.world_map.sample_friction_at(self.player.position);
let current_temperature = self.world_map.sample_temperature_at(self.player.position);
let player_size =
(constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32;
ctx2d.draw_rectangle(
self.player.position[0] as i32 - player_size / 2,