diff --git a/rustdoc/game_logic/scenes/player_interaction/index.html b/rustdoc/game_logic/scenes/player_interaction/index.html index bddc93ec..56281756 100644 --- a/rustdoc/game_logic/scenes/player_interaction/index.html +++ b/rustdoc/game_logic/scenes/player_interaction/index.html @@ -1,6 +1,6 @@ game_logic::scenes::player_interaction - Rust

Module game_logic::scenes::player_interaction[][src]

Expand description

This scene encompasses all of the game where the player can walk around.

+

Module player_interaction

Module game_logic::scenes::player_interaction[][src]

Expand description

This scene encompasses all of the game where the player can walk around.

Structs

\ No newline at end of file diff --git a/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html b/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html index 820bbca3..a2a2da1d 100644 --- a/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html +++ b/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html @@ -7,9 +7,9 @@ camera: Camera2D, last_update: SystemTime, game_soundtrack: Music, -}

Fields

has_updated_discord_rpc: boolplayer: Playerworld_map: MapRenderercamera: Camera2Dlast_update: SystemTimegame_soundtrack: Music

Implementations

Construct a new PlayableScene

-

Handler for each frame

-

Trait Implementations

Formats the value using the given formatter. Read more

+}

Fields

has_updated_discord_rpc: boolplayer: Playerworld_map: MapRenderercamera: Camera2Dlast_update: SystemTimegame_soundtrack: Music

Implementations

Construct a new PlayableScene

+

Handler for each frame

+

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/rustdoc/src/game_logic/scenes/player_interaction.rs.html b/rustdoc/src/game_logic/scenes/player_interaction.rs.html index e69507b3..902fed6e 100644 --- a/rustdoc/src/game_logic/scenes/player_interaction.rs.html +++ b/rustdoc/src/game_logic/scenes/player_interaction.rs.html @@ -202,6 +202,46 @@ 200 201 202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242
//! This scene encompasses all of the game where the player can walk around.
 
 use nalgebra as na;
@@ -248,13 +288,16 @@
 
         Self {
             has_updated_discord_rpc: false,
-            player: Player::new(na::Vector2::new(10.0, 10.0)),
+            player: Player::new(na::Vector2::new(10.0 * constants.tile_size as f32, -10.0 * constants.tile_size as f32)),
             world_map: map_renderer,
             camera: raylib::camera::Camera2D {
-                target: raylib::math::Vector2 { x: 0.0, y: 0.0 },
-                offset: raylib::math::Vector2 {
-                    x: (constants.base_window_size.0 as f32 / 2.0),
-                    y: (constants.base_window_size.1 as f32 / 2.0),
+                target: raylib::math::Vector2 { 
+                    x: 0.0, 
+                    y: 0.0,
+                },
+                offset: raylib::math::Vector2 { 
+                    x: 0.0,
+                    y: 0.0
                 },
                 rotation: 0.0,
                 zoom: 1.0,
@@ -397,11 +440,48 @@
         self.update_camera(raylib);
     }
 
-    pub fn update_camera(&mut self, raylib: &raylib::RaylibHandle) {
-        self.camera.target = self.player.position.into();
-        self.camera.target.y *= -1.0;
-        self.camera.offset.x = raylib.get_screen_width() as f32 / 2.0;
-        self.camera.offset.y = raylib.get_screen_height() as f32 / 2.0;
+    // Update the camera
+    pub fn update_camera(
+        &mut self, 
+        raylib: & raylib::RaylibHandle,
+    ) {
+        
+        // Bounding box
+        let bbox = na::Vector2::new(0.2, 0.2);
+
+        // Get bounding box dimensions on the screen
+        let bbox_screen_min: raylib::math::Vector2 = (((na::Vector2::new(1.0, 1.0) - bbox) * 0.5).component_mul(
+            &na::Vector2::new(raylib.get_screen_width() as f32, raylib.get_screen_height() as f32)
+        )).into();
+        let bbox_screen_max: raylib::math::Vector2 = (((na::Vector2::new(1.0, 1.0) + bbox) * 0.5).component_mul(
+            &na::Vector2::new(raylib.get_screen_width() as f32, raylib.get_screen_height() as f32)
+        )).into();
+
+        // Get bounding box in world space
+        let mut bbox_world_min = raylib.get_screen_to_world2D(bbox_screen_min, self.camera);
+        let mut bbox_world_max = raylib.get_screen_to_world2D(bbox_screen_max, self.camera);
+
+        // Invert y 
+        bbox_world_min.y *= -1.0;
+        bbox_world_max.y *= -1.0;
+
+        self.camera.offset = bbox_screen_min;
+        
+        if self.player.position.x < bbox_world_min.x {
+            self.camera.target.x = self.player.position.x;
+        }
+
+        if self.player.position.y > bbox_world_min.y {
+            self.camera.target.y = -self.player.position.y;
+        }
+
+        if self.player.position.x > bbox_world_max.x {
+            self.camera.target.x = bbox_world_min.x + (self.player.position.x - bbox_world_max.x);
+        }
+        
+        if self.player.position.y < bbox_world_max.y {
+            self.camera.target.y = bbox_world_max.y - (self.player.position.y + bbox_world_min.y);
+        }
     }
 }