Hello!
I am trying to have a game where you shoot falling balls with a laser. I used an array to make the balls fall, so when I shoot one of the multiple balls they all reset. How do I make it so that you have to shoot all the balls that fall, not just one of them?
I tried making the variable count to add on to itself when it comes in contact with a ball, and then if its equal to the number of balls the array makes (exp) to reset
This is what I have so far, my teacher also says we’re not allowed to use objects, classes, and other things like that so please let me know a way to do this without using those. Thank you!
int y ;
int ballx=mouseX;
int bally=mouseY;
int mx = mouseX;
int my=400;
int [] num=new int [4];
int []numx=new int[4];
int rand =int(random(-2,7));
float xball=400;
float yball=400;
boolean win =false;
int exp = int(random(3,6));
float count = 0;
void setup(){
size(600,600);
}
void draw(){
xball=constrain(xball,0,600);
yball=constrain(yball,400,600);
background(255);
line(0,400,600,400);
if(y<400)
y=400;
ellipse(xball,yball,40,40);
ellipse(xball,my,20,20);
my-=10;
exp = int(random(1,5));
for ( int i=0; i<num.length; i++)
{
fill(int(random(255)),int(random(255)),int(random(255)));
for( int j =0; j<numx.length;j++)
{
ellipse(numx[j],num[i], 40, 40);
num[i]+=rand;
rand =int(random(1,3));
ellipse(xball,yball, 20, 20);
if (num[i]>=height)
{
for(i=0;i<num.length; i++)
{
num=expand(num, exp);
numx=expand(num,exp);
num[i]=-50;
}
for ( j=0; j<numx.length; j++)
{
numx[j]=int(random(height));
}
}
else if(dist(xball,my,numx[j],num[i])<=30)
{
count+=0.2;
//println(count);
if(count>=exp)
{
win=true;
println(count);
count=0;
}
if(win==true)
{
for(i=0;i<num.length; i++)
{
num=expand(num, exp);
numx=expand(num,exp);
num[i]=-50;
}
for ( j=0; j<numx.length; j++)
{
numx[j]=int(random(height));
}
}
win=true;
}
}
}
if(keyPressed)
{
if (key ==CODED)
{
if (keyCode==LEFT)
xball-=10;
else if (keyCode == RIGHT)
xball+=10;
else if (keyCode ==UP)
yball-= 10;
else if (keyCode ==DOWN)
yball+=10;
}
}
}
void mouseReleased(){
my=400;
}