summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp1
-rw-r--r--src/train.cpp3
-rw-r--r--src/train.h4
3 files changed, 6 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 436660c..28b2281 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -54,6 +54,7 @@ int main(int argc, char** argv)
int my = y / Scale + yOffs;
auto pos = ScreenToTile({ mx, my });
engine.setPosition(pos.x, pos.y);
+ engine.setSpeed(0.2f);
}
});
diff --git a/src/train.cpp b/src/train.cpp
index 7ce1c2d..d3ea7fb 100644
--- a/src/train.cpp
+++ b/src/train.cpp
@@ -14,6 +14,7 @@ void Train::update()
return;
}
+ m_speed *= m_acceleration;
if (m_progress < 1.f) {
m_progress += m_speed;
return;
@@ -48,8 +49,8 @@ void Train::setPosition(int tx, int ty)
{
x = tx;
y = ty;
-
m_progress = 0.f;
+
findDirection();
findNextTile();
}
diff --git a/src/train.h b/src/train.h
index 3cd23e4..178583f 100644
--- a/src/train.h
+++ b/src/train.h
@@ -14,6 +14,7 @@ public:
void draw(Bitmap&, int, int);
void setPosition(int x, int y);
+ void setSpeed(float speed) { m_speed = speed; };
// Add a vehicle to the end of this train
void addVehicle(Train*);
@@ -28,7 +29,8 @@ private:
Level& m_level;
int x { 0 }, y { 0 };
- float m_speed { 0.05f };
+ float m_speed { 0.f };
+ float m_acceleration { 0.98f };
float m_progress { 0.f };
Direction m_dir { North };