0

I'm working on my Tower Defence game and right now I'm creating a wave of enemies. I wrote a method in class EnemyWave, that creates next wave. In my main class GameScreen, while starting new game I'm setting number of current wave to 0, which I need to use uptadeWave(), which creates new Wave in a game loop. I can't figure out why I get NullPointerException.

 public void run() {


    int frames = 0;

    loadGame();
    startGame("Level1");

    while (running) {

        repaint();
        frames++;

        waveUpdate();
        enemyUpdate();

        try {
            Thread.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Method which I have in run(), it gets errors in line with this.wave.waveNumber=0 (which should just set waveNumber to 0)

public void startGame(String level) {
    createPlayer();

    this.level = levelFile.getLevel(level);
    this.level.findSpawnPoint();
    this.map = this.level.map;

    this.wave.waveNumber = 0;

}

Method which is creating wave in game loop

 public void waveUpdate() {
    if (waveID == 0) {
        wave.nextWave();
        waveID++;
    }

}

Method which is beginning a next wave of my enemies.

 public void nextWave() {
    System.out.println("enemies are coming!!!");
    this.waveNumber++;
    this.enemiesThisRound = 0;
    this.waveSpawning = true;

//  System.out.println("Wave " + this.waveNumber + "spawning!");
    for (int i = 0; i < this.screen.enemyMap.length; i++) {
        this.screen.enemyMap[i] = null;
    }
}

This is my first question in StackOverflow so if I should place here more, please just tell me. :)

0 Answers0