Hello Processing!
Ive been having a wee bit of trouble with my code.
Currently i have Balls falling down, and when my mouse hovers over them they disappear, and more balls spawn and keep falling down.
Now instead of them falling down from the top of the screen, i have decided to make then pop up/out, in different/random areas on screen, also making the balls not overlap each other (which is whats happening now as the balls fall from the top of the screen)....
Here is my code now, i just cant figure out how to get the balls to spawn randomly on screen rather than falling down.
Thanks alot
(this code was a mixture of my own code and a little of from blindfish's code from an earlier post)
//creating an array of Spot objects
Spot foo[] = new Spot[20];
int tRadius = 50;
boolean colFlag = false;
void setup(){
size(640,480);
for(int i=0; i<foo.length; i++){
foo[i] = new Spot((int)random(640), (-1)*tRadius, tRadius);
}
}
//this is my collision detection
boolean collisionD(int uX, int uY, int uW, int uH, int bX, int bY, int bW, int bH){
boolean col=false;
if(uX+uW/2 > bX-bW/2 && uX-uW/2 < bX+bW/2 && uY+uH/2 > bY-bH/2 && uY-uH/2 < bY+bH/2){
col = true;
}
return col;
}
void draw(){
background(50);
//draw mouse circle
ellipse(mouseX,mouseY,30,30);
for(int i=0;i<foo.length;i++) {
colFlag = collisionD(mouseX,mouseY,30,30,foo[i].getX(),foo[i].getY(),tRadius,tRadius);
if(colFlag==true || foo[i].getY() > 480){
foo[i].setX((int)random(640));
foo[i].setY((-1)*tRadius);
}else{
foo[i].setY(foo[i].getY()+1);
foo[i].display();
}
}
}
//our Spot class, this is a Spot object. Think of it as an actual spot with the properties X,Y,Radius(spotX,spotY,spotRadius)
class Spot {
int spotX, spotY, spotRadius;
//constructor it takes X, Y and Radius. This gets called when you write Spot whatever = new Spot(50,50,50);
Spot(int theX, int theY, int theRadius){
spotX = theX;
spotY = theY;
spotRadius = theRadius;
}
//sets the X value of the spot object
void setX(int newX){
spotX = newX;
}
//" y value
void setY(int newY){
spotY = newY;
}
//get the x value of the spot object
int getX(){
return spotX;
}
//" y value
int getY(){
return spotY;
}
//display the spot object
void display(){
ellipse(spotX,spotY,spotRadius,spotRadius);
}
void destroy(){
spotX = 0;
spotY = 0;
spotRadius=0;
}
}
//again Thanks alot