Main menu button fixes
This commit is contained in:
parent
ff36b1c2c3
commit
d972238574
@ -1,9 +1,6 @@
|
|||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, pallette::WATER_DARK};
|
||||||
gamecore::{GameCore, GameState},
|
|
||||||
lib::wrappers::audio::player::AudioPlayer,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::screen::Screen;
|
use super::screen::Screen;
|
||||||
|
|
||||||
@ -34,40 +31,48 @@ impl Screen for MainMenuScreen {
|
|||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"ONE BREATH",
|
"ONE BREATH",
|
||||||
(win_height / 2) - 80,
|
(win_height / 2) - 80,
|
||||||
win_width / 4,
|
win_width / 8,
|
||||||
40,
|
80,
|
||||||
Color::BLACK,
|
Color::BLACK,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get mouse position data
|
||||||
|
let mouse_position = draw_handle.get_mouse_position();
|
||||||
|
let hovering_play_button = mouse_position.y > (win_width as f32 / 4.0)
|
||||||
|
&& mouse_position.y < (win_width as f32 / 4.0) + 60.0;
|
||||||
|
let hovering_quit_button = mouse_position.y > (win_width as f32 / 4.0) + 100.0
|
||||||
|
&& mouse_position.y < (win_width as f32 / 4.0) + 160.0;
|
||||||
|
|
||||||
// Play and quit
|
// Play and quit
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Play",
|
"Play",
|
||||||
(win_height / 2) - 80,
|
(win_height / 2) + 120,
|
||||||
(win_width / 4) + 100,
|
(win_width / 4),
|
||||||
20,
|
60,
|
||||||
Color::BLACK,
|
match hovering_play_button {
|
||||||
|
true => Color::GREEN,
|
||||||
|
false => Color::BLACK,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Quit",
|
"Quit",
|
||||||
(win_height / 2) - 80,
|
(win_height / 2) + 130,
|
||||||
(win_width / 4) + 140,
|
(win_width / 4) + 100,
|
||||||
20,
|
60,
|
||||||
Color::BLACK,
|
match hovering_quit_button {
|
||||||
|
true => Color::GREEN,
|
||||||
|
false => Color::BLACK,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle button presses
|
// Handle button presses
|
||||||
let mouse_position = draw_handle.get_mouse_position();
|
|
||||||
let mouse_clicked = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
let mouse_clicked = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
||||||
|
|
||||||
// Check clicks
|
// Check clicks
|
||||||
if mouse_clicked {
|
if mouse_clicked {
|
||||||
if mouse_position.y > (win_width as f32 / 4.0) + 100.0
|
if hovering_play_button {
|
||||||
&& mouse_position.y < (win_width as f32 / 4.0) + 120.0
|
|
||||||
{
|
|
||||||
return Some(GameState::InGame);
|
return Some(GameState::InGame);
|
||||||
} else if mouse_position.y > (win_width as f32 / 4.0) + 140.0
|
} else if hovering_quit_button {
|
||||||
&& mouse_position.y < (win_width as f32 / 4.0) + 180.0
|
|
||||||
{
|
|
||||||
return Some(GameState::GameQuit);
|
return Some(GameState::GameQuit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user