-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from MylesScholz/Mitochondria
Mitochondria
- Loading branch information
Showing
9 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "mitochondria.hpp" | ||
|
||
using namespace godot; | ||
|
||
void Mitochondria::_bind_methods() { | ||
ClassDB::bind_method(D_METHOD("add_nutrients", "amount"), &Mitochondria::addNutrients); | ||
ClassDB::bind_method(D_METHOD("decrement_nutrients", "amount"), &Mitochondria::decrementNutrients); | ||
ClassDB::bind_method(D_METHOD("get_nutrients"), &Mitochondria::getNutrients); | ||
ClassDB::bind_method(D_METHOD("set_nutrients", "level"), &Mitochondria::setNutrients); | ||
ClassDB::add_property("Mitochondria", PropertyInfo(Variant::FLOAT, "nutrients"), | ||
"set_nutrients", "get_nutrients"); | ||
} | ||
|
||
Mitochondria::Mitochondria() { | ||
_nutrients = 26; | ||
_nutrient_maximum = 26; | ||
_nutrient_efficiency = 1; | ||
} | ||
Mitochondria::~Mitochondria() {} | ||
|
||
void Mitochondria::addNutrients(float nutrients) { | ||
nutrients *= _nutrient_efficiency; | ||
if (_nutrients + nutrients > _nutrient_maximum) | ||
nutrients = _nutrient_maximum; | ||
else | ||
_nutrients += nutrients; | ||
} | ||
|
||
void Mitochondria::decrementNutrients(const float decrement) { | ||
if (_nutrients - decrement > 0) | ||
_nutrients -= decrement; | ||
else if (_nutrients - decrement <= 0) | ||
_nutrients = 0; | ||
} | ||
|
||
float Mitochondria::getNutrients() const { return _nutrients; } | ||
|
||
void Mitochondria::setNutrients(const float level) { | ||
_nutrients = level; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <godot_cpp/classes/node.hpp> | ||
|
||
namespace godot { | ||
|
||
class Mitochondria : public Node { | ||
GDCLASS(Mitochondria, Node); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
public: | ||
Mitochondria(); | ||
~Mitochondria(); | ||
|
||
void addNutrients(float); | ||
void decrementNutrients(const float); | ||
float getNutrients() const; | ||
void setNutrients(const float); | ||
|
||
private: | ||
float _nutrients; | ||
float _nutrient_maximum; | ||
float _nutrient_efficiency; | ||
}; | ||
|
||
}; // namespace godot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters