/** * Create a new paddle. * * @param world The world the paddle will be added to. * @param y The height of the paddle (starts centered on the x) * @param mode The keys that will move this paddle */ public Paddle(World world, int y, MovementMode mode) { Mode = mode; // Respond to the keyboard KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(this); // Add the physics body BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(world.Bounds.width / 2, y); bd.linearDamping = 0.0f; bd.angularDamping = 0.01f; FixtureDef fd = new FixtureDef(); fd.shape = new PolygonShape(); ((PolygonShape) fd.shape).setAsBox(SIZE.width / 2, SIZE.height / 2); fd.density = 0.1f; fd.friction = 0.0f; fd.restitution = 1.0f; j2dBody = world.j2dWorld.createBody(bd); j2dBody.createFixture(fd); j2dBody.setUserData(this); // Limit it to only x movement BodyDef gbd = new BodyDef(); gbd.type = BodyType.STATIC; bd.position.set(world.Bounds.width / 2, y); PrismaticJointDef pjd = new PrismaticJointDef(); pjd.collideConnected = true; pjd.initialize( j2dBody, world.j2dWorld.createBody(gbd), j2dBody.getWorldCenter(), new Vec2(1.0f, 0.0f)); world.j2dWorld.createJoint(pjd); }