Advertisement
dermetfan

designception

Dec 12th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. package net.dermetfan.utils.libgdx.box2d;
  2.  
  3. import com.badlogic.gdx.physics.box2d.Body;
  4. import com.badlogic.gdx.physics.box2d.Joint;
  5. import com.badlogic.gdx.utils.Array;
  6.  
  7. public class Rope2 {
  8.  
  9.     public static class Segment {
  10.  
  11.         public final Body body;
  12.         public final Array<Connection> connections = new Array<Connection>(2);
  13.  
  14.         public Segment(Body body) {
  15.             this.body = body;
  16.         }
  17.  
  18.         public Segment(Body body, Connection... connections) {
  19.             this(body);
  20.             this.connections.addAll(connections);
  21.         }
  22.  
  23.     }
  24.  
  25.     /** abstracts a {@link Joint} with child joints
  26.      *  @author dermetfan */
  27.     public static abstract class Connection {
  28.  
  29.         public static interface Builder {
  30.             public Connection createConnection(Body bodyA, Body bodyB);
  31.         }
  32.  
  33.         public final Array<Connection> children = new Array<Connection>(0);
  34.  
  35.         public Connection() {
  36.         }
  37.  
  38.         public Connection(Body bodyA, Body bodyB) {
  39.             connect(bodyA, bodyB);
  40.         }
  41.  
  42.         public abstract void connect(Body bodyA, Body bodyB);
  43.  
  44.         public abstract void destroy();
  45.  
  46.     }
  47.  
  48.     public static abstract class SingleConnection extends Connection {
  49.         protected Joint joint;
  50.     }
  51.  
  52.     public static abstract class DoubleConnection extends Connection {
  53.         protected Joint joint1, joint2;
  54.     }
  55.  
  56.     public static abstract class TripleConnection extends Connection {
  57.         protected Joint joint1, joint2, joint3;
  58.     }
  59.  
  60.     public static abstract class MultipleConnection extends Connection {
  61.         protected final Array<Joint> joints = new Array<Joint>(4);
  62.     }
  63.  
  64.     public static abstract class Builder {
  65.         private Connection.Builder connectionBuilder;
  66.  
  67.         public abstract Segment createSegment();
  68.  
  69.         public abstract Connection connect();
  70.     }
  71.  
  72.     public static void main(String[] args) {
  73.         Connection.Builder connectionBuilder = new Connection.Builder() {
  74.  
  75.             @Override
  76.             public Connection createConnection(Body bodyA, Body bodyB) {
  77.                 return null;
  78.             }
  79.  
  80.         };
  81.  
  82.         Rope2.Builder ropeBuilder = new Rope2.Builder() {
  83.  
  84.             @Override
  85.             public Segment createSegment() {
  86.                 return null;
  87.             }
  88.  
  89.             @Override
  90.             public Connection connect() {
  91.                 return null;
  92.             }
  93.  
  94.         };
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement