Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main menu #17

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ fn main() {
.add_systems(
Update,
(
sys_draw_border,
(sys_start_game_on_click).run_if(in_state(GameState::MainMenu)),
(ui::main_menu).run_if(in_state(GameState::MainMenu)),
(
sys_draw_border,
sys_spawn_on_click,
plant_roots::sys_plant_move,
sys_harvester_look_for_fruit,
Expand Down Expand Up @@ -90,15 +90,6 @@ pub fn sys_draw_border(mut gizmos: Gizmos, bounds: Res<LevelBounds>) {
gizmos.line_2d(bounds.max, bounds.max.with_x(bounds.min.x), Color::WHITE);
}

pub fn sys_start_game_on_click(
buttons: Res<ButtonInput<MouseButton>>,
mut next_state: ResMut<NextState<GameState>>,
) {
if buttons.just_pressed(MouseButton::Left) {
next_state.set(GameState::Playing);
}
}

pub fn sys_harvester_look_for_fruit(
mut commands: Commands,
spatial_tree: Res<KDTree2<SpatialTracked>>,
Expand Down
36 changes: 33 additions & 3 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
use bevy::prelude::*;
use bevy_egui::{
egui::{self, RichText},
egui::{self, Align, Layout, RichText},
EguiContexts,
};

use crate::Score;
use crate::{GameState, Score};

pub fn scoreboard(mut contexts: EguiContexts, score: Res<Score>) {
pub fn main_menu(mut contexts: EguiContexts, mut next_state: ResMut<NextState<GameState>>) {
egui::CentralPanel::default()
.frame(egui::Frame::none())
.show(contexts.ctx_mut(), |ui| {
ui.add_space(40.0);
ui.with_layout(Layout::top_down(Align::Center), |ui| {
ui.heading("Welcome to Fruitstar!");
ui.add_space(10.0);
if ui
.button(RichText::new("Start").text_style(egui::TextStyle::Heading))
.clicked()
{
next_state.set(GameState::Playing);
}
});
});
}

pub fn scoreboard(
mut contexts: EguiContexts,
mut score: ResMut<Score>,
mut next_state: ResMut<NextState<GameState>>,
) {
let score_label = format!("Score: {}", score.to_string());
egui::Window::new("Fruitstar")
.collapsible(false)
Expand All @@ -15,5 +37,13 @@ pub fn scoreboard(mut contexts: EguiContexts, score: Res<Score>) {
.resizable(false)
.show(contexts.ctx_mut(), |ui| {
ui.label(RichText::new(score_label).text_style(egui::TextStyle::Heading));
if ui.button("Reset").clicked() {
**score = 0;
}
if ui.button("End").clicked() {
next_state.set(GameState::GameOver);
}
});
}

// High scores
Loading