xxxxxxxxxx
var gun = [];
function setup() {
createCanvas(600, 600);
gun[0] = new Gun(width/2, height, 50, 50, 100, 30);
}
function draw() {
background(51,51,51);
for (var i = 0; i < gun.length; i++) {
gun[i].draw();
}
}
//For making Gun object
function Gun(x,y,tempWidth,tempTopWidth,tempHeight,amount){
this.bubbles = [];
this.x = x;
this.y = y;
this.width = tempWidth;
this.topWidth = tempTopWidth;
this.height = tempHeight;
this.amountOfBubbles = amount;
this.draw = function(){
fill(192,192,192); //gun color
quad(this.x - this.width / 4,
this.y, this.x - this.topWidth / 4,
this.y - this.height, this.x + this.topWidth / 4,
this.y - this.height,
this.x + this.width / 4,
this.y);
this.water();
}
this.water = function(){
for (var i = 0; i < this.amountOfBubbles; i++){
if (this.isBubbleActive(this.bubbles[i])){
this.bubbles[i].move();
this.bubbles[i].draw();
}
else{
this.bubbles[i]= new Bubble(this.x + random(-this.topWidth / 4, this.topWidth / 2),
this.y-this.height,
color(0, 204, 255,150),
random(4, 10),
random(-3,3),
random(-2, -5));
}
}
}
this.isBubbleActive = function(part){
if (part != null){
if (part.isVisible()){
return true;
}
}
return false;
}
}
//For Bubble object
function Bubble(x, y, tempColor, tempWidth, xSpeed, ySpeed){
this.x = x;
this.y = y;
this.color = tempColor;
this.width = tempWidth;
this.xSpd = xSpeed;
this.ySpd = ySpeed;
this.lifeSpan = 100;
this.move = function(){
this.x += this.xSpd;
this.y += this.ySpd;
this.ySpd += 0.03;
this.lifeSpan--;
}
this.draw = function(){
fill(this.color)
ellipse(this.x , this.y, this.width*4);
}
this.isVisible = function(){
if(this.x > width || this.x < 0 || this.y > height || this.y < 0){
return false;
}
return true;
}
}