GameObjects are stored in a Tilemap class, within a std::map<Vec2Int, GameObject>
container. The Vec2Int
struct describes the object's x and y coordinates. Each GameObject also contains a Vec2Int describing the same thing.
There are two things I would like to do (unless there is an entirely different/better way):
- The Tilemap should be able to traverse all GameObjects so that they may be drawn to the screen. The Tilemap uses a Camera class so that it can figure out which tiles/objects can be seen in the current camera view.
- However, GameObjects should be in control of their own position, not the Tilemap! The GameObject should be able to reposition itself by simply changing its x or y coordinates
For reference (I've only included the relevant stuff):
struct Vec2int {
int x, y;
};
class Tilemap {
public:
Tilemap(const int &w, const int &h);
void LoadLevel();
private:
//A 2D array of Tile pointers
std::vector<std::vector<Tile*>> _tileMap;
std::map<Vec2int, GameObject*> _objects;
};
class GameObject : public Tile {
public:
GameObject(const int &tileID, const Vec2int &position);
//virtual void Update() = 0;
private:
Vec2int _position;
};