-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.js
31 lines (28 loc) · 767 Bytes
/
box.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Angry Birds with Matter.js
// The Coding Train / Daniel Shiffman
// https://thecodingtrain.com/challenges/content/videos/challenges/138-angry-birds-with-matterjs
//https://youtu.be/TDQzoe9nslY
// Code from Challenge: https://editor.p5js.org/codingtrain/sketches/UOR4nIcNS
class Box {
constructor(x, y, w, h) {
const options = {
restitution: 0.5
};
this.body = Matter.Bodies.rectangle(x, y, w, h, options);
Matter.World.add(world, this.body);
this.w = w;
this.h = h;
}
show() {
const pos = this.body.position;
const angle = this.body.angle;
push();
translate(pos.x, pos.y);
rotate(angle);
fill(255);
rectMode(CENTER);
imageMode(CENTER);
image(boxImg, 0, 0, this.w, this.h);
pop();
}
}