xxxxxxxxxx
43
let walls;
let block;
function setup() {
new Canvas(400,400);
walls = new Group();
let w1 = createSprite(0, -10, 1500, 10);
walls.add(w1);
let w2 = createSprite(width + 10, 10, 10, 1500);
walls.add(w2);
let w3 = createSprite(0, height + 10, 1500, 10);
walls.add(w3);
let w4 = createSprite(-10, 0, 10, 1500);
walls.add(w4);
for (let i = 0; i < walls.length; i++) {
walls[i].immovable = true;
walls[i].collider = 'static';
}
block = new Sprite(150,150,15,15);
block.color = "black";
block.immovable = true;
block.collider = 'static';
}
function draw() {
background(220);
}
function mousePressed() {
let spr = createSprite(
width/2, height/2,
random(10, 50), random(10, 50));
spr.shapeColor = color(255);
spr.velocity.y = random(-3,3);
spr.velocity.x = random(-3, 3);
spr.position.x = mouseX;
spr.position.y = mouseY;
spr.rotationSpeed = ~~random(-5,5);
spr.friction = 0.1;
spr.life = ~~random(300)+300;
}