xxxxxxxxxx
67
let walls = [];
let particles = [];
var angle = 0;
var step;
var r = 10;
let player;
function setup() {
createCanvas(windowWidth, windowHeight);
walls.push(new Boundary(0,0,width,0));
walls.push(new Boundary(width,0,width,height));
walls.push(new Boundary(width,height,0,height));
walls.push(new Boundary(0,height,0,0));
for(let i = 0; i < 9; i++){
walls.push(new Boundary(random(width),random(height),random(width),random(height)));
}
for(let a = 0; a < 9; a++){
particles.push(new Particle());
}
player = new Player(width / 2, height / 2, 2);
particles[0].update(200,200);
for(let i = 1; i < particles.length; i++){
let x = r * sin(angle);
let y = r * cos(angle);
particles[i].update(200+x,200+y);
angle = angle + step;
}
}
function draw() {
background(0);
step = TWO_PI/8;
for(let wall of walls){
wall.show();
}
particles[0].show();
for(let particle of particles){
particle.look(walls);
}
player.move();
player.display();
// Check if the player picks up the object
if (player.pickUp(particles[0])) {
if(keyIsDown(32)){
particles[0].update(player.x,player.y);
for(let i = 1; i < particles.length; i++){
let x = r * sin(angle);
let y = r * cos(angle);
particles[i].update(player.x+x,player.y+y);
angle = angle + step;
}
}
}
}