diff options
Diffstat (limited to 'src/train.cpp')
| -rw-r--r-- | src/train.cpp | 32 | 
1 files changed, 28 insertions, 4 deletions
| diff --git a/src/train.cpp b/src/train.cpp index 98a493f..2604898 100644 --- a/src/train.cpp +++ b/src/train.cpp @@ -5,15 +5,29 @@  void Train::update(Level& level)  { -	auto tile = level.get(x, y); -	if (tile == 0) -		return; +	if (m_next) { +		m_speed = m_next->m_speed; +		m_progress = m_next->m_progress; +	} else { +		auto tile = level.get(x, y); +		if (tile == 0) +			return; +	}  	if (m_progress < 1.f) {  		m_progress += m_speed;  		return;  	} +	if (m_next) { +		x = m_nextX; +		y = m_nextY; +		m_nextX = m_next->x; +		m_nextY = m_next->y; +		m_progress = 0.f; +		findDirection(); +	} +  	setPosition(m_nextX, m_nextY);  } @@ -40,6 +54,16 @@ void Train::setPosition(int tx, int ty)  	findNextTile();  } +void Train::addVehicle(Train* newTrain) +{ +	if (!m_prev) { +		m_prev = newTrain; +		newTrain->m_next = this; +	} else { +		m_prev->addVehicle(newTrain); +	} +} +  void Train::findDirection()  {  	auto tile = m_level.get(x, y); @@ -81,4 +105,4 @@ void Train::findNextTile()  		m_nextX = x - 1;  		m_nextY = y;  	} -}
\ No newline at end of file +} | 
