Skip to content

Commit

Permalink
Moved Mitochondria to be child of CellState
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesScholz committed Jan 31, 2024
1 parent 6ad46c0 commit 8535c08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
3 changes: 1 addition & 2 deletions cell.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 2 additions & 3 deletions src/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Size2 Cell::getSpriteSize() const { return _spriteSize; }

void Cell::_ready() {
_cellState = this->get_node<CellState>("CellState");
_mitochondria = this->get_node<Mitochondria>("Mitochondria");
}

void Cell::_process(double delta) {
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Cell : public RigidBody2D {

private:
CellState *_cellState;
Mitochondria *_mitochondria;
Size2 _spriteSize;
Ref<RandomNumberGenerator> rand;
};
Expand Down
9 changes: 8 additions & 1 deletion src/cell_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -44,4 +47,8 @@ void CellState::applyScale(const float scale) {
if (scale <= 0)
_scale *= scale;
}
float CellState::getScale() const { return _scale; }
float CellState::getScale() const { return _scale; }

void CellState::_ready() {
_mitochondria = this->get_node<Mitochondria>("Mitochondria");
}
7 changes: 7 additions & 0 deletions src/cell_state.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "mitochondria.hpp"
#include <godot_cpp/classes/node.hpp>

namespace godot {
Expand All @@ -14,6 +15,9 @@ class CellState : public Node {
CellState();
~CellState();

void setMitochondria(Mitochondria *);
Mitochondria *getMitochondria();

void setAlive(const bool);
bool getAlive() const;

Expand All @@ -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;
Expand Down

0 comments on commit 8535c08

Please sign in to comment.