This is probably a really stupid question but I am having trouble showing more that one copy of my class on the screen. I have created an asteroid class that generates and moves an asteroid on the screen. Yet when I try and call multiple versions of this class in my main body, it still only shows one asteroid.
Main
int lrgAsteroids = 4;
Asteroid[] asteroid = new Asteroid[lrgAsteroids];
void setup() {
size(800,800);
for (int i = 0; i < lrgAsteroids; i++) {
asteroid[i] = new Asteroid();
asteroid[i].display();
}
}
void draw() {
background(0);
asteroid[0].move();
asteroid[1].move();
for (int i = 0; i < lrgAsteroids; i++) {
asteroid[i].move();
}
}
asteroid class.
class Asteroid {
PImage lrgAsteroid;
float xpos, ypos;
float yDirection;
float xDirection;
float radians = 0;
Asteroid() {
lrgAsteroid = loadImage("largeAsteroid.png");
xpos = random(0,710);
ypos = random(0,710);
int xDir = (int) random(2);
int yDir = (int) random(2);
if (xDir == 1) {
xDirection = 1;
} else if (xDir == 0) {
xDirection = -1;
}
if (yDir == 1) {
yDirection = 1;
} else if (yDir == 0) {
yDirection = -1;
}
}
void display() {
image(lrgAsteroid, xpos, ypos);
}
void move() {
background(0);
pushMatrix();
imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, 0, 0);
popMatrix();
if (xpos <= 0) {
xpos = random(750,800);
} else if (xpos >= 800) {
xpos = random(0,100);
}
if (ypos <= 0) {
ypos = random(750,800);
} else if (ypos >= 800) {
ypos = random(0,100);
}
radians += 0.02;
xpos += xDirection;
ypos += yDirection;
}
}
Any help would be greatly appreciated.