Fix the zoom absurdity

This commit is contained in:
Evan Pratten 2021-10-04 16:09:57 -04:00
parent a1feeb9f82
commit 4fa1384f95
2 changed files with 11 additions and 5 deletions

View File

@ -1,13 +1,10 @@
use std::ops::Div;
use super::InGameScreen;
use crate::{
character::CharacterState,
utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::FrameUpdate},
GameConfig,
};
use crate::{GameConfig, character::CharacterState, utilities::{math::{interpolate_exp_unchecked, linear_interpolate}, non_ref_raylib::HackedRaylibHandle, render_layer::FrameUpdate}};
use chrono::Duration;
use raylib::prelude::*;
use tracing::trace;
impl FrameUpdate for InGameScreen {
fn update(
@ -24,6 +21,8 @@ impl FrameUpdate for InGameScreen {
// Set the camera's offset based on screen size
self.camera.offset = raylib.get_screen_size().div(Vector2::new(2.0, 1.05));
self.camera.target = Vector2::new(self.player.position.x, self.camera.target.y);
self.camera.zoom = linear_interpolate(raylib.get_screen_size().y.max(200.0), 720.0..1016.0, 0.85..1.2);
trace!("Zoom level set to: {} {}", raylib.get_screen_size().y, self.camera.zoom);
// Check the only possible keyboard inputs
let is_jump = raylib.is_key_pressed(KeyboardKey::KEY_SPACE)

View File

@ -92,3 +92,10 @@ mod test {
assert!(relative_eq!(actual_value, expected_value, epsilon = 0.001));
}
}
pub fn linear_interpolate(value: f32, input_range: Range<f32>, output_range: Range<f32>) -> f32 {
let normalized_value = (value - input_range.start) / (input_range.end - input_range.start);
let mapped_value = (normalized_value * (output_range.end - output_range.start)) + output_range.start;
mapped_value
}