Angry Birds Game
(Part I)
Box.js:
class Box {
constructor(x, y, w, h) {
var options = {
restitution: 1,
};
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);
fill(255);
rect(0, 0, this.width, this.height);
pop(); //revert back to the old setting
}
}
0 Comments: