Hello @PaddedMellie ,
Please read:
Guidelines—Asking Questions
It is not necessary to post your entire code.
I suggest that you introduce a state variable to manage state changes:
- Create a global variable called state:
boolean state = true; // Initial value
- Isolate the code that makes the ships and make a function called
make()
You can then call this once in setup or as required later. - When there is a state change such as level increasing call the function set
state = true;
which can then be used to callmake()
. - If you are calling make() in draw you only want to do it once and then set
state = false;
after so it is not called multiple times for everydraw()
cycle..
Code added to draw()
:
boolean state = true;
void draw(){
background(0, 0, 0);
if (state)
{
println(level, state);
switch(level)
{
case 0:
break;
case 1:
shipCount = 1;
make(shipCount);
break;
case 2:
shipCount = 3;
make(shipCount);
break;
case 3:
shipCount = 5;
make(shipCount);
break;
}
state = false;
println(level, state);
}
switch(level)
{
// Your original code here
}
}
// makes ships
void make(int _noOfShips)
{
s = new Spaceships[_noOfShips];
// Your code
}
The above worked for me and was from experience.
There are other changes to make and you can work these out.
Make liberal use of println()
to see what is (or is not) going on at different points in your code.
Use the tools available to you to debug… right click on a variable and Show usage… was useful for me to peruse your code.
At some point consider reworking your code.
The example I provided was patched in… you may be able to integrate this with other code or find a better solution.
See:
Have fun!
:)