I'm trying to make a space invaders type program. So I have an array of bullets from the ship and an array of enemies. I have a boolean function in the Bullet class, but I'm not sure how to test it against all of the other enemies. Sorry if this seems confusing. Here's my code. (O line 63, where i wrote "
HERE IS WHERE I NEED HELP!!" is where i think i need help. haha)
Timer timer;
Bullet[] bullets;
int xBullet, yBullet;
int r;
int totalBullets = 0;
Enemy[] enemies;
int totalEnemies = 0;
void setup() {
size(600, 600);
smooth();
background(0);
enemies = new Enemy[1000];
bullets = new Bullet[5000];
timer = new Timer(300); // Create a timer that goes off every 2 seconds
timer.start(); // Starting the timer
}
void draw() {
if (frameCount == 10) {
// delay(1000);
}
fill(0, 10);
rect(0, 0, 600, 600);
//ENEMIES
// Check the timer
if (timer.isFinished()) {
// Deal with enemies
// Initialize one enemy
enemies[totalEnemies] = new Enemy();
// Increment totalEnemies
totalEnemies ++ ;
// If we hit the end of the array
if (totalEnemies >= enemies.length) {
totalEnemies = 0; // Start over
}
timer.start();
}
// Move and display all enemies
for (int i = 0; i < totalEnemies; i++ ) {
enemies[i].move();
enemies[i].display();
}
//BULLETS
bullets[totalBullets] = new Bullet();
if (totalBullets >= bullets.length) {
totalBullets = 0;
}
for (int i = 0; i <= totalBullets; i++) {
bullets[i].shoot();
bullets[i].display();
println("here");
if (bullets[i].hit(enemies[HERE IS WHERE I NEED HELP!!])) {