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
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: bool
player: Player
world_map: MapRenderer
camera: Camera2D
last_update: SystemTime
game_soundtrack: Music
world_colliders: Vec<ObjectCollider>
show_debug_info: bool
play_start_time: DateTime<Utc>
Implementations
pub fn new(
raylib_handle: &mut RaylibHandle,
thread: &RaylibThread,
constants: &ProjectConstants
) -> Self
Construct a new PlayableScene
-pub async fn render_frame(
&mut self,
raylib: &mut RaylibHandle,
rl_thread: &RaylibThread,
discord: &Sender<DiscordRpcSignal>,
global_resources: &GlobalResources,
constants: &ProjectConstants,
audio_subsystem: &mut RaylibAudio
) -> MenuStateSignal
Handler for each frame
-Trait Implementations
Formats the value using the given formatter. Read more
+}Fields
has_updated_discord_rpc: bool
player: Player
world_map: MapRenderer
camera: Camera2D
last_update: SystemTime
game_soundtrack: Music
world_colliders: Vec<ObjectCollider>
show_debug_info: bool
play_start_time: DateTime<Utc>
Implementations
pub fn new(
raylib_handle: &mut RaylibHandle,
thread: &RaylibThread,
constants: &ProjectConstants
) -> Self
Construct a new PlayableScene
+pub async fn render_frame(
&mut self,
raylib: &mut RaylibHandle,
rl_thread: &RaylibThread,
discord: &Sender<DiscordRpcSignal>,
global_resources: &GlobalResources,
constants: &ProjectConstants,
audio_subsystem: &mut RaylibAudio
) -> MenuStateSignal
Handler for each frame
+Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for PlayableScene
impl !Send for PlayableScene
impl !Sync for PlayableScene
impl Unpin for PlayableScene
impl UnwindSafe for PlayableScene
Blanket Implementations
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);
}