From 9623dc5830cf280f130930e9a2ceeac9c7bb76c4 Mon Sep 17 00:00:00 2001 From: Ewpratten Date: Sun, 3 Apr 2022 22:14:29 +0000 Subject: [PATCH] deploy: b4ab6aa74ea53ea0aa8d70df2ad511e813f916bc --- .../scenes/player_interaction/index.html | 2 +- .../struct.PlayableScene.html | 8 +- .../scenes/player_interaction.rs.html | 166 +++++++++++++++++- 3 files changed, 168 insertions(+), 8 deletions(-) diff --git a/rustdoc/game_logic/scenes/player_interaction/index.html b/rustdoc/game_logic/scenes/player_interaction/index.html index 94b5252f..a5d309dc 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 26ed2a62..225e81f1 100644 --- a/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html +++ b/rustdoc/game_logic/scenes/player_interaction/struct.PlayableScene.html @@ -1,6 +1,6 @@ PlayableScene in game_logic::scenes::player_interaction - Rust

Struct game_logic::scenes::player_interaction::PlayableScene[][src]

pub struct PlayableScene {
+        

Struct PlayableScene

Struct game_logic::scenes::player_interaction::PlayableScene[][src]

pub struct PlayableScene {
     pub has_updated_discord_rpc: bool,
     player: Player,
     world_map: MapRenderer,
@@ -10,9 +10,9 @@
     world_colliders: Vec<ObjectCollider>,
     show_debug_info: bool,
     play_start_time: DateTime<Utc>,
-}

Fields

has_updated_discord_rpc: boolplayer: Playerworld_map: MapRenderercamera: Camera2Dlast_update: SystemTimegame_soundtrack: Musicworld_colliders: Vec<ObjectCollider>show_debug_info: boolplay_start_time: DateTime<Utc>

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: Musicworld_colliders: Vec<ObjectCollider>show_debug_info: boolplay_start_time: DateTime<Utc>

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 2fc90e20..a2a8589c 100644 --- a/rustdoc/src/game_logic/scenes/player_interaction.rs.html +++ b/rustdoc/src/game_logic/scenes/player_interaction.rs.html @@ -299,6 +299,86 @@ 297 298 299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379
//! This scene encompasses all of the game where the player can walk around.
 
 use chrono::{DateTime, Utc};
@@ -310,7 +390,10 @@
     asset_manager::{load_music_from_internal_data, load_sound_from_internal_data},
     discord::{DiscordChannel, DiscordRpcSignal},
     global_resource_package::GlobalResources,
-    model::{player::Player, world_object::WorldSpaceObjectCollider},
+    model::{
+        player::Player,
+        world_object::{ObjectCollider, WorldSpaceObjectCollider},
+    },
     project_constants::ProjectConstants,
     rendering::utilities::{anim_texture::AnimatedTexture, map_render::MapRenderer},
 };
@@ -478,6 +561,21 @@
                 20,
                 Color::GREEN,
             );
+            draw.draw_text(
+                format!(
+                    "player: ({}, {}) size: {} map: ({}, {})",
+                    self.player.position.x,
+                    self.player.position.y,
+                    self.player.size,
+                    self.world_map.get_map_size().x,
+                    self.world_map.get_map_size().y
+                )
+                .as_str(),
+                10,
+                50,
+                20,
+                Color::GREEN,
+            );
         }
 
         draw.draw_rectangle(draw.get_screen_width() / 2 - 225, 0, 450, 40, Color::WHITE);
@@ -511,7 +609,6 @@
         let current_temperature = self.world_map.sample_temperature_at(player.position);
         let map_size = self.world_map.get_map_size();
         // TODO: You can access the colission list with: self.world_colliders
-        // like this: self.world_colliders[0].size.x;
 
         // Get input direction components
         let h_axis = raylib.is_key_down(KeyboardKey::KEY_D) as i8
@@ -547,7 +644,70 @@
 
         let velocity_modifier = &player.velocity * delta_time;
 
-        player.position += velocity_modifier;
+        let player_size =
+            (constants.tile_size as f32 * constants.player.start_size * player.size / 2.0) as f32;
+
+        player.position.x += velocity_modifier.x;
+
+        for i in &self.world_colliders {
+            if player.position.x - player_size <= i.position.x + i.size.x / 2.0
+                && player.position.x + player_size >= i.position.x + i.size.x / 2.0
+                && player.position.y - player_size <= i.position.y + i.size.y / 2.0
+                && player.position.y + player_size >= i.position.y + i.size.x / 2.0
+            {
+                // if player.velocity.x < 0.0 {
+                //     player.position.x = i.position.x + i.size.x / 2.0 + player_size;
+                // } else if player.velocity.x > 0.0 {
+                //     player.position.x = i.position.x - i.size.x / 2.0 - player_size;
+                // }
+
+                player.position.x -= velocity_modifier.x;
+                player.velocity.x = 0.0;
+                break;
+            }
+        }
+
+        if player.position.x - player_size < 0.0
+            || player.position.x + player_size > self.world_map.get_map_size().x
+        {
+            if player.velocity.x < 0.0 {
+                player.position.x = player_size;
+            } else if player.velocity.x > 0.0 {
+                player.position.x = self.world_map.get_map_size().x - player_size;
+            }
+            player.velocity.x = 0.0;
+        }
+
+        player.position.y += velocity_modifier.y;
+
+        for i in &self.world_colliders {
+            if player.position.x - player_size <= i.position.x + i.size.x / 2.0
+                && player.position.x + player_size >= i.position.x + i.size.x / 2.0
+                && player.position.y - player_size <= i.position.y + i.size.y / 2.0
+                && player.position.y + player_size >= i.position.y + i.size.x / 2.0
+            {
+                if player.velocity.y < 0.0 {
+                    player.position.y = i.position.y + i.size.y / 2.0 + player_size;
+                } else if player.velocity.y > 0.0 {
+                    player.position.y = i.position.y - i.size.y / 2.0 - player_size;
+                }
+                player.position.y -= velocity_modifier.y;
+                player.velocity.y = 0.0;
+
+                break;
+            }
+        }
+
+        if player.position.y + player_size > 0.0
+            || player.position.y - player_size < -self.world_map.get_map_size().y
+        {
+            if player.velocity.y > 0.0 {
+                player.position.y = -player_size;
+            } else if player.velocity.y < 0.0 {
+                player.position.y = -self.world_map.get_map_size().y + player_size;
+            }
+            player.velocity.y = 0.0;
+        }
 
         self.update_camera(raylib);
     }