Skip to content

PacktPublishing/Game-Development-with-Rust-and-WebAssembly

Repository files navigation

Game Development with Rust and WebAssembly

Game Development with Rust and WebAssembly, published by Packt

Game Development with Rust and WebAssembly

This is the code repository for Game Development with Rust and WebAssembly, published by Packt.

Learn how to run Rust on the web while building a game

What is this book about?

The Rust programming language has held the most-loved technology ranking on Stack Overflow for 6 years running, while JavaScript has been the most-used programming language for 9 years straight as it runs on every web browser. Now, thanks to WebAssembly (or Wasm), you can use the language you love on the platform that's everywhere.

This book covers the following exciting features:

  • Build and deploy a Rust application to the web using WebAssembly
  • Use wasm-bindgen and the Canvas API to draw real-time graphics
  • Write a game loop and take keyboard input for dynamic action
  • Explore collision detection and create a dynamic character that can jump on and off platforms and fall down holes
  • Manage animations using state machines
  • Generate levels procedurally for an endless runner
  • Load and display sprites and sprite sheets for animations

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigation

You're currently looking the main branch of this repository, which represents the "completed" state of this book. I say completed because development on this branch is ongoing - specifically the challenges cited in the book are being implemented here. If you want to see the end state of any chapter those are stored as tags, such as https://github.com/PacktPublishing/Game-Development-with-Rust-and-WebAssembly/tree/chapter_1.

Following is what you need for this book:

This game development book is for developers interested in Rust who want to create and deploy 2D games to the web. Game developers looking to build a game on the web platform using WebAssembly without C++ programming or web developers who want to explore WebAssembly along with JavaScript web will also find this book useful. The book will also help Rust developers who want to move from the server side to the client side by familiarizing them with the WebAssembly toolchain. Basic knowledge of Rust programming is assumed.

With the following software and hardware list you can run all code files present in the book (Chapter 1-11).

Software and Hardware List

Chapter Software required version OS required
(1 - 11) Rust Toolchains via Rustup 1.57.0 Any OS
(1 - 11) NodeJS 16.13.0 Any OS
(1 - 11) Rust Compile target wasm32-unknown-unknown NA NA

I use https://asdf-vm.com to install Node and a .tool-versions file is present but you don't have to. Instructions for creating a new project are found in the book (chapter 1) but the project can also be setup by cloning this repository and running the commands for building and running. Speaking of that:

Running this App

Installation

npm install Will install the Node dependencies (primarily WebPack). Don't worry you don't have to think about those much.

Running in debug

npm start Will compile the application to Wasm and start a server, running it at localhost:8080 by default. This will also ensure wasm-pack is setup and running and run cargo build.

Building for release

npm run build Creates a release build and puts it in the dist directory.

Running Tests

npm run test

You can use a lot of the cargo commands as well - but those do not go through the process of bundling up the built assembly for distribution.

Deployment

This branch is setup for continuous deployment with GitHub Actions, as is the tag for chapter_10. Something to keep in mind when forking the repository. The current production version of this game can be found at:

https://rust-games-webassembly.netlify.app

Challenges

At the end of the book (Further Resources and What's Next?) there are six challenges for you, the reader. I'll be completing them on and off my stream, and making a note here when they are complete.

Challenge #6:

  • Challenge #6 was completed two ways. I displayed the score via the canvas's render text function, as well as via the DOM. There are two branches with the solutions: add-score and add-score-html. The HTML version looks a lot better, and is also implemented in the main branch.

More Information

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

The Code in Action videos for this book can be viewed at https://bit.ly/3uxXl4W.

Related products

Get to Know the Author

Eric Smith is a software crafter with over 20 years of software development experience. Since 2005, he's worked at 8th Light, where he consults for companies big and small by delivering software, mentoring developers, and coaching teams. He's a frequent speaker at conferences speaking on topics such as educating developers and test-driven development, and holds a master's degree in video game development from DePaul University. Eric wrote much of the code for this book live on his Twitch stream. When he's not at the computer, you can find Eric running obstacle races and traveling with his family.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781801070973

About

Game Development with Rust and WebAssembly, Published by Packt

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages