Advertisement
Guest User

Rope.java

a guest
Aug 25th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. public class Rope {
  2.  
  3.     private World world;
  4.     private DistanceJoint rope;
  5.     private boolean ropeExists = false;
  6.  
  7.     public Rope(World world){
  8.         this.world = world;
  9.     }
  10.  
  11.     public void createRope(Body player, Body cloud){
  12.         destroyRope();
  13.  
  14.         DistanceJointDef dDef = new DistanceJointDef();
  15.  
  16.         dDef.initialize(player, cloud, player.getPosition(), cloud.getPosition());
  17.  
  18.         if(!world.isLocked()) {
  19.             rope = (DistanceJoint) this.world.createJoint(dDef);
  20.         }
  21.        
  22.         ropeExists = true;
  23.     }
  24.  
  25.  
  26.     public void destroyRope(){
  27.         if(ropeExists && !world.isLocked()) {
  28.             this.world.destroyJoint(rope);
  29.             rope = null;
  30.             ropeExists = false;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement