Vine.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Rope Vine
  2. var NUM_OBJECTS = 10;
  3. var node = self.node;
  4. var x = node.position2D[0];
  5. var y = node.position2D[1];
  6. node.position = [0, 0, 0];
  7. print("VINE!");
  8. function start() {
  9. // create the node body
  10. var groundBody = node.createComponent("RigidBody2D");
  11. var prevBody = groundBody;
  12. for (var i = 0; i < NUM_OBJECTS; i++) {
  13. // can we create off our node instead of scene?
  14. var vnode = scene.createChild("RigidBody");
  15. var vbody = vnode.createComponent("RigidBody2D");
  16. vbody.bodyType = Atomic.BT_DYNAMIC;
  17. // Create box
  18. var vbox = vnode.createComponent("CollisionBox2D");
  19. // Set friction
  20. vbox.friction = .2;
  21. // Set mask bits.
  22. vbox.maskBits = 0xFFFF & ~0x0002;
  23. vnode.position = [x + 0.5 + 1.0 * i, y, 0.0];
  24. vbox.size = [1.0, 0.1];
  25. vbox.density = 10.0;
  26. vbox.categoryBits = 0x0001;
  27. var joint = vnode.createComponent("ConstraintRevolute2D");
  28. joint.otherBody = prevBody;
  29. joint.anchor = [x + i, y];
  30. joint.collideConnected = false;
  31. prevBody = vbody;
  32. }
  33. var constraintRope = node.createComponent("ConstraintRope2D");
  34. constraintRope.otherBody = prevBody;
  35. constraintRope.ownerBodyAnchor = [x, y];
  36. constraintRope.maxLength = (NUM_OBJECTS - 1.0 + 0.01);
  37. }