trouble with arrays for my paddle game
in
Programming Questions
•
2 years ago
so i'm making a game and i want to bounce 3 balls off a paddle. I just, somewhat, learned how to use Arrays but i keep getting error messages. If anyone could help me out with this I would really appreciate it!
float[] circle=new float[3];
float[] circX=new float[3];
float[] circY=new float[3];
float[] vy=new float[3];
float[] vx=new float[3];
int w=500;
float d=40;
void setup()
{
for(int i=0;i<3;i++){
circX[i]=random(d/2,w-d/2);
circY[i]=random(d/2,w-d/2);
vx[i]=random(5,10);
vy[i]=random(5,10);
fill(255);
}
size(w,w);
}
//float circX=200;
//float circY=100;
//float velocityX=5;
//float velocityY=0;
int hit=0;
int miss=0;
void draw()
{
if(mousePressed)
{
hit=0; miss=0;
}
float paddle=1000/(miss+10);
if(miss>10){
text("GAME OVER:");
}
if(circX[i]<0 || circX[i]>width) velocityX=-velocityX;
if(circY[i]>height)
{
velocityY=-velocityY;
float distance = abs(mouseX-circX[i]);
if(distance<paddle) hit +=1;
else miss= miss+1;
}
else velocityY = velocityY+ 1;
circX[i]=circX[i]+velocityX;
circY[i]=circY[i]+velocityY;
background(100,100,100);
fill(100,200,50);
ellipse(circX[i],circY[i],50,50);
fill(255);
rect(mouseX-paddle,height-10,2*paddle,20);
fill(0);
text("hit:" + hit,10,20);
text("miss:" + miss,10,40);
}
1