Angry Birds
(Part 2)
Box.js:
class Box {
constructor(x, y, w, h) {
var options = {
restitution: 0.3,
friction: 1.0,
density: 1.0,
};
this.body = Bodies.rectangle(x, y, w, h, options);
this.width = w;
this.height = h;
World.add(world, this.body);
}
display() {
var pos = this.body.position;
var angle = this.body.angle;
push(); //Capture new setting
translate(pos.x, pos.y); //Change the zero of the axis to a given x and y position
rotate(angle);
rectMode(CENTER);
strokeWeight(4);
stroke('green');
fill(255);
rect(0, 0, this.width, this.height);
pop(); //revert back to the old setting
}
}
0 Comments: