-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathboundary.js
More file actions
38 lines (32 loc) · 981 Bytes
/
boundary.js
File metadata and controls
38 lines (32 loc) · 981 Bytes
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
32
33
34
35
36
37
38
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// A fixed boundary class
// A boundary is a simple rectangle with x,y,width,and height
class Boundary
{
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
let fd = new box2d.b2FixtureDef();
fd.density = 1.0;
fd.friction = 0.5;
fd.restitution = 0.2;
let bd = new box2d.b2BodyDef();
bd.type = box2d.b2BodyType.b2_staticBody;
bd.position.x = scaleToWorld(this.x);
bd.position.y = scaleToWorld(this.y);
fd.shape = new box2d.b2PolygonShape();
fd.shape.SetAsBox(this.w / (scaleFactor * 2), this.h / (scaleFactor * 2));
this.body = world.CreateBody(bd).CreateFixture(fd);
}
// Draw the boundary, if it were at an angle we'd have to do something fancier
display() {
fill(127);
stroke(0);
rectMode(CENTER);
rect(this.x, this.y, this.w, this.h);
}
}