So basically what I'm trying to do is have a boss spawn (ever 10 levels) and have every other enemy currently on screen removed. All object are in a linkedlist and extend GameObject.
In GameObject I have removed as a boolean and:
public GameObject(float x, float y, ID id) {
this.x = x;
this.y = y;
this.removed = removed;
this.id = id;
}
Going off another suggestion from a previous thread, in the handler I have:
for (int i = 0; i < object.size(); i++) {
if (object.get(i).removed == true)
object.remove(i);
}
The way I'm checking the level and removing the enemy is (basic enemy line 41) This is in the basic enemies class:
if(hud.level % 10 == 0) {
this.removed = true;
}
Every time I run the code and an enemy spawns in it throws a nullPointerException at line 41 of basic enemy. Full error is:
Exception in thread "Thread-0" java.lang.NullPointerException
at BasicEnemy.tick(BasicEnemy.java:41)
at Handler.tick(Handler.java:13)
at Game.tick(Game.java:92)
at Game.run(Game.java:73)
at java.base/java.lang.Thread.run(Thread.java:844)
The int level is public and set to 1 at the start
I'm not very good with LinkedLists so this is pretty confusing atm.
edit
hud.level is
public int level = 1;
HUD is the class which keeps track of overlays, current level, and score the code for increasing score and level is:
public void tick() {
HEALTH = Game.clamp(HEALTH, 0, 100);
greenValue = Game.clamp(greenValue, 0, 255);
greenValue = HEALTH * 2;
score++;
}
Level:
public void tick() {
scoreKeep ++;
if(scoreKeep >= 100) {
scoreKeep = 0;
hud.setLevel(hud.getLevel() + 1);