DEV Community

Cover image for Bevy Minesweeper: Introduction
Qongzi
Qongzi

Posted on

 

Bevy Minesweeper: Introduction

Check the repository

Hello, in this tutorial we will introduce game development in Rust using Bevy, a free and open source data-driven game engine.

The final result of this course is a cross-platform minesweeper you can test in this live version:

Demo

Disclaimer

The tutorial focuses on the following goals:

  • Breakdown basic Bevy features and the ECS making a minesweeper
  • Using development tools such as the inspector gui, the logger, etc.
  • Developing a generic bevy plugin making good use of the state system and resources
  • Having Web Assembly support

The programming choices are not the most efficient but allow to fulfill the goals. For example, you may notice that the uncovering system has a 3 to 4 frames delay:

  • frame 1: click event read and tile trigger event send
  • frame 2: tile trigger event read and Uncover component insert
  • frame 3: Actual uncovering

There are better ways to do this but this way you learn to receive and send events, place components in order for a system to query it, etc.

A decent understanding of the Rust language is a prerequisite.

Note that this is my first Bevy project, there may be improvements so trust the latest version of the code.

Technologies

Why an ECS?

I have experience in game development using Unity3D component system using C#.
It is very user-friendly, but I think Object-oriented programming is getting obsolete, and I wanted to try an Entity component system.

Unity made an ECS, why not use it?

Unity is taking the leap towards ECS, but looking at the documentation I found it very complex and honestly, bad.
Maybe they were forced to compromise with the existing core but it doesn't stand the comparison with Bevy's ECS.

Why Rust?

I love the rust language, I love game dev, I wanted to try the combination.
Also, since I wanted to experiment with an ECS which is the incarnation of the Compound VS Inheritance pattern in game dev,
using Rust is very natural.

Furthermore, I find garbage collection to be a critical issue in game dev and Rust completely wipes it away.

Resources

We will be using the 0.6 version of the Bevy engine:

Some resources I used that you should check out:

The assets I used are not mine, they are all free for personal use, please check the credits.

I suggest you follow the tutorial using a modern IDE, like Jetbrains CLion or VS Code with the Rust plugin.

ECS

So what's an Entity component system?

The Unity documentation has a nice graphic explanation of ECS:

ECS Infographic

It's a data-oriented coding paradigm using the following elements:

  • Entities: representing an object via a simple identifier (usually a classic integer)
  • Components: structures that can be attached to entities, containing data but no logic
  • Systems: functions using Component queries to apply logic

The point is to apply identical logic to all Health components instead of applying logic to a complete object.
It is more modular and makes it easier to manage in threads.

The final element would be Resources which are data shared across systems.


Next Chapter


Author: FΓ©lix de Maneville
Follow me on Twitter

Published by Qongzi

Top comments (0)

Rust Roundup: Top News & trends

Ramping Up Your CLI Toolkit with Rust

Discover 50 CLI tools written using Rust that any developer can find useful. A complete comprehensive command-line experience is provided, helping devs compactly view and utilize available Rust-based tools at several stages. Don't miss this opportunity to optimize your workflow! (Browse Tools πŸ“)

Moving from Electron to Tauri

Explore the benefits and the process of moving from Electron to Tauri to create lean and efficient apps. This article narrates a personal experience in rebuilding an Electron-based UMLBoard app using Tauri as a Rust alternative. Tauri is claimed to create apps up to ten times smaller too! (Switch over now! ⚑)

Plumbing Tracing Through a Kafka Cluster with Rust

Catch up with tracing distributed systems such as Kafka using Rust and OpenTelemetry with this complete guide. It explained how-to monitors a postulated request through applications to maintaining oversight between distributed Framework ecosystems present in Kafka, simply using Rust. (Discover Insights πŸ”Ž)

Stay up-to-date with our weekly round-ups for the news and trends from the Rust ecosystem!