Skip to content

Minesweeper-style game example using Bevy UI#25039

Open
ickshonpe wants to merge 6 commits into
bevyengine:mainfrom
ickshonpe:mines
Open

Minesweeper-style game example using Bevy UI#25039
ickshonpe wants to merge 6 commits into
bevyengine:mainfrom
ickshonpe:mines

Conversation

@ickshonpe

@ickshonpe ickshonpe commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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 Game resource 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 Game resource, 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

mines3

@ickshonpe ickshonpe added C-Examples An addition or correction to our examples A-UI Graphical user interfaces, styles, layouts, and widgets labels Jul 17, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Jul 17, 2026
@ickshonpe ickshonpe added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 17, 2026
@ickshonpe ickshonpe changed the title game example using Bevy UI Minesweeper-style game example using Bevy UI Jul 18, 2026

@TheBlckbird TheBlckbird left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, it's a bit nit picky, but it looks fine in general.

Great idea!

Comment on lines +29 to +30
width: i32,
height: i32,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

@TheBlckbird TheBlckbird Jul 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An is_ prefix for booleans makes it easier to understand the code.

#[derive(Resource)]
struct Game {
field: MineField,
game_over: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another is_ prefix?

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets C-Examples An addition or correction to our examples D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants