From 57c5aaa71471092c3e6e31106b101a76aa0781a1 Mon Sep 17 00:00:00 2001 From: Si Bartha Date: Sat, 2 Apr 2022 16:05:14 -0400 Subject: [PATCH 1/3] Poo Text --- game/dist/project-constants.json | 3 +- game/game_logic/src/project_constants.rs | 3 ++ .../src/scenes/player_interaction.rs | 52 +++++++++++-------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/game/dist/project-constants.json b/game/dist/project-constants.json index cd2d0e59..46f8c02e 100644 --- a/game/dist/project-constants.json +++ b/game/dist/project-constants.json @@ -20,6 +20,7 @@ "player": { "max_velocity": 3, "acceleration": 2, - "deceleration": 1 + "deceleration": 1, + "start_size": 0.8 } } diff --git a/game/game_logic/src/project_constants.rs b/game/game_logic/src/project_constants.rs index 0797baf2..6df497d3 100644 --- a/game/game_logic/src/project_constants.rs +++ b/game/game_logic/src/project_constants.rs @@ -40,6 +40,9 @@ pub struct PlayerConstants { /// Deceleration, tiles per second per second pub deceleration: u32, + + /// Starting size of player in tiles + pub start_size: f32, } /// This structure is filled with the contents of `dist/project-constants.json` at runtime diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs index cef3186e..294278c7 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -81,34 +81,44 @@ impl PlayableScene { // Clear the screen draw.clear_background(Color::WHITE); + + self.draw_world(&mut draw, constants); - { - // Begin camera mode - let mut ctx2d = draw.begin_mode2D(self.camera); + self.draw_ui(&mut draw, constants); + } - // Render the map - self.world_map.render_map(&mut ctx2d, &self.camera, true); - } + pub fn draw_world( + &mut self, + draw: &mut RaylibDrawHandle, + constants: &ProjectConstants, + ) { + // Begin camera mode + let mut ctx2d = draw.begin_mode2D(self.camera); - for i in 0..100 { - for j in 0..100 { - draw.draw_rectangle( - constants.tile_size as i32 * (i * 2), - constants.tile_size as i32 * (j * 2) * -1, - constants.tile_size as i32, - constants.tile_size as i32, - Color::RED - ) - } - } - - draw.draw_rectangle( + // Render the map + self.world_map.render_map(&mut ctx2d, &self.camera, true); + + ctx2d.draw_rectangle( self.player.position[0] as i32, self.player.position[1] as i32 * -1, - (constants.tile_size as f32 * self.player.size) as i32, - (constants.tile_size as f32 * self.player.size) as i32, + (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, + (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, Color::GREEN ); + + } + + pub fn draw_ui( + &mut self, + draw: &mut RaylibDrawHandle, + constants: &ProjectConstants, + ) { + draw.draw_fps(0, 0); + draw.draw_text( + "Poo Text", + 10, 100, 144, + Color::BROWN + ); } // Physics From 82991696484a93f923726003322f8e9022f29f33 Mon Sep 17 00:00:00 2001 From: Si Bartha Date: Sat, 2 Apr 2022 16:40:50 -0400 Subject: [PATCH 2/3] Unregistered Hypercam 2 --- .../src/scenes/player_interaction.rs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs index 294278c7..f4227582 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -103,9 +103,8 @@ impl PlayableScene { self.player.position[1] as i32 * -1, (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, - Color::GREEN + Color::LIGHTBLUE ); - } pub fn draw_ui( @@ -113,11 +112,15 @@ impl PlayableScene { draw: &mut RaylibDrawHandle, constants: &ProjectConstants, ) { - draw.draw_fps(0, 0); + draw.draw_rectangle( + draw.get_screen_width() / 2 - 225, 0, + 450, 40, + Color::WHITE + ); draw.draw_text( - "Poo Text", - 10, 100, 144, - Color::BROWN + "Unregistered HyperCam 2", + draw.get_screen_width() / 2 - 215, 0, + 32, Color::BLACK ); } @@ -153,7 +156,7 @@ impl PlayableScene { * constants.player.deceleration as f32 * constants.tile_size as f32 * delta_time; - if player.velocity.magnitude() < 0.01 { + if player.velocity.magnitude() < 1.0 { player.velocity.set_magnitude(0.0); } } @@ -164,6 +167,18 @@ impl PlayableScene { } player.position += &player.velocity * delta_time; + + 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; } } From 38f26d7330669ffc0ddc15290fced5fe9c24d530 Mon Sep 17 00:00:00 2001 From: Si Bartha Date: Sat, 2 Apr 2022 16:47:31 -0400 Subject: [PATCH 3/3] Center Plater --- game/game_logic/src/scenes/player_interaction.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs index f4227582..32aca9f3 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -97,12 +97,14 @@ impl PlayableScene { // Render the map self.world_map.render_map(&mut ctx2d, &self.camera, true); - + + 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, - self.player.position[1] as i32 * -1, - (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, - (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32, + self.player.position[0] as i32 - player_size / 2, + self.player.position[1] as i32 * -1 - player_size / 2, + player_size, + player_size, Color::LIGHTBLUE ); }