Another problem with this is I have seen that if any blocks change, it might not work. Also, the map is quite big, so updating these would probably not be efficient. Also, it seems that if I make the tiles get called from a class it slows down furthermore.
The Way I tried doing it was like this:
for (int i = 0; i < MapWidth; i++) {
for (int j = 0; j < MapHeight; j++) {
for (int k = 0; k < blocks.size(); k++) {
blocks.get(k).display((i*Width)+X, (j*Height)+Y, tile, extraMapData[i][j]);
//blocks.get(k).special((i*Width)+X, (j*Height)+Y, Width, Height, tile, extraMapData[i][j]);
}
}
}
class Block {
//Note: all hitbox related things are done in the Player class.
int id;
boolean cammo;
boolean solid;
PImage img;
PImage[] animatedLooks;
ArrayList<String> mods = new ArrayList<String>();
ArrayList<PImage> modimgs = new ArrayList<PImage>();
Block(PImage looks, int id) {
img = looks;
this.id = id;
}
Block(PImage[] looks, int id) {
animatedLooks = looks;
this.id = id;
}
Block(boolean invisible, int id) {
this.cammo = invisible;
this.id = id;
}
void display(int x, int y, int id, String mods) {
if (id == this.id) {
if (!cammo) {
if (img != null) {
image(img, x, y);
} else {
image(animateOffset(animatedLooks, x, y), x, y, BlockSize, BlockSize);
}
} else {
//grab neighboring block
}
} else {
for (int i = 0; i < blocks.size(); i++) {
if (blocks.get(i).getId() == id) {
blocks.get(i).display(x, y, id, mods);
}
}
}
}
void addMod(String str, PImage img) {
mods.add(str);
modimgs.add(img);
}
void setSolid(boolean s) {
solid = s;
}
int getId() {
return id;
}
}
blocks is an ArrayList of these block types. The array list is only as long as the number of block types in the game. Some reason this is way slower than directly for looping it and using an if statement, and then displaying it like this:
for (int i = 0; i < MapWidth; i++) {
for (int j = 0; j < MapHeight; j++) {
switch(tile) {
case 1:
image(grass, (i*Width)+X, (j*Height)+Y);
break;
....
}
}
I want to use the other method so its easier to add blocks to the game, but for some reason, it slows it down a lot.