xxxxxxxxxx
37
// https://discourse.processing.org/t/how-to-change-object-size-upon-bouncing-in-p5-play/16540/2
// https://molleindustria.github.io/p5.play/docs/classes/Sprite.html
// https://creative-coding.decontextualize.com/making-games-with-p5-play/
// i not know that library, so i can not say if you can customize a bounce
// that way to just change the position of a sprite ( nail move down.. )
// here try like in bounce pysics the play lib provides.
var balls;
function setup() {
createCanvas(400, 400);
bar = createSprite(200, 300, 7, 200);
// bar.immovable = true;
bar.mass=10;
bar.friction=0.05;
balls = new Group();
}
function draw() {
background(0,0,80);
if (frameCount % 120 == 0) {
let dx = int( random(-20,20) );
let dc = random(100);
let ball = createSprite(200+dx, 10, 20, 20);
ball.draw = function() {
fill(100+dc,200-dc,dc);
ellipse(0,0,20,20)
}
ball.setSpeed(2, 90);
ball.restitution = 0.3;
ball.setCollider('circle', 0, 0, 10);
balls.push(ball);
}
balls.bounce(bar);
drawSprites();
}