aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv/java/wallj/block/SolidDef.java
blob: 25ff02267f1a606a7052a6538079f62f68257852 (plain)
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
52
53
54
55
56
57
58
59
60
package fr.umlv.java.wallj.block;

import fr.umlv.java.wallj.board.TileVec2;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;

/**
 * @author Pacien TRAN-GIRARD
 */
public final class SolidDef {
  private SolidDef() {
    // static class
  }

  /**
   * @param bodyType type of body
   * @param pos      initial position of the body
   * @return a corresponding body definition
   */
  public static BodyDef bodyDefOf(BodyType bodyType, Vec2 pos) {
    BodyDef def = new BodyDef();
    def.type = bodyType;
    def.position = pos;
    return def;
  }

  /**
   * @param shape a shape definition
   * @return a corresponding fixture definition
   */
  public static FixtureDef fixtureDefOf(Shape shape) {
    FixtureDef def = new FixtureDef();
    def.shape = shape;
    def.restitution = 1.0f;
    return def;
  }

  /**
   * @return a tile square shape definition
   */
  public static PolygonShape squareShape() {
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(TileVec2.TILE_DIM / 2, TileVec2.TILE_DIM / 2);
    return shape;
  }

  /**
   * @return a circle shape definition fitting in a tile
   */
  public static CircleShape circleShape() {
    CircleShape shape = new CircleShape();
    shape.m_radius = TileVec2.TILE_DIM / 2;
    return shape;
  }
}