Hello, I am making a video game for a class project and ran across a big problem! I will past the code below. Basically, I am adding bullets to an array to move them once they are fired. This is the section that fires the enemy bullets. I want the fire certain types every 1-3 seconds. I am using frameCount % == 60, 120, 180... etc to control this. The problem however is that once something is fired it adds 100's of bullets to the arrays(I saw this through println statements). I am using the code if(framecount% 60 == 0) print d to print out a clock incrementing every second. The clock prints out every second which means it is working. I am stumped! Please help!
void fireEnemyBullets() {
int xDir = 0;
int yDir = 1;
int xPos;
int yPos;
int bulletType;
if(frameCount % 60 == 0){
println(d);
d++;
}
for (int i = enemies.size() - 1; i >= 0; i--) {
Enemy enemy = (Enemy) enemies.get(i);
ArrayList turrents = enemy.getCurrentTurrentPostions();
for (int j = turrents.size() - 1; j >= 0; j-= 3) {
xPos = (Integer) turrents.get(j - 2);
yPos = (Integer) turrents.get(j - 1);
bulletType = (Integer) turrents.get(j);