I have my arrays set like this in my main area:
Wall[] walls = new Wall[100];
Gate[] gates = new Gate[100];
Player1[] player = new Player1[100];
Goal[] goals = new Goal[100];
Key[] keys = new Key[100];
Enemy[] enemies = new Enemy[100];
Level[] levels = new Level[100];
The levels array creates an error.
Once I have my arbitrary blank array of levels i can then say levels[0].append(walls[0]);
Or loop through a specific number of walls like
for (int i = 0; i <= 4; i ++){
levels[0].append(walls[i]);
}
and do that for every set of walls, players, gates, and everything for levels[0], then levels[1], until I’m done with everything, then I have all my levels set in a neat array.
I completely forgot about the implements ArrayList thing… I can just append every element corresponding to particular levels into objects levels[i]…
My level class has a mistake or two cuz there’s different arraylists at beginning which I don’t need.
class Level{
ArrayList<Wall> walls;
ArrayList<Key> keys;
ArrayList<Goal> goals;
ArrayList<GameElement> elements = new ArrayList<GameElement>();
Level() {
walls = new ArrayList<Wall>();
//gates = new ArrayList<Gate>();
keys = new ArrayList<Key>();
goals = new ArrayList<Goal>();
}
void draw() {
for (int i = 0; i < walls.size(); i++) { // normal for loop
walls.get(i).draw(); // use .get() on ArrayLists
}
for (Key k : keys) { // for each loop, effectively the same as above but a little quicker to write once you understand how it works
k.draw(); // k is equal to the current key so no need for .get()
}
// loop through doors also
}
}
// In your main program store all the levels in another ArrayList and just key a variable to say what level you're on
ArrayList<Level> levels = new ArrayList<Level>();
int currentLevel = 1;
// You can start creating level in setup by doing something like this
// so on and so forth
// then add level to levels ArrayList and repeat
I think the constructor confuses me, shouldn’t there be an object of some kind in the constructor so when I implement the specific level objects and append an element, the level class knows where to put the element?