blob: 8e462a9b139b330c5008ab01b5b3a492a5bb008e (
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
|
#ifndef COMPONENTS_PHYSICS_HPP_
#define COMPONENTS_PHYSICS_HPP_
#include "base.hpp"
/**
* @struct Physics
* @brief Allows and entity to react to gravity and frictions.
* When an entity inherits this component it will react with gravity and move with friction.
*/
struct Physics : public Component {
/**
* Constructor that sets the gravity constant, if not specified it becomes 0.
* @param g The non default gravity constant.
*/
Physics(float g = 0.2f): g(g) {}
Physics(XMLElement* imp, XMLElement* def) {
fromXML(imp, def);
}
float g; /**< The gravity constant, how fast the object falls */
void fromXML(XMLElement* imp, XMLElement* def) final {
if (imp->QueryFloatAttribute("gravity", &g) != XML_NO_ERROR) {
if (def->QueryFloatAttribute("value", &g) != XML_NO_ERROR)
g = 0.2f;
}
}
};
#endif // COMPONENTS_PHYSICS_HPP_
|