summaryrefslogtreecommitdiff
path: root/src/level.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-03-03 20:30:10 -0700
committercflip <cflip@cflip.net>2022-03-03 20:30:10 -0700
commitd198dd25af201aaacc7782f4bd36d2cfa5f0c05b (patch)
tree541fec3336c5090d8be8390ddae8fb47002df3b1 /src/level.cpp
parent4ccfcb2c394b1e2b9e0e521c713444c952b91edf (diff)
Keep list of all vehicles in Level class
Newly created vehicles are now to be added to the Level, which automatically updates and renders them. This infrastructure will be needed for depth sorting and eventually level saving.
Diffstat (limited to 'src/level.cpp')
-rw-r--r--src/level.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/level.cpp b/src/level.cpp
index 54cf7f0..92ec208 100644
--- a/src/level.cpp
+++ b/src/level.cpp
@@ -1,4 +1,5 @@
#include "level.h"
+#include "train.h"
#include "util.h"
Level::Level(int width, int height, Bitmap& tileSprites)
@@ -23,6 +24,13 @@ void Level::set(int x, int y, uint8_t tile)
m_tiles[x + y * m_width] = tile;
}
+void Level::update()
+{
+ for (Train* vehicle : m_vehicles) {
+ if (vehicle) vehicle->update();
+ }
+}
+
void Level::draw(Bitmap& bitmap, int xo, int yo)
{
for (int y = 0; y < 32; ++y) {
@@ -58,6 +66,15 @@ void Level::draw(Bitmap& bitmap, int xo, int yo)
bitmap.blit(m_tileSprites, xx, yy, tx * TileSize, ty * TileSize, TileSize, TileSize);
}
}
+
+ for (Train* vehicle : m_vehicles) {
+ if (vehicle) vehicle->draw(bitmap, xo, yo);
+ }
+}
+
+void Level::addVehicle(Train& vehicle)
+{
+ m_vehicles.emplace_back(&vehicle);
}
void Level::toggleTile(int x, int y)