Ok so I've implemented pointers now, avoiding copying the array.
LevelMap.cpp:
#include "Tile.cpp"
#include "Bitmaps.h"
class LevelMap {
public:
const unsigned char *pTileTexture = floorTile;
Tile tiles[2] = {Tile(pTileTexture),Tile(pTileTexture)};
const unsigned char tileMap[2][8][16] = {
{ // Level 0:
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
},
{ // Level 1:
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
}
};
LevelMap(int a) {
}
Draw() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 16; j++) {
if (tileMap[0][i][j] > 0)
tiles[1].Draw(j * 8 * 256, i * 8 * 256);
}
}
}
};
Tile.cpp:
#pragma once
#include "Sprite.cpp"
#include "Bitmaps.h"
class Tile {
public:
Sprite sprite;
unsigned char *pTileTexture;
Tile(const unsigned char pTexture) {
pTileTexture = pTexture;
}
void Update() {
sprite.active = false;
sprite.Update(true);
}
void Draw(int posX, int posY) {
sprite.Draw(posX, posY, *pTileTexture);
}
};
The result is something very close to how the level should look, but is mangling the graphics. I'm not 100% sure if I'm using the pointers right, I haven't used them much before. I've attached an image of the screen.
