Complete roguelike tutorial using C++ and libtcod - extra 5: more generic items
Jump to navigation
Jump to search
Complete roguelike tutorial using C++ and libtcod -originally written by Jice Text in this tutorial was released under the Creative Commons Attribution-ShareAlike 3.0 Unported and the GNU Free Documentation License (unversioned, with no invariant sections, front-cover texts, or back-cover texts) on 2015-09-21. |
---|
|
This article is an optional "extra" that implements more generic items, making it possible to create new items with less code. It can be applied on article 9 source code.
In article 9, we brought more variety to the items, but each new item required a new class inheriting from Pickable. Yet, we can see some pattern in the way pickable actors behave :
They all select one or several targets :
- the wearer of the item (health potion)
- the wearer's closest enemy (lightning bolt)
- a selected actor (confusion)
- all actors close to a selected tile (fireball)
A fifth way that is not yet used but might be useful would be :
- all actors close to the wearer of the item
They all apply some effect to the selected targets :
- increase or decrease health (all but confusion)
- temporary replace the target's Ai (confusion)
So instead of implementing the target selection and the effect in a class inheriting from Pickable, why not add a TargetSelector and an Effect directly to the Pickable class ?