-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBoundary.pde
51 lines (39 loc) · 1.15 KB
/
Boundary.pde
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
39
40
41
42
43
44
45
46
47
48
49
50
51
class Boundary extends HitBody
{
// A boundary is a simple rectangle with x, y, width and height
float m_x;
float m_y;
boolean done() { return false; }
Boundary(float x, float y, float w, float h)
{
super(HitBodyType.Boundary);
m_x = x; m_y = y; //<>//
m_w = w; m_h = h;
makeBody(new Vec2(x, y), w, h);
}
protected void makeBody(Vec2 center, float w, float h)
{
// Define the polygon
PolygonShape sd = new PolygonShape();
// Figure out the box2d coordinates
float box2dW = box2d.scalarPixelsToWorld(w / 2);
float box2dH = box2d.scalarPixelsToWorld(h / 2);
sd.setAsBox(box2dW, box2dH);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = 10;
fd.friction = 30.0;
fd.restitution = 0.0;
// Create the body
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(box2d.coordPixelsToWorld(center));
m_body = box2d.createBody(bd);
m_body.createFixture(fd);
m_body.setUserData(this);
}
// Draw the boundary, if it were at an angle we'd have to do something fancier
void onDisplay() {
// Keep invisible
}
}