diff --git a/cell.tscn b/cell.tscn index 60d49c8..721eae0 100644 --- a/cell.tscn +++ b/cell.tscn @@ -26,5 +26,4 @@ debug_color = Color(0, 0.6, 0.701961, 0.419608) [node name="CellState" type="CellState" parent="."] lifespan = 20.0 -[node name="Mitochondria" type="Mitochondria" parent="."] -lifespan = 20.0 +[node name="Mitochondria" type="Mitochondria" parent="CellState"] diff --git a/src/cell.cpp b/src/cell.cpp index cc972c0..d86ae17 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -45,7 +45,6 @@ Size2 Cell::getSpriteSize() const { return _spriteSize; } void Cell::_ready() { _cellState = this->get_node("CellState"); - _mitochondria = this->get_node("Mitochondria"); } void Cell::_process(double delta) { @@ -58,10 +57,10 @@ void Cell::_process(double delta) { // Increment the Cell's age and decrement nutrients _cellState->incrementAge(delta); - _mitochondria->decrementNutrients(delta); + _cellState->getMitochondria()->decrementNutrients(delta); // Aging, starvation and death - float nutrients = _mitochondria->getNutrients(); + float nutrients = _cellState->getMitochondria()->getNutrients(); float ageDiff = _cellState->getAge() - _cellState->getLifespan(); if (ageDiff > 0) { // The Cell's age exceeds its lifespan diff --git a/src/cell.hpp b/src/cell.hpp index 26f4a1e..ab5b20e 100644 --- a/src/cell.hpp +++ b/src/cell.hpp @@ -31,7 +31,6 @@ class Cell : public RigidBody2D { private: CellState *_cellState; - Mitochondria *_mitochondria; Size2 _spriteSize; Ref rand; }; diff --git a/src/cell_state.cpp b/src/cell_state.cpp index 8b1f3f6..fb87f02 100644 --- a/src/cell_state.cpp +++ b/src/cell_state.cpp @@ -18,6 +18,9 @@ CellState::CellState() { } CellState::~CellState() {} +void CellState::setMitochondria(Mitochondria *mitochondria) { _mitochondria = mitochondria; } +Mitochondria *CellState::getMitochondria() { return _mitochondria; } + void CellState::setAlive(const bool alive) { _alive = alive; } bool CellState::getAlive() const { return _alive; } @@ -44,4 +47,8 @@ void CellState::applyScale(const float scale) { if (scale <= 0) _scale *= scale; } -float CellState::getScale() const { return _scale; } \ No newline at end of file +float CellState::getScale() const { return _scale; } + +void CellState::_ready() { + _mitochondria = this->get_node("Mitochondria"); +} \ No newline at end of file diff --git a/src/cell_state.hpp b/src/cell_state.hpp index c9e39a2..95367b5 100644 --- a/src/cell_state.hpp +++ b/src/cell_state.hpp @@ -1,5 +1,6 @@ #pragma once +#include "mitochondria.hpp" #include namespace godot { @@ -14,6 +15,9 @@ class CellState : public Node { CellState(); ~CellState(); + void setMitochondria(Mitochondria *); + Mitochondria *getMitochondria(); + void setAlive(const bool); bool getAlive() const; @@ -28,7 +32,10 @@ class CellState : public Node { void applyScale(const float); float getScale() const; + void _ready() override; + private: + Mitochondria *_mitochondria; bool _alive; float _age; float _lifespan;