Limiting Monsters’ Fields of View
You can significantly improve game play by making the monsters chase the player only when they can see them. Doing so introduces new tactics—if you can break line of sight to the monster, it won’t follow you. It removes the certainty that if you “camp” long enough, you will defeat the level’s denizens. It also adds some uncertainty—the player isn’t given many clues as to what may reside beyond the next corner.
Fortunately, you’ve already done most of the hard work. Monsters have a FieldOfView component just like the player. By generically implementing the system, the game mechanic applies to any entity that has a FieldOfView component. You’ve also already learned how to use contains to see if a tile is visible ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access