From d198dd25af201aaacc7782f4bd36d2cfa5f0c05b Mon Sep 17 00:00:00 2001 From: cflip Date: Thu, 3 Mar 2022 20:30:10 -0700 Subject: 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. --- src/level.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/level.cpp') 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) -- cgit v1.2.3