"Cannot find anything named 'i'" (A "fix my code" question)
in
Programming Questions
•
11 months ago
Hello everyone! I'm new to Processing, and for my Intro to Comp Sci class, we are making an interactive asteroid game. The problem is that whenever I try to run the program, it says it can't find anything named "i," even though I've attempted to define it in the past. Anyway, here's the code as it is right now. Do you guys know what's wrong with it? Much appreciated!
Asteroid[] obstacles;
int numAsteroids = 10;
void setup() {
size(600,600);
smooth();
obstacles = new Asteroid[numAsteroids];
for (int i = 0; i<obstacles.length; i++) {
obstacles[i] = new Asteroid();
}
}
void draw() {
background(0);
obstacles[i].draw();
obstables[i].stepAnimation();
}
class Asteroid {
float x, y, xSpeed, ySpeed;
int maxSpeed = 3;
float size;
Asteroid() {
initialze();
}
void initalize() {
//pick the size
size=(int)random(5,50);
x = random(0,width);
y = random(0,height);
xSpeed = random(-maxSpeed, maxSpeed);
ySpeed = random(-maxSpeed, maxSpeed);
//generate the asperoid along the edge
int edge = (int) random(0,4);
switch(edge) {
//left edge
case 0:
x = -size/2;
y = random(0,height);
xSpeed = abs(xSpeed); //make xSpeed postitive
break;
//top edge
case 1:
y = -size/2;
ySpeed = abs(ySpeed);//make positive
break;
//right edge
case 2:
x = width + size/2;
xSpeed = -abs(xSpeed); //make negative
break;
//bottom edge
case 3:
y = height + size/2;
ySpeed = -abs(ySpeed); //make negative
}
}
void draw() {
ellipse(x,y,size,size);
}
void stepAnimation() {
x += xSpeed;
y += ySpeed;
//check for asteroid being off screen
if (x > width+size/2 || x<-size/2 || y > height+size/2 || y<-size/2) {
intialize();
}
}
}
1