Posts
Pathfinding in Rust - Part 2 - BFS
In the last section, we created a grid-based map with tiles and code to render it. That puts us in a good position to start the pathfinding logic.
Start and end We’ll need a start and end point to track where we’re pathfinding to and from. Later on, I’d like to set this via mouse input, but for now, let’s just make them hard coded variables:
let start = Position { x: 0, y: 0 }; let end = Position { x: 7, y: 7 }; The basic idea of a pathfinding algorithm is to iterate through the grid by checking the neighbors of any one tile.
Posts
Pathfinding in Rust - Part 4 - BFS cont
In the last section, we implemented a basic version of a breath first traversal. While that is nice and useful, let’s use it to find a path.
To start, we need to update the reached HashSet from last time, into a HashMap<Position, Option>. We’ll use this hash map to track where the tile was reached from. We can use this hash map as a sort of breadcrumb system to generate a path to a destination.
Posts
Pathfinding in Rust - Part 1 - Setup
In this series my goal is to implement various pathfinding algorithms on a 2D grid, and bundle them up into a neat little program to run, test and tweak their parameters live as they run. This post will just cover the initial setup.
For this series I’ll be using Macroquad as a rendering/window engine.
Starting a window With Macroquad, starting a window is extremely easy:
use macroquad::{ color::BLUE, window::{clear_background, next_frame}, }; #[macroquad::main("pathfinder")] async fn main() { println!
Posts
Kickoff
Welcome! I’d like to explore various game dev techniques and concepts, and document that process here. Some of the topics I plan to cover are:
pathfinding procedural generation simulation techniques graphics and shaders quad trees and spatial partitioning more Additionally, I’m going to start off using rust and I’d like to improve my usage of that language. I’ve explored several game engines and rendering libraries including bevy, winit and wpgu.
Posts
Building rust for web with WASM
One of the goals for this project is to produce runnable example in the web browser using web assembly. So let’s dive in to that.
Building Luckily, our graphics library macroquad has comes with WASM build support. The documentation lists the following commands to build for WASM:
rustup target add wasm32-unknown-unknown cargo build --target wasm32-unknown-unknown Running them goes smoothly and produces a .wasm file. I’ve copied that over into the project for this blog, inserted a bit of html, and:
Posts
Pathfinding in Rust - Part 3 - Visualization
In the last section, we wrote up a very basic BFS algorithm. Now, it’s time to add some visualization
Basics I know we’ll need to break up the BFS algorithm into steps, so I do so now:
pub fn start_bfs(&mut self, start: Position) { self.start = start.to_owned(); self.frontier.push_back(start.to_owned()); self.reached.insert(start.to_owned()); } pub fn step_bfs(&mut self) { if self.frontier.is_empty() { println!("algo complete!"); } self.current = self.frontier.pop_front().unwrap().to_owned(); for next in self.map.neighbors(&self.current) { if !