get rid of the ripples

master
Jordan Orelli 5 years ago
parent 69f661dc63
commit d4f380089a

@ -137,8 +137,6 @@ function processJoystick (data) {
function processButton (data) {
game.players[data.id].val = data.button;
game.createRipple(data.id, 300, 1000);
if (debug) {
console.log(data.id + ': ' +
data.button);
@ -156,7 +154,6 @@ class Game {
this.numPlayers = 0;
this.id = 0;
this.colliders = new Group();
this.ripples = new Ripples();
}
add (id, x, y, w, h) {
@ -175,19 +172,9 @@ class Game {
draw() {
this.checkBounds();
this.ripples.draw();
drawSprites();
}
createRipple(id, r, duration) {
this.ripples.add(
this.players[id].position.x,
this.players[id].position.y,
r,
duration,
this.players[id].color);
}
setColor (id, r, g, b) {
this.players[id].color = color(r, g, b);
this.players[id].shapeColor = color(r, g, b);
@ -250,65 +237,3 @@ class Game {
}
}
}
// A simple pair of classes for generating ripples
class Ripples {
constructor() {
this.ripples = [];
}
add(x, y, r, duration, rcolor) {
this.ripples.push(new Ripple(x, y, r, duration, rcolor));
}
draw() {
for (let i = 0; i < this.ripples.length; i++) {
// Draw each ripple in the array
if(this.ripples[i].draw()) {
// If the ripple is finished (returns true), remove it
this.ripples.splice(i, 1);
}
}
}
}
class Ripple {
constructor(x, y, r, duration, rcolor) {
this.x = x;
this.y = y;
this.r = r;
// If rcolor is not defined, default to white
if (rcolor == null) {
rcolor = color(255);
}
this.stroke = rcolor;
this.strokeWeight = 3;
this.duration = duration; // in milliseconds
this.startTime = millis();
this.endTime = this.startTime + this.duration;
}
draw() {
let progress = (this.endTime - millis())/this.duration;
let r = this.r*(1 - progress);
push();
stroke(red(this.stroke),
green(this.stroke),
blue(this.stroke),
255*progress);
strokeWeight(this.strokeWeight);
fill(0, 0);
ellipse(this.x, this.y, r);
pop();
if (millis() > this.endTime) {
return true;
}
return false;
}
}

Loading…
Cancel
Save