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..32aca9f3 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -81,33 +81,48 @@ 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 - ) - } - } + // 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 - player_size / 2, + self.player.position[1] as i32 * -1 - player_size / 2, + player_size, + player_size, + Color::LIGHTBLUE + ); + } + + pub fn draw_ui( + &mut self, + draw: &mut RaylibDrawHandle, + constants: &ProjectConstants, + ) { draw.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, - Color::GREEN + draw.get_screen_width() / 2 - 225, 0, + 450, 40, + Color::WHITE + ); + draw.draw_text( + "Unregistered HyperCam 2", + draw.get_screen_width() / 2 - 215, 0, + 32, Color::BLACK ); } @@ -143,7 +158,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); } } @@ -154,6 +169,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; } }