2015-07-04: Original article. 2015-07-25: Changed library to rust-sdl2 0.6, no change to rust code. 2015-10-17: Changed library to rust-sdl2 0.9; increased the date of publication. 2016-01-21: Changed library to rust-sdl2 0.13, minimal change to rust code.
This is the introduction of a series whose objective is to explore the Rust programming language and ecosystem through the development of a simple, old-school shooter. It is composed of 16 parts, excluding this introduction:
This tutorial was written for people who are already somewhat familiar with the craft of software development, perhaps even through a scripting language, and who have just discovered this strange beast called Rust. They skimmed through the Book, read plenty of blog posts about how this familiar-looking language supposedly challenges all previous ideas about software safety and, excited, want to discover how Rust really works out in practice.
What I demand of the reader is that he or she (or it?) understands such concepts as interfaces, methods, conditional structures, and (basic) static typing. Most of the time, the meaning of these terms will be self-evident from the context. However, if these pose a problem to you, then be informed that I will not go to great lengths to explain them.
I also expect you to have already learned a bit of Rust prior to reading this
tutorial, at least from a high level. For example, you must understand what
use statement does, at least in the
main.rs file, however there is
no need to be an expert in the subject as we will discover its subtleties
In the next couple of weeks, we are going to build a simple space shooter based on Mike Geig's superb 2D Game Development Course, and a basic library called phi which will provide us with the basic components required by 2D games, such as views (called screens in LibGDX), rectangles with built-in (albeit basic) collision detection, and animated sprites.
The libraries we are going to use for that will be AngryLawyer's SDL2 bindings, version 0.13, which you can see here, and the associated plugins.
Before we continue, I want to stress that you do not need to have mastered Rust prior to reading this tutorial. On the contrary, exploring Rust's subtleties is one of its objectives, if not the main one because, let's be honest, I do not recommend to use phi in production. However, you need to have at least skimmed through the book or Rust by Example.
Basically, I will not explain the syntax, but how to use it to make things.
So, without further ado, let's get to it!
After being asked about it a few times, I thought I'd include a little disclaimer:
You can use the code we're writing in this tutorial for whatever purpose you have, whether in a personal project or a commercial one.
I would like to note, however, that I do not encourage it — not because of copyright stuff, but simply because I'm building this project with pedagogy in mind, not performance or maintainability.
THIS DOES NOT INCLUDE THE GAME'S ASSETS, which I've mostly taken from google and Mike Geig's course to save time. I might bother to replace those by custom resources one day. Until then, though, you shouldn't use those in your projects, just in case.