Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Game Progression if statement
    primarykey
    data
    text
    <p>My game is wave based. The wave is completed by eliminating x amount of bad guys; x increasing every wave. </p> <p>I've got a simple if statement that checks if the wave is completed:</p> <pre><code>if(numberOfVanishedEnemies == numberOfEnemiesOfWave) { // Wave completed } </code></pre> <p>With one enemy on the screen, one can use a simple if statement to check if a new enemy should be created:</p> <pre><code>if(numberOfVanishedEnemies &lt; numberOfEnemiesOfWave) { // Create new enemy } </code></pre> <p>Yet the number of badGuys visible on the screen increases every wave. Currently I'm trying to create an if statement that checks if a new enemy should be created, yet I don't want to create more than needed eg. have 2 enemies on the screen if only one is needed to eliminate to clock the wave.</p> <p>Could someone provide me with a if statement that could do this. </p> <p>The variables that I've created are: - numberOfWaveEnemies - numberOfVanishedEnemies - numberOfVisibleEnemies</p> <p>(Are those enough to solve the problem?)</p> <p>Here is the code I've got so far (as requested):</p> <pre><code>public void updateWave() { for(int i = 0; i &lt; this.amountOfLevelVisibleStupidBadDroids; i++) { if(holderStupidBadDroids[i] != null) { game.getGameLog().d(classTAG, "Number of STBD: " + this.amountOfGeneratedStupidBadDroids); // Check if a StupidBadDroid collided with the player if(holderStupidBadDroids[i].isDead) { this.amountOfVanishedStupidBadDroids += 1; if(this.amountOfGeneratedStupidBadDroids &lt; this.amountOfLevelStupidBadDroids) { game.getGameLog().d(classTAG, "GENERATING NEW STUPIDBADDROID"); generateNewStupidBadDroid(i); this.amountOfGeneratedStupidBadDroids += 1; } else { // Keep the StupidBadDroid dead and don't re-spawn a new one game.getGameLog().d(classTAG, "DISPOSING CURRENT STUPIDBADDROID"); holderStupidBadDroids[i] = null; } } // Check if a StupidBadDroid has traveled off the visible screen else if(holderStupidBadDroids[i].getY() &gt; game.getWSScreen().getGameScreenHeight()) { //this.amountOfVanishedStupidBadDroids - 1 + this.amountOfLevelVisibleStupidBadDroids &lt; this.amountOfLevelStupidBadDroids if(this.amountOfGeneratedStupidBadDroids &lt; this.amountOfLevelStupidBadDroids) { game.getGameLog().d(classTAG, "GENERATING NEW STUPIDBADDROID"); holderStupidBadDroids[i].setY(0 - Assets.StupidBadDroid.getHeight()); //generateNewStupidBadDroid(i); } else { // Keep the StupidBadDroid dead and don't respawn a new one game.getGameLog().d(classTAG, "DISPOSING CURRENT STUPIDBADDROID"); holderStupidBadDroids[i] = null; } } } } for(int i = 0; i &lt; this.amountOfLevelVisiblePlayerDroids; i++) { if(holderPlayerDroid[i].isDead) { gameOver = true; begineOfGameOver = System.currentTimeMillis(); } } } </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload