aboutsummaryrefslogtreecommitdiffstats
path: root/include/components/health.hpp
blob: f0b8e6b3ecb6abe3705a6b12ba90537894c894e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef COMPONENTS_HEALTH_HPP_
#define COMPONENTS_HEALTH_HPP_

#include "base.hpp"

#include <SDL2/SDL_mixer.h>

/**
 * @struct Health
 * @brief Gives and entity health and stuff.
 */
struct Health : public Component {
	/**
	 * Constructor that sets the variables, with 1 health as default.
	 */
	Health(int m = 1, int h = 0)
		: health(h != 0 ? h : m), maxHealth(m) {}
	Health(XMLElement* imp, XMLElement* def) {
		fromXML(imp, def);
	}

	int health; /**< The current amount of health */
	int maxHealth; /**< The maximum amount of health */
	Mix_Chunk* ouch; /**< Sound made when attacked */

	void fromXML(XMLElement* imp, XMLElement* def) final {
		(void)imp;
		(void)def;
		// TODO
		if (def->QueryIntAttribute("value", &health) != XML_NO_ERROR)
			health = 1;
		maxHealth = health;
		auto o = def->Attribute("ouch");
		if (o != nullptr)
			ouch = Mix_LoadWAV(o);
		else
			ouch = nullptr;
	}
};


#endif // COMPONENTS_HEALTH_HPP_