From 9af1683801816dcdaac552193bb403c48dd0e585 Mon Sep 17 00:00:00 2001 From: Marcelo Geldres Date: Sat, 2 Oct 2021 18:50:40 -0400 Subject: [PATCH 1/2] Fixes to the Pause menu Centering the hitbox of main menu and the hitbox of resume --- game/src/scenes/pause_screen.rs | 64 +++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/game/src/scenes/pause_screen.rs b/game/src/scenes/pause_screen.rs index a496c5a..854175a 100644 --- a/game/src/scenes/pause_screen.rs +++ b/game/src/scenes/pause_screen.rs @@ -59,6 +59,15 @@ impl Action for PauseScreen { ) -> Result, ScreenError> { trace!("execute() called on PauseScreen"); self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); + //Screen Size + let screen_size = context.renderer.borrow_mut().get_screen_size(); + + + let centered_x_menu = (screen_size.x as f32 / 2.0) - 120.0; + let centered_y_menu = (screen_size.y as f32 / 2.0) + 100.0; + let centered_x_paused = (screen_size.x as f32 / 2.0) - 220.0; + let centered_y_paused = (screen_size.y as f32 / 2.0) - 40.0; + //Mouse Position let mouse_position: Vector2 = context.renderer.borrow_mut().get_mouse_position(); @@ -69,14 +78,16 @@ impl Action for PauseScreen { .is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); //"Hitboxes" for the resume and Main menu buttons + + //For Paused if is_left_click - && Rectangle::new(322.0, 321.0, 435.0, 80.0).check_collision_point_rec(mouse_position) + && Rectangle::new(centered_x_paused, centered_y_paused, 435.0, 80.0).check_collision_point_rec(mouse_position) { return Ok(ActionFlag::SwitchState(Scenes::InGameScene)); } - + //For Menu if is_left_click - && Rectangle::new(390.0, 464.0, 200.0, 50.0).check_collision_point_rec(mouse_position) + && Rectangle::new(centered_x_menu, centered_y_menu, 200.0, 50.0).check_collision_point_rec(mouse_position) { return Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen)); } @@ -114,6 +125,8 @@ impl ScreenSpaceRender for PauseScreen { //Mouse Input let is_left_click = raylib.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); + raylib.draw_rectangle_lines(0, 0, screen_size.x as i32, screen_size.y as i32, config.colors.white); + //Pause Menu Texts With Glitchy Effect raylib.draw_text( "Paused", @@ -179,23 +192,60 @@ impl ScreenSpaceRender for PauseScreen { Color::WHITE, ); - if Rectangle::new(390.0, 464.0, 200.0, 50.0).check_collision_point_rec(mouse_position) { + + //Variables for centering + let centered_x_menu = (screen_size.x as f32 / 2.0) - 120.0; + let centered_y_menu = (screen_size.y as f32 / 2.0) + 100.0; + let centered_x_paused = (screen_size.x as f32 / 2.0) - 220.0; + let centered_y_paused = (screen_size.y as f32 / 2.0) - 40.0; + + + if Rectangle::new(centered_x_menu, centered_y_menu, 200.0, 50.0).check_collision_point_rec(mouse_position) { + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 116, + (screen_size.y as i32 / 2) + 100, + 50, + Color::RED, + ); + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 124, + (screen_size.y as i32 / 2) + 100, + 50, + Color::BLUE, + ); raylib.draw_text( "Main Menu", (screen_size.x as i32 / 2) - 120, (screen_size.y as i32 / 2) + 100, 50, - Color::YELLOW, + Color::WHITE, ); + } - if Rectangle::new(322.0, 321.0, 435.0, 80.0).check_collision_point_rec(mouse_position) { + if Rectangle::new(centered_x_paused, centered_y_paused, 435.0, 80.0).check_collision_point_rec(mouse_position) { + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 215, + (screen_size.y as i32 / 2) - 40, + 120, + Color::BLUE, + ); + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 225, + (screen_size.y as i32 / 2) - 40, + 120, + Color::RED, + ); raylib.draw_text( "Paused", (screen_size.x as i32 / 2) - 220, (screen_size.y as i32 / 2) - 40, 120, - Color::DARKBLUE, + Color::WHITE, ); } } From 27abfcd149ad28d62b550721a0ea7bcb66023e59 Mon Sep 17 00:00:00 2001 From: Marcelo Geldres Date: Sat, 2 Oct 2021 18:54:46 -0400 Subject: [PATCH 2/2] Push Comment just to make sure I commit and push the code --- game/src/scenes/pause_screen.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/game/src/scenes/pause_screen.rs b/game/src/scenes/pause_screen.rs index 854175a..6f5ad77 100644 --- a/game/src/scenes/pause_screen.rs +++ b/game/src/scenes/pause_screen.rs @@ -192,6 +192,7 @@ impl ScreenSpaceRender for PauseScreen { Color::WHITE, ); + //Push comment //Variables for centering let centered_x_menu = (screen_size.x as f32 / 2.0) - 120.0;