Minesweeper-style game example using Bevy UI#25039
Open
ickshonpe wants to merge 6 commits into
Open
Conversation
TheBlckbird
approved these changes
Jul 19, 2026
Comment on lines
+29
to
+30
| width: i32, | ||
| height: i32, |
Contributor
There was a problem hiding this comment.
Not to be picky, but what about using u8s or u16s instead? I think it's kinda good practice to always use the smallest possible number type. Or at least unsigned if signed doesn't make any sense
Comment on lines
+515
to
+530
| fn main() { | ||
| App::new() | ||
| .add_plugins(DefaultPlugins) | ||
| .init_resource::<Game>() | ||
| .init_state::<GameState>() | ||
| .add_systems(Startup, setup) | ||
| .add_systems(OnEnter(GameState::Menu), setup_menu) | ||
| .add_systems(OnEnter(GameState::Playing), setup_game) | ||
| .add_observer(on_button_click) | ||
| .add_observer(on_button_over) | ||
| .add_observer(on_button_out) | ||
| .add_observer(on_tile_click) | ||
| .add_observer(on_tile_over) | ||
| .add_observer(on_tile_out) | ||
| .run(); | ||
| } |
Contributor
There was a problem hiding this comment.
What about moving this to the top of the file right below all the structs and enums? That makes it easier to see what systems, Resources and so on are used. Think of it as a table of content
Comment on lines
+23
to
+25
| mined: bool, | ||
| revealed: bool, | ||
| flagged: bool, |
Contributor
There was a problem hiding this comment.
An is_ prefix for booleans makes it easier to understand the code.
| #[derive(Resource)] | ||
| struct Game { | ||
| field: MineField, | ||
| game_over: bool, |
Zeophlite
approved these changes
Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Add a simple game example made using Bevy UI.
I think having some simple, concrete example applications that we can iterate on and that different people can contribute to would be very useful.
Solution
The minefield is displayed using UI nodes in a grid layout that is kept synchronised with a
Gameresource that stores the state of all the cells in an array.Notes
We don't have any builtin reactivity support yet, so it rerenders the whole field in response to any changes. It wouldn't be difficult to add an adhoc incremental rendering system, but I think it would better to wait until Bevy has an official builtin solution.
I didn't use feathers, I'd prefer not make any more significant changes before this is merged (if it is merged) but I'd be happy if someone wants to adapt it to use feathers in a follow up PR.
I considered removing the global
Gameresource, storing each tile’s state on its entity, and using a custom relation to locate neighbouring tiles. It might be a better design, at least from an instructional viewpoint. But, again, I'd rather leave it for someone else to experiment with (if they want to) in a follow up PR.Showcase