Merge pull request #63 from Ewpratten/next_level_screen_buttons

Added level select button
This commit is contained in:
Evan Pratten 2021-10-03 21:23:20 -07:00 committed by GitHub
commit c7412689be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct NextLevelScreen {
is_next_pressed: bool,
is_level_select_pressed: bool,
screen_load_time: DateTime<Utc>,
attempt_time: String,
best_time: String,
@ -34,6 +35,7 @@ impl NextLevelScreen {
pub fn new() -> Self {
Self {
is_next_pressed: false,
is_level_select_pressed: false,
screen_load_time: Utc::now(),
attempt_time: String::new(),
best_time: String::new(),
@ -100,6 +102,9 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
.unwrap();
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
}
else if self.is_level_select_pressed {
Ok(ActionFlag::SwitchState(Scenes::LevelSelectScreen))
}else {
Ok(ActionFlag::Continue)
}
@ -108,6 +113,7 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished NextLevelScreen");
self.is_next_pressed = false;
self.is_level_select_pressed = false;
Ok(())
}
}
@ -168,11 +174,42 @@ impl ScreenSpaceRender for NextLevelScreen {
.check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, screen_size.y / 2.0 + 50.0),
">> Next Level",
"Next Level",
25,
hovering_next_button,
Color::WHITE,
);
if hovering_next_button {
raylib.draw_rgb_split_text(
Vector2::new(50.0, screen_size.y as f32 / 2.0 + 50.0),
">>",
25,
hovering_next_button,
Color::WHITE,
);
};
self.is_next_pressed = hovering_next_button && mouse_pressed;
//Next Level
let hovering_level_select_button =
Rectangle::new(80.0, screen_size.y as f32 / 2.0 + 90.0, 300.0, 20.0)
.check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, screen_size.y / 2.0 + 100.0),
"Back To Level Select",
25,
hovering_level_select_button,
Color::WHITE,
);
if hovering_level_select_button {
raylib.draw_rgb_split_text(
Vector2::new(50.0, screen_size.y as f32 / 2.0 + 100.0),
">>",
25,
hovering_level_select_button,
Color::WHITE,
);
};
self.is_level_select_pressed = hovering_level_select_button && mouse_pressed;
}
}