incompatible operand types foat[] and int
in
Programming Questions
•
2 years ago
I know I need to find out how to write an if statement that says when a line hits the ellipse play a sound. I know the position of the ellipse is mouseX and mouseY and the dimentions are 50pixels by 20pixels, but i cant quite work out where each line is being drawn exactly and how to arrange it in an if statement? Please help I have been at it for hours and have gotten nowhere.
This is my code:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer song2;
AudioPlayer song3;
AudioPlayer song4;
float[] yCoord;
float[] speed;
float[] circles;
int space=6;
float size1=50;
int r=0;
int g=0;
int b=255;
void setup()
{
minim = new Minim(this);
song2 = minim.loadFile("noise1.aif");
song3 = minim.loadFile("nosie2.aif");
song4 = minim.loadFile("noise3.aif");
song5 = minim.loadFile("noise4.aif");
size (500,500);
smooth();
yCoord = new float [width/space+1];
speed = new float [width/space+1];
for(int i=0;i<yCoord.length;i=i+1) {
yCoord[i]=0;
speed[i]=random(6,8);
}
circles = new float [50+1];
for(int n=0;n<circles.length;n=n+1) {
circles[n]=random(10,50);
}
background(0);
fill(0,5);
rect(0,0,width,height);
stroke(56, 146,240);
strokeWeight(5);
}
void draw()
{
noCursor();
noStroke();
fill(200);
ellipse(mouseX,mouseY,50,20);
fill(0,10);
noStroke();
rect(0,0,width,height);
stroke(56, 146,240);
strokeWeight(5);
for(int i=0;i<yCoord.length;i=i+1) {
line(i*space,yCoord[i]-5,i*space,yCoord[i]);
yCoord[i]= yCoord[i] + speed[i];
if (yCoord[i]>500)
{
yCoord[i]=0;
}
}
void stop()
{
song2.close();
minim.stop();
super.stop();
}
This is my code:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer song2;
AudioPlayer song3;
AudioPlayer song4;
float[] yCoord;
float[] speed;
float[] circles;
int space=6;
float size1=50;
int r=0;
int g=0;
int b=255;
void setup()
{
minim = new Minim(this);
song2 = minim.loadFile("noise1.aif");
song3 = minim.loadFile("nosie2.aif");
song4 = minim.loadFile("noise3.aif");
song5 = minim.loadFile("noise4.aif");
size (500,500);
smooth();
yCoord = new float [width/space+1];
speed = new float [width/space+1];
for(int i=0;i<yCoord.length;i=i+1) {
yCoord[i]=0;
speed[i]=random(6,8);
}
circles = new float [50+1];
for(int n=0;n<circles.length;n=n+1) {
circles[n]=random(10,50);
}
background(0);
fill(0,5);
rect(0,0,width,height);
stroke(56, 146,240);
strokeWeight(5);
}
void draw()
{
noCursor();
noStroke();
fill(200);
ellipse(mouseX,mouseY,50,20);
fill(0,10);
noStroke();
rect(0,0,width,height);
stroke(56, 146,240);
strokeWeight(5);
for(int i=0;i<yCoord.length;i=i+1) {
line(i*space,yCoord[i]-5,i*space,yCoord[i]);
yCoord[i]= yCoord[i] + speed[i];
if (yCoord[i]>500)
{
yCoord[i]=0;
}
}
if (yCoord[i]==mouseX&&yCoord[i]==mouseY) //<<< I thought it should go something like this to start off with
{ song1.play();
}
}void stop()
{
song2.close();
minim.stop();
super.stop();
}
First it says that it cannot find anything called "i", then when I take away the [i] from each yCoord in the if statement it says incompatible operand types foat[] and int. How do I fix this?
1