mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add difficulty selection
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
use checkers::ui::{
|
use checkers::{
|
||||||
macroquad::{
|
super_advanced_ai::BotDificulty,
|
||||||
main_menu::{draw_main_menu, get_main_menu_style},
|
ui::{
|
||||||
mode_selection::draw_mode_selection,
|
macroquad::{
|
||||||
|
difficulty_selection::draw_dificulty_selection,
|
||||||
|
main_menu::{draw_main_menu, get_main_menu_style},
|
||||||
|
mode_selection::draw_mode_selection,
|
||||||
|
},
|
||||||
|
state::{GameContext, GuiState},
|
||||||
},
|
},
|
||||||
state::GuiState,
|
|
||||||
};
|
};
|
||||||
use macroquad::{
|
use macroquad::{
|
||||||
color::{BLACK, BLUE, RED, WHITE},
|
color::{BLACK, BLUE, RED, WHITE},
|
||||||
@@ -51,6 +55,8 @@ pub async fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let mut state = Default::default();
|
let mut state = Default::default();
|
||||||
|
let mut context = GameContext::default();
|
||||||
|
|
||||||
let background = load_texture("assets/background.png").await.unwrap();
|
let background = load_texture("assets/background.png").await.unwrap();
|
||||||
|
|
||||||
let main_menu_style = get_general_style().await;
|
let main_menu_style = get_general_style().await;
|
||||||
@@ -78,7 +84,7 @@ pub async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiState::DificultySelection => {
|
GuiState::DificultySelection => {
|
||||||
todo!();
|
draw_dificulty_selection(&mut state, &mut context).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiState::ServerSelection => {
|
GuiState::ServerSelection => {
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ use crate::{
|
|||||||
settings::{client_settings::ClientSettings, general_settings::DEFAULT_URL},
|
settings::{client_settings::ClientSettings, general_settings::DEFAULT_URL},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[derive(PartialEq, Eq, Clone, Copy, Default)]
|
||||||
pub enum BotDificulty {
|
pub enum BotDificulty {
|
||||||
|
#[default]
|
||||||
Easy,
|
Easy,
|
||||||
Normal,
|
Normal,
|
||||||
Hard,
|
Hard,
|
||||||
|
|||||||
53
src/ui/macroquad/difficulty_selection.rs
Normal file
53
src/ui/macroquad/difficulty_selection.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use macroquad::{
|
||||||
|
color::GRAY,
|
||||||
|
math::vec2,
|
||||||
|
shapes::draw_rectangle,
|
||||||
|
ui::{hash, root_ui, widgets::Group},
|
||||||
|
window::{next_frame, screen_height, screen_width},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::ui::{
|
||||||
|
macroquad::menu_builder::MenuBuilder,
|
||||||
|
state::{
|
||||||
|
GameContext,
|
||||||
|
GuiState::{self},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn draw_dificulty_selection(state: &mut GuiState, context: &mut GameContext) {
|
||||||
|
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
||||||
|
let menu_pos = vec2(
|
||||||
|
screen_width() / 2.0 - menu_size.x / 2.0,
|
||||||
|
screen_height() / 2.0 - menu_size.y / 2.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut menu_builder = MenuBuilder::new(menu_size.x, menu_size.y * 0.1);
|
||||||
|
|
||||||
|
draw_rectangle(menu_pos.x, menu_pos.y, menu_size.x, menu_size.y, GRAY);
|
||||||
|
|
||||||
|
Group::new(hash!(), menu_size)
|
||||||
|
.position(menu_pos)
|
||||||
|
.ui(&mut root_ui(), |ui| {
|
||||||
|
menu_builder.label(ui, "Difficulty Selection");
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Easy") {
|
||||||
|
context.is_single = true;
|
||||||
|
context.difficulty = crate::super_advanced_ai::BotDificulty::Easy;
|
||||||
|
*state = GuiState::Game;
|
||||||
|
}
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Medium") {
|
||||||
|
context.is_single = true;
|
||||||
|
context.difficulty = crate::super_advanced_ai::BotDificulty::Normal;
|
||||||
|
*state = GuiState::Game;
|
||||||
|
}
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Hard") {
|
||||||
|
context.is_single = true;
|
||||||
|
context.difficulty = crate::super_advanced_ai::BotDificulty::Hard;
|
||||||
|
*state = GuiState::Game;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next_frame().await;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod difficulty_selection;
|
||||||
pub mod main_menu;
|
pub mod main_menu;
|
||||||
pub mod mode_selection;
|
|
||||||
mod menu_builder;
|
mod menu_builder;
|
||||||
|
pub mod mode_selection;
|
||||||
|
|||||||
44
src/ui/macroquad/mode_selection.rs
Normal file
44
src/ui/macroquad/mode_selection.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use macroquad::{
|
||||||
|
color::GRAY,
|
||||||
|
math::vec2,
|
||||||
|
shapes::draw_rectangle,
|
||||||
|
ui::{hash, root_ui, widgets::Group},
|
||||||
|
window::{next_frame, screen_height, screen_width},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::ui::{
|
||||||
|
macroquad::menu_builder::MenuBuilder,
|
||||||
|
state::GuiState::{self, ServerSelection},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn draw_mode_selection(state: &mut GuiState) {
|
||||||
|
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
||||||
|
let menu_pos = vec2(
|
||||||
|
screen_width() / 2.0 - menu_size.x / 2.0,
|
||||||
|
screen_height() / 2.0 - menu_size.y / 2.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut menu_builder = MenuBuilder::new(menu_size.x, menu_size.y * 0.1);
|
||||||
|
|
||||||
|
draw_rectangle(menu_pos.x, menu_pos.y, menu_size.x, menu_size.y, GRAY);
|
||||||
|
|
||||||
|
Group::new(hash!(), menu_size)
|
||||||
|
.position(menu_pos)
|
||||||
|
.ui(&mut root_ui(), |ui| {
|
||||||
|
menu_builder.label(ui, "Mode selection");
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Singleplayer") {
|
||||||
|
*state = GuiState::DificultySelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Multiplayer") {
|
||||||
|
*state = ServerSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Go back") {
|
||||||
|
*state = GuiState::MainMenu;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next_frame().await;
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::super_advanced_ai::BotDificulty;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum GuiState {
|
pub enum GuiState {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -11,3 +13,9 @@ pub enum GuiState {
|
|||||||
Game,
|
Game,
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct GameContext {
|
||||||
|
pub difficulty: BotDificulty,
|
||||||
|
pub is_single: bool,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user