Hello I have a little mini project and i need help concerning making once object go from one object into another. I have two scripts here. The first is the file i will be submitting for my project and its a box shooting and once it detects the circles, the circles disappear. Once the circle is disappeared i would want this explosion to happen but i don't know how to go about that. Here is the first script.
float px, py;
float vx, vy;
float minX, maxX;
ArrayList bullets;
int cols= 1;
int rows =2;
int cols_select;
int rows_select;
Alien[][] aliens = new Alien[cols][rows];
int deadAliens=0;
int lastGuy=0;
void setup(){
size( 600, 600, P3D );
bullets = new ArrayList();
minX = 150;
maxX = 450;
vx = 2;
vy = 2;
px = minX; // position px in minX at the start
py = 100 ; // posiiton py in the middle of the sketch
for (int i=0; i< cols; i++){
for (int j=0; j<rows; j++){
aliens[i][j] = new Alien(100, 300, 300, 360, i*100, j*150, 200,1);
}
}
fill(0,200,0,100);
}
void draw(){
background(255);
for (int i=0; i< cols; i++){
for(int j=0; j<rows; j++){
aliens[i][j].display();
aliens[i][j].move();
aliens[i][j].shift();
aliens[i][j].exitStageLeft();
}
}
for (int i=0; i < bullets.size(); i++) {
Bullet b = (Bullet) bullets.get(i);
b.display();
b.fire();
if(b.finished()){
bullets.remove(b);
}
for (int k=0; k< cols; k++){
for(int j=0; j<rows; j++){
if(b.intersect(aliens[k][j])){
bullets.remove(b);
aliens[k][j].destroyed();
deadAliens=deadAliens+1;
}
}
}
}
// Move box to x,y,z
pushMatrix();
fill(0,200,0,100);
rect(250,550,20,20);
popMatrix();
//Draw a box with size 50
}
class Alien {
color h;
color s;
color b;
float a;
float xpos;
float true_xpos;
float true_ypos;
float ypos;
float zpos;
float xspeed;
float d;
float r;
boolean imaDeadAlien=false;
Alien(color h_, color s_, color b_, float a_, float xpos_, float ypos_, float zpos_, float xspeed_){
h= h_;
s= s_;
b= b_;
a=a_;
xpos = xpos_;
ypos = ypos_;
zpos = zpos_;
xspeed = xspeed_;
}
void display(){
noStroke();
fill(h,s,b,a);
r=40;
true_xpos=xpos+200;
true_ypos=ypos+100;
ellipse(true_xpos, true_ypos, 55,40);
}
void move() {
xpos = xpos + xspeed;
}
void shift() {
if(xpos+100 >= width-300){
ypos=ypos;
xspeed=(xspeed*(-1));
}
if(xpos+100<= 100){
ypos=ypos;
xspeed=xspeed*(-1);
}
}
void destroyed(){
imaDeadAlien=true;
}
void exitStageLeft(){
if(imaDeadAlien==true){
xpos=-2000;
xspeed=0;
}
}
}
void keyPressed() {
bullets.add(new Bullet(int(random(180,220)),200,200,250,550,10));
}
boolean intersect(Alien a){
return true;
}
class Bullet{
int h;
int s;
int b;
float xpos;
float ypos;
float yspeed;
Bullet(int temp_h, int temp_s, int temp_b, float temp_xpos, float temp_ypos, float temp_yspeed){
h= temp_h;
s= temp_s;
b= temp_b;
xpos = temp_xpos;
ypos = temp_ypos;
yspeed = temp_yspeed;
}
void display(){
fill(h,s,b);
rect(xpos, ypos, 4, 10);
}
void fire(){
ypos=ypos-yspeed;
}
boolean finished(){
if (ypos-yspeed < 50 || ypos-yspeed > 950) return true;
else return false;
}
boolean intersect(Alien a){
float distance = dist(xpos,ypos,a.true_xpos,a.true_ypos);
if(distance < 20){
return true;
} else {
return false;
}
}
}
class Spaceship{
//declare variables
int h;
int s;
int b;
float xpos;
float ypos;
//constructor
Spaceship(int temp_h, int temp_s, int temp_b, float temp_xpos, float temp_ypos){
h=temp_h;
s=temp_s;
b=temp_b;
xpos=temp_xpos;
ypos=temp_ypos;
}
void display(){
noStroke();
fill(h,s,b);
ellipse(xpos,ypos,50,50);
}
void move(){
xpos=mouseX;
noCursor();
}
void limit_x(){
if(mouseX<100){
xpos=100;
}
if(mouseX>(width-100)){
xpos=(width-100);
}
}
void lastGuy(){
println(deadAliens);
if(deadAliens==cols*rows-1){ //changed this line here to match global variables
lastGuy=1000;
}
else {
lastGuy=0;
}
}
}
The second script is what i want the explosion to be once the circle is gone.
int num = 300;
float[] px = new float[num];
float[] py = new float[num];
void setup(){
size(400,400);
for(int i=0;i<num;i=i+5){
px[i]=200;
py[i]=200;
}
}
void draw(){
background(200);
for(int i=0;i<num;i=i+1){
px[i] = px[i] + random(-2, 2);
py[i] = py[i] + random(-2, 2);
constrain(px[i],0,100);
constrain(py[i],0,100);
ellipse(px[i],py[i],10,10);
}
}
1