Skip to content

Commit

Permalink
-Add rope joint support
Browse files Browse the repository at this point in the history
refs #9
  • Loading branch information
narfman0 committed Dec 6, 2014
1 parent a6303dd commit 38556e0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.blastedstudios.gdxworld.plugin.mode.joint.window.rope;

import net.xeoh.plugins.base.annotations.PluginImplementation;

import com.badlogic.gdx.physics.box2d.JointDef.JointType;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.blastedstudios.gdxworld.plugin.mode.joint.BaseJointWindow;
import com.blastedstudios.gdxworld.plugin.mode.joint.IJointWindow;
import com.blastedstudios.gdxworld.plugin.mode.joint.JointMode;
import com.blastedstudios.gdxworld.world.joint.RopeJoint;

@PluginImplementation
public class RopePlugin implements IJointWindow<RopeJoint>{
@Override public JointType getJointType() {
return JointType.RopeJoint;
}

@Override public RopeJoint createJoint(RopeJoint joint) {
return joint == null ? new RopeJoint() : joint;
}

@Override public BaseJointWindow createJointWindow(Skin skin, JointMode mode, RopeJoint joint) {
return new RopeWindow(skin, mode, joint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.blastedstudios.gdxworld.plugin.mode.joint.window.rope;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.JointDef.JointType;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.blastedstudios.gdxworld.plugin.mode.joint.BaseJointWindow;
import com.blastedstudios.gdxworld.plugin.mode.joint.JointMode;
import com.blastedstudios.gdxworld.ui.leveleditor.VertexTable;
import com.blastedstudios.gdxworld.world.joint.RopeJoint;

class RopeWindow extends BaseJointWindow {
private final VertexTable centerTable;
private final RopeJoint joint;

public RopeWindow(Skin skin, JointMode mode, RopeJoint joint) {
super("Rope Editor", skin, JointType.RopeJoint, mode, joint);
this.joint = joint;
centerTable = new VertexTable(joint.getCenter(), skin);
add(new Label("Anchor: ", skin));
add(centerTable);
row();
add(createControlTable()).colspan(2);
pack();
}

@Override public void apply(){
super.apply();
joint.setCenter(centerTable.getVertex());
}

@Override public boolean clicked(Vector2 pos) {
if(!super.clicked(pos))
centerTable.setVertex(pos.x, pos.y);
return true;
}

@Override public Vector2 getCenter() {
return centerTable.getVertex();
}
}
35 changes: 18 additions & 17 deletions src/com/blastedstudios/gdxworld/world/joint/RopeJoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@
public class RopeJoint extends GDXJoint {
private static final long serialVersionUID = 1L;
private float maxLength;
private transient Vector2 center;

public RopeJoint(Vector2 center){
this.center = center;
}
private Vector2 center = new Vector2();

@Override public Joint attach(World world) {
RopeJointDef def = new RopeJointDef();
def.maxLength = maxLength;
return attach(world, def);
}

public float getMaxLength() {
return maxLength;
@Override public Object clone() {
RopeJoint clone = new RopeJoint();
clone.setMaxLength(maxLength);
clone.setCenter(center.cpy());
return super.clone(clone);
}

public void setMaxLength(float maxLength) {
this.maxLength = maxLength;
@Override public void translate(Vector2 center) {
center.add(center);
}

@Override public void scl(float scalar) {
center.scl(scalar);
}

@Override public Vector2 getCenter() {
return center.cpy();
}

@Override public Object clone() {
RopeJoint clone = new RopeJoint(center.cpy());
clone.setMaxLength(maxLength);
return super.clone(clone);
public void setCenter(Vector2 center) {
this.center = center;
}

@Override public void translate(Vector2 center) {
center.add(center);
public float getMaxLength() {
return maxLength;
}

@Override public void scl(float scalar) {
center.scl(scalar);
public void setMaxLength(float maxLength) {
this.maxLength = maxLength;
}
}

0 comments on commit 38556e0

Please sign in to comment.