xxxxxxxxxx
49
class Bomb{
constructor(){
this.pos = createVector(random(width),height-20);
this.velocity = createVector(0,-1);
this.velocity.setMag(random(1,7));
this.exploded = false;
this.acceleration = createVector(0,1);
this.acceleration.setMag(-0.3);
this.sparks = [];
}
show(){
push()
noStroke();
if(!this.exploded){
fill('red');
triangle(this.pos.x,this.pos.y,this.pos.x+10,this.pos.y,this.pos.x+5,this.pos.y-10);
fill(255)
rect(this.pos.x,this.pos.y,10,30)
fill(226, 88, 34)
rect(this.pos.x+2,this.pos.y+30,5,20)
}
else{
for(let spark of this.sparks){
spark.show();
spark.update();
}
}
pop()
}
applyForce(force){
this.acceleration.add(force);
}
update(){
if(floor(this.velocity.mag())==0){
this.explode()
}
this.applyForce(gravity);
this.velocity.add(this.acceleration);
this.pos.add(this.velocity);
}
explode(){
this.exploded = true;
for(var i=0;i<15;i++){
this.sparks.push(new Spark(this.pos.x,this.pos.y))
}
}
}