Difference between revisions of "Complete roguelike tutorial using C++ and libtcod - part 8: items and inventory"

From RogueBasin
Jump to navigation Jump to search
(pasted →‎top: , cat and sidebar)
 
Line 8: Line 8:


[http://roguecentral.org/doryen/data/libtcod/doc/1.5.2/html2/console_blocking_input.html?c=false&cpp=true&cs=true&py=false&lua=true TCODSystem::waitForEvent]
[http://roguecentral.org/doryen/data/libtcod/doc/1.5.2/html2/console_blocking_input.html?c=false&cpp=true&cs=true&py=false&lua=true TCODSystem::waitForEvent]
==Actors that can be healed==
For the health potion to work, we first need to be able to heal a Destructible. Let's add this.
Destructible.hpp :
float heal(float amount);
Destructible.cpp :
float Destructible::heal(float amount) {
    hp += amount;
    if ( hp > maxHp ) {
        amount -= hp-maxHp;
        hp=maxHp;
    }
    return amount;
}
The function returns the amount of health point actually restored.




[[Category:Developing]]
[[Category:Developing]]

Revision as of 15:48, 15 October 2015

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.


In this article, we will start to add items to the dungeon, in the form of health potions. This will make it possible to kill every monster in the dungeon for the first time, even if the engine won't yet detect the end of game.

libtcod functions used in this article :

TCODConsole::printFrame

TCODSystem::waitForEvent

Actors that can be healed

For the health potion to work, we first need to be able to heal a Destructible. Let's add this. Destructible.hpp :

float heal(float amount);

Destructible.cpp :

float Destructible::heal(float amount) {
   hp += amount;
   if ( hp > maxHp ) {
       amount -= hp-maxHp;
       hp=maxHp;
   }
   return amount;
}

The function returns the amount of health point actually restored.