Vine.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Rope Vine
  2. var game = Atomic.game;
  3. var NUM_OBJECTS = 10;
  4. var node = self.node;
  5. node.position = [0, 0, 0];
  6. self.init = function(position) {
  7. var x = position[0];
  8. var y = position[1];
  9. // create the node body
  10. var groundBody = node.createComponent("RigidBody2D");
  11. groundBody.castShadows = false;
  12. var prevBody = groundBody;
  13. for (var i = 0; i < NUM_OBJECTS; i++) {
  14. var vnode = game.scene.createChild("RigidBody");
  15. var sprite2D = vnode.createComponent("StaticSprite2D");
  16. sprite2D.sprite = game.cache.getResource("Sprite2D", "Sprites/vine.png");
  17. var vbody = vnode.createComponent("RigidBody2D");
  18. vbody.castShadows = false;
  19. vbody.bodyType = Atomic.BT_DYNAMIC;
  20. // Create box
  21. var vbox = vnode.createComponent("CollisionBox2D");
  22. // Set friction
  23. vbox.friction = .2;
  24. // Set mask bits.
  25. vbox.maskBits = 0xFFFF & ~0x0002;
  26. vnode.position = [x + 0.5 + 1.0 * i, y, 0.0];
  27. vbox.size = [1.0, 0.1];
  28. vbox.density = 5.0;
  29. vbox.categoryBits = 0x0001;
  30. if (i == NUM_OBJECTS - 1)
  31. vbody.angularDamping = 0.4;
  32. var joint = vnode.createComponent("ConstraintRevolute2D");
  33. joint.otherBody = prevBody;
  34. joint.anchor = [x + i, y];
  35. joint.collideConnected = false;
  36. prevBody = vbody;
  37. }
  38. var constraintRope = node.createComponent("ConstraintRope2D");
  39. constraintRope.otherBody = prevBody;
  40. constraintRope.ownerBodyAnchor = [x, y];
  41. constraintRope.maxLength = (NUM_OBJECTS + 0.01);
  42. }
  43. function start() {
  44. }
  45. // fixme must have an update
  46. function update(timeStep) {}