/rusty_sword_arena

Rusty Sword Arena: A Crash Course in Rust (Companion repository to the OSCON tutorial)

Primary LanguageRustMIT LicenseMIT

Build Status

Rusty Sword Arena: A Crash Course in Rust

This is the companion repository to the half-day tutorial for OSCON 2019. (The links you need during OSCON are in the Resources section at the bottom)

Just watching the training will be entertaining and informative, but you will truly learn a lot more if you actually dig in and do some coding! This repository is for you hands-on-learners who are ready to roll.

Preparation - DO THIS BEFORE OSCON

I use macOS, and that is what I developed Rusty Sword Arena on. Everything ought to be able to work on major Linux distributions and Windows. Please do the following preparation before OSCON so we can focus our time on learning Rust. Please contact me ASAP if you have trouble with anything on this page.

Install Rust

We will be using Rust 1.35.0 or newer for Rusty Sword Arena.

  • Go to rust-lang.org and click on the big yellow Get Started button and follow the instructions to install Rust for your operating system.
    • Please DO NOT install rust via some other package manager, because it will be a version that is too old.

You should get somewhat similar output (versions may be newer) if you run commands like the ones below. If you get a version older than 1.35.0, then run rustup update to install a newer version.

$ rustc --version
rustc 1.35.0 (3c235d560 2019-05-20)

$ cargo --version
cargo 1.35.0 (6f3e9c367 2019-04-04)

If you have any trouble with installation or running the commands above, please contact me before OSCON!!!

Install Other Dependencies

ZeroMQ 4.1.x or later is used under-the-hood for networking. It's abstracted away, so you will not actually deal with it other than making sure the library portion of it is installed so Rust can find it.

On Linux, the alsa development libraries are needed for sound.

macOS

Make sure you have Homebrew installed and then run

brew install pkgconfig zmq

CentOS

# czmq-devel is in EPEL (Extra Packages for Linux), so if you haven't installed it, do
sudo yum install -y epel-release

# ...then you can actually install the dependencies
sudo yum install -y czmq-devel alsa-lib-devel

Debian/Ubuntu

Run the following AND follow the instructions for Debian/Ubuntu in the ZeroMQ's download documentation (you might need to create an /etc/apt/sources.list.d/zeromq.list file if you don't have a sources.list file on Debian 9) :

sudo apt install libasound2-dev
sudo apt install pkgconf

Other Operating Systems

Follow the instructions in ZeroMQ's download documentation 4.1.x or later for your operating system.

See if everything is working

THIS IS THE IMPORTANT PART! Following these steps will download a few hundred dependencies, which is really important to do before OSCON because when a hundred people do it at the same time at the conference the IT folks freak out and scold me. 😉 Also, this will ensure that you have a working environment so that you will be able to listen during the tutorial instead of trying to get this stuff working.

  • Clone this repository (see the green "Clone or Download" button at the top-right of the page)
  • From a terminal, change directory to inside the repository and then run:
cargo run --bin server
  • It should download & compile for a long time and then you should get a startup message and some stats.
    • Leave the server running for the next step! When you're ready to shut it down press Ctrl-C
    • If your firewall prompts you for whether to allow the server to use the network, choose YES
    • If something crashes or goes wrong, please contact me before OSCON!!!
  • In another terminal window, change directory to inside the repository and run:
cargo run --bin client -- YOURNAME localhost
  • You can replace YOURNAME with your own name, for example: Nathan
  • This should compile much more quickly since it shares all the same dependencies as the server
    • when compilation is done, then a window should appear with a circle holding a sword
    • The server should say something about a player connecting
  • The sword should point at your mouse pointer.
  • The circle can be moved around with the arrow keys or WASD.
  • You can swing your sword by clicking your mouse or pressing space bar
  • Stop the client by closing the window or pressing the Escape key.
  • Stop the server by pressing Ctrl-C in its terminal window.
  • If something crashes or goes wrong, please contact me before OSCON!!!

If you got through all those steps without anything crashing, then you are all ready for OSCON. We are going to learn Rust while making our own game client similar to this reference implementation. ✨🎉✨

Prepare to Learn

Please do each of the following before OSCON (see the How To Learn Rust page for details on all of these)

  • Choose an IDE (or Editor) and configure it with Rust support and customize it to your liking
  • Choose one place to "find answers" and either introduce yourself (if it's a forum, IRC, etc.) or find the answer to one question you have.
  • Try doing something in Rust! If you don't have a better idea, then just do this:
    • cargo new message
    • cd message
    • cargo run
    • Edit src/main.rs and change the message.
    • cargo run again to see your new message.
  • Check out the descriptions of the tools and books.

Resources

Now you are ready for the tutorial! You are going to make your own game client far Rusty Sword Arena!