Implementing Combat

Combat plays a large part in most games—so it’s worth the effort to develop a flexible system. You now have all of the elements required to implement combat. Monsters and the player have health, you know where they are, and you display the results. Let’s implement “bump to attack” melee combat.

Remove the Collision System

You need to start by removing the existing collision system. It served its purpose, but you need something more advanced to handle combat. Remove the file systems/collision.rs and all references to it and remove calls to the collision system in systems/mod.rs.

Indicating Intent to Attack

The WantsToMove component indicates that an entity intends to move into a tile. You can indicate that an entity wishes ...

Get Hands-on Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.