The source code that accompanies Hands-on Rust: Effective Learning through 2D Game Development and Play by Herbert Wolverson

Overview

Hands-on Rust Source Code

This repository contains the source code for the examples found in Hands-on Rust. These are also available from my publisher, PragProg and are shared with their permission.

The examples included are:

Installing Rust

This code covers the Rust and Your Development Environment chapter. It is designed to help you get a working Rust toolchain together, and understand the tools Rust provides.

  • Hello World---the obligatory first Rust program we all encounter.
  • Clippy---an example showing Clippy in action, finding a common issue.
  • Clippy Fixed---the Clippy example, now working without suggestions.

First Steps with Rust

This code covers the First Steps with Rust chapter. It is designed to teach language basics.

Build Your First Game with Rust

This code covers the Build Your First Game with Rust chapter. It takes the knowledge from the previous two chapters and helps you make your first game, Flappy Dragon.

  • Hello, Bracket Terminal---import that bracket-lib crate, learn about dependencies and writing to the screen.
  • Flappy States---learn to manage the overall structure of the game with states.
  • Flappy Player---add a player to the game, flapping on command.
  • Flappy Dragon---your first playable game, an ASCII mode Flappy Dragon game.
  • Flappy Bonus---Bonus content, showing Flappy Dragon with graphics and smooth movement.

Flappy Bonus has an accompanying bonus online tutorial.

Build a Dungeon Crawler

This code covers the Build a Dungeon Crawler chapter. It starts a new game that will form the basis of the remainder of the book.

  • Dungeon Map---helps you organize your code into modules, build a blank map, and understand tile map storage.
  • Dungeon Player---adds a player who can walk around the map, introducing game-loop based input handling, state management and interactions between structures.
  • Dungeon Rooms---introduces using algorithms to build a basic dungeon map, and the concept of a map builder API.
  • Dungeon Graphics---adds tile-based rendering to the game, giving you a dungeon you can walk around.

Compose Dungeon Denizens

This code covers the Compose Dungeon Denizens chapter. It introduces the Entity-Component System architecture and focuses on composing dungeon elements from reusable parts.

  • Player ECS---converts the simple player handler to use entities, components and systems. Introduces multi-file modules and using procedural macros. Demonstrates fearless concurrency, and how easy Rust can make it to benefit from concurrency.
  • ECS Monsters---walks you through using the same systems to support monsters in your game. Adds initial collision detection, allowing you to kill monsters by walking into them.

Take Turns with the Monsters

This code covers the Take Turns with the Monsters chapter. It expands upon game states by transitioning between states and implementing a turn-based game structure.

  • Wandering Monsters---Introduces code to make the monsters wander randomly through the dungeon.
  • Turn Based---applies state management to make the game turn based. You move, then the monsters move.
  • Messages of Intent---introduces using the ECS to store messages of intent, allowing you to separate functionality between systems and use the underlying storage system as a messaging system. Makes monsters and the player use the same system to apply movement, but with different movement inputs.

Health and Melee Combat

This code covers the Health and Melee Combat chapter. It adds health to both the player and monsters, and implements a simple combat system. It also adds a heads-up display to show the current game status. It emphasizes code re-use.

  • Health---adds hit points to the game and adds health display. It also introduces the concept of rendering layers, tooltips and naming entities.
  • Combat---allows you to damage monsters by bumping into them, and lets them damage the player.
  • Healing---introduces health restoration, initially by waiting.

Victory and Defeat

This code covers the Victory and Defeat chapter. It adds winning and losing conditions to the game.

  • The Gauntlet---all about trait implementation, and using traits to make Dijkstra Maps work. Monsters path towards the player.
  • Losing---detect when the player is dead, and use a game state to display a "you lost" message. Offer to play again, resetting the game state.
  • Winning---adds an amulet to the map. When the player reaches the amulet, the game state changes to a "you won" screen.

Fields of View

This code covers the Fields of View chapter. It implements traits to provide functionality from bracket-lib---specifically fields of view. It then limits monsters to chasing what they can see, and adds spatial memory.

  • Field of View---introduces the concept of vision, and implements it via traits. Limits the player to displaying only what they can currently see.
  • Monstrous Eyesight---adds fields of view to monsters, reusing the same code. Monsters now only chase the player when they can see it.
  • Memory---keep track of where you've been with a dungeon map memory system. Show areas you've previously visited, but not areas you've yet to discover.

More Interesting Dungeons

This code covers the More Interesting Dungeons chapter. It teaches the reader to create new traits, and use them interchangeably via a trait interface. It covers various popular procedural generation techniques, providing tips and tricks along the way.

  • Traits---convert map generation into a trait-based API and dynamically select algorithms at run-time.
  • Traits: Rooms---convert your existing room generator to a trait-based map builder.
  • Cellular Automata---implement your first real map provider, and learn to use Cellular Automata to make an interesting map.
  • Drunkard's Walk---implement a second map generation technique, and learn about bounded iteration.
  • Prefabs---learn to hand design your own level content, and apply it.
  • Test Harness---a convenient structure for testing map builders without having to play the game over and over. Demonstrates the utility of making traits generic and then building separate harnesses in which to test them.

Map Themes

This code covers the Map Themes chapter. It extends upon reusable traits by creating a generic rendering system that can visually theme any level to the tileset of your choice.

  • Themed Maps---separates the dungeon graphics into one theme, and adds a forest map theme.

Inventory and Power-Ups

This code covers the Inventory and Power-Ups chapter. It teaches you to build items with composition, manage their storage and implement item interactions.

  • Potions and Scrolls---Learn to implement items, reusing a lot of existing code. Adds health potions and a magic mapping item to the game.
  • Carrying Items---learn to use components to represent an item in inventory, and iterate it to display the player's inventory. Use carried items when you want to.

Deeper Dungeons

This code covers the Deeper Dungeons chapter. It extends your data storage system to provide for multi-level dungeons, with the end-game item only appearing on the final level.

  • More Levels---is about making more dungeon levels, showing you how your game structure is reusable and can readily be extended into a deeper game.

Combat Systems and Loot

This code covers the Combat Systems and Loot chapter. Learn to design your entities as data---in TOML files. Learn to de-serialize the files, and use them as templates to spawn items and monsters.

  • Loot Tables---introduces serialization with Serde, and the power it provides for quickly extending your game. Migrate your monsters to simple data files, allowing for quick iteration of new baddies.
  • Better Combat---further extends the data-driven aspects of the game by letting you design weapons and change monster difficulty. Change how monsters spawn, providing for a difficulty curve.
You might also like...
Rust, cargo and QEMU setup for multi-architecture OS development.

rust-osdev-jumpstart Rust, cargo and QEMU setup for multi-architecture OS development. Goal This repo should give you a boost in starting a bare-metal

 A new blockchain architecture under active development, with a strong focus on scalability, privacy and safety
A new blockchain architecture under active development, with a strong focus on scalability, privacy and safety

Project Slingshot Accelerating trajectory into interstellar space. Slingshot is a new blockchain architecture under active development, with a strong

The ray tracer challenge in rust - Repository to follow my development of
The ray tracer challenge in rust - Repository to follow my development of "The Raytracer Challenge" book by Jamis Buck in the language Rust

The Ray Tracer Challenge This repository contains all the code written, while step by implementing Ray Tracer, based on the book "The Ray Tracer Chall

Rust development environment for MIPS on NT4

Summary This is a project which allows us to run Rust "shellcode" in a MIPS environment on NT 4.0. TL;DR Setup NT Install NT 4.0 MIPS in QEMU using th

A collection of crates to make minecraft development (client, server) with rust possible.

rust-craft rust-craft is a collection of crates to make minecraft development (client, server) with rust possible. Motivation There's no better way of

This experiment shows connecting wasm-bindgen generated code to a good-web-game application.

GWG + wasm-bindgen example This experiment shows connecting wasm-bindgen generated code to a good-web-game application. It uses simple_logger crate to

Rust implementation of Andrej Karpathy's micrograd for purposes of learning both ML and Rust.

micrograd_rs Rust implementation of Andrej Karpathy's micrograd for purposes of learning both ML and Rust. Main takeaways Basically the same takeaways

Rust language from simple to deep, and then to strengthen learning in multiple module

Rust Library This project is used to learn rust language from simple to deep, and then to strengthen learning in multiple module. It is used to help n

A bunch of links to blog posts, articles, videos, etc for learning Rust

rust-learning A bunch of links to blog posts, articles, videos, etc for learning Rust. Feel free to submit a pull request if you have some links/resou

Comments
  • Filter out multiple enemy messages moving to the same location

    Filter out multiple enemy messages moving to the same location

    This pull request is in regards to the code in Chapter 9: Victory and Defeat. At least, it's where I discovered it.

    This fixes an issue with enemies being able to move into the same location at the same time. If you have two enemies like this:

    .g.
    g..
    ...
    

    And manipulate them into moving into the center position, they'll both end up occupying the same space. There's no actual check at the time of processing the message that the space is free. I think Legion's parallelism is getting in the way but I'm not sure*.

    Also would like to know if I wrote this correctly or if there is a better/more efficient way. Creating that Vec and throwing it away every frame for positions seen seems wasteful but I'm just getting started with rust so maybe not?

    *I tried following your very recent article to disable Legion's parallelism and test without this fix, but it still occurs. I still see the program using multiple threads on my computer though so I don't trust that it's actually disabled.

    opened by tmilker 1
Owner
Herbert "TheBracket"
Developer of RLTK and Nox Futura open source projects, and consultant on Rust, C++, TypeScript, C#, Java, Mikrotik and anything else you want to hand my way!
Herbert
Game development practices with Rust programming language. I want to use different crates for this.

Hazır Oyun Motorlarını Kullanarak Rust Dili Yardımıyla Oyunlar Geliştirmek Rust programlama dilinde oyun geliştirmek için popüler birkaç hazır çatıyı

Burak Selim Senyurt 16 Dec 27, 2022
This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust to play back video files.

FFmpeg Rust Video Player This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust

Jenin Sutradhar 3 Apr 10, 2024
Elemental System Designs is an open source project to document system architecture design of popular apps and open source projects that we want to study

Elemental System Designs is an open source project to document system architecture design of popular apps and open source projects that we want to study

Jason Shin 9 Apr 10, 2022
Code to follow along the "Zero To Production" book on API development in Rust.

Zero To Production / Code (Chapter 10 - Part 1) Zero To Production In Rust is an opinionated introduction to backend development using Rust. This repo

Luca Palmieri 2.8k Dec 31, 2022
Tool to convert variable and function names in C/C++ source code to snake_case

FixNameCase Tool to convert variable and function names in C/C++ source code to snake_case. Hidden files and files listed in .gitignore are untouched.

AgriConnect 4 May 25, 2023
This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition

Overview This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

chuan 549 Dec 26, 2022
Source code for the book Rust in Action

Welcome to Rust in Action source code This source code repository is a companion to the Rust in Action book available from Manning Publications. Suppo

Rust in Action 1.3k Dec 30, 2022
Source code of Ferrocene, safety-critical Rust toolchain

Ferrocene is a toolchain to enable the use of the Rust programming language in safety-critical environments. It is a proper downstream of the main Rus

Ferrocene 530 Oct 7, 2023
This blog provides detailed status updates and useful information about Theseus OS and its development

The Theseus OS Blog This blog provides detailed status updates and useful information about Theseus OS and its development. Attribution This blog was

Theseus OS 1 Apr 14, 2022
Source code from Atlas, our 64k demo presented at Revision 2019 with Macau Exports

Atlas source code dump This is a dump of the source code for the engine, graphics tool and player for Atlas, our 64k demo released with Macau Exports

Monad 65 Jan 2, 2023