Last active
December 27, 2017 20:24
-
-
Save Siunami/219c1cabfd5ccb151446306f9c36059c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WIDTH = 600; | |
var HEIGHT = 400; | |
function setup() { | |
createCanvas(WIDTH,HEIGHT); | |
} | |
var bombs = []; | |
var particles = []; | |
function draw() { | |
background(240); | |
console.log("bombs: " + bombs.length); | |
console.log("particles" + particles.length); | |
// if this.planted is true, stop redrawing. just have a static object | |
for (var i = 0; i < bombs.length; i++){ | |
if (!bombs[i].landed()){ | |
bombs[i].update(); | |
bombs[i].draw(); | |
} else { | |
bombs.splice(i, 1); | |
} | |
} | |
for(var x = 0; x < particles.length; x++){ | |
if (!particles[x].outOfBound()){ | |
particles[x].update(); | |
particles[x].draw(); | |
} else { | |
particles.splice(x,1); | |
} | |
} | |
} | |
function mouseClicked(){ | |
bombs.push(new Bomb(mouseX,mouseY)); | |
} | |
function Bomb(mouseX, mouseY){ | |
this.x = mouseX; | |
this.y = mouseY; | |
this.dy = 0; | |
this.gravity = .47; | |
this.r = 30; | |
this.g = 30; | |
this.b = 30; | |
this.increaseColor = true; | |
this.color = color(this.r, this.g, this.b); | |
this.ground = false; | |
this.draw = function() { | |
this.smoothColorFade(); | |
fill(this.color); | |
ellipse(this.x, this.y, 20, 20); | |
}; | |
this.smoothColorFade = function(){ | |
if(this.increaseColor && this.r < 235){ | |
this.r += 7; // 40 steps from 66 to 205 | |
console.log("increasing"); | |
} else if (this.increaseColor) { | |
this.increaseColor = false; | |
console.log("switch down"); | |
} else if (!this.increaseColor && this.r > 30){ | |
this.r -= 7; | |
console.log("decreasing"); | |
} else { | |
this.increaseColor = true; | |
console.log("switch up"); | |
} | |
this.color = color(this.r, this.g, this.b); | |
} | |
this.landed = function(){ | |
return this.ground; | |
} | |
this.update = function() { | |
if(!this.ground){ | |
if (this.y + this.dy > HEIGHT){ | |
this.ground = true; | |
for (var i = 0; i < 100; i++){ | |
particles.push(new Particle(this.x, this.y)); | |
} | |
} else { | |
this.y += this.dy; | |
this.dy += this.gravity; | |
} | |
} | |
}; | |
} | |
// Need to figure out to generate plant | |
function Particle(x, y) { | |
this.x = x; | |
this.y = y; | |
this.dx = random(-20,20); | |
this.dy = random(-10,-40); | |
this.accely = 8; | |
this.r = random(100, 255); | |
this.g = random(100, 255); | |
this.b = random(100, 255); | |
this.color = color(this.r,this.g,this.b); | |
this.draw = function(){ | |
fill(this.color); | |
ellipse(this.x,this.y,5,5); | |
} | |
this.update = function(){ | |
this.y += this.dy; | |
this.x += this.dx; | |
// if (this.y < -4){ | |
// this.y += this.accely; | |
// } | |
this.y += this.accely; | |
} | |
this.outOfBound = function(){ | |
if (this.x > WIDTH || this.x < 0 | |
|| this.y > HEIGHT || this.y < 0){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment