-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBox.pde
43 lines (33 loc) · 906 Bytes
/
Box.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
abstract class Box extends HitBody
{
// Constructor
Box(float x, float y, float w, float h)
{
super(HitBodyType.Box);
m_w = w; m_h = h;
makeBody(new Vec2(x, y), w, h);
}
boolean done()
{
return false;
}
abstract FixtureDef getFixture();
protected void makeBody(Vec2 center, float w, float h)
{
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w / 2);
float box2dH = box2d.scalarPixelsToWorld(h / 2);
sd.setAsBox(box2dW, box2dH);
// Define a fixture
FixtureDef fd = getFixture();
fd.shape = sd;
// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
m_body = box2d.createBody(bd);
m_body.createFixture(fd);
m_body.setUserData(this);
//body.setMassFromShapes();
}
}