| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // Rope Vine
- "atomic component";
- var component = function (self) {
- var NUM_OBJECTS = 10;
- var node = self.node;
- node.position = [0, 0, 0];
- self.start = function() {
- var x = self.startPosition[0];
- var y = self.startPosition[1];
- // create the node body
- var groundBody = node.createComponent("RigidBody2D");
- groundBody.castShadows = false;
- var prevBody = groundBody;
- for (var i = 0; i < NUM_OBJECTS; i++) {
- var vnode = node.scene.createChild("RigidBody");
- var sprite2D = vnode.createComponent("StaticSprite2D");
- sprite2D.sprite = Atomic.cache.getResource("Sprite2D", "Sprites/vine.png");
- var vbody = vnode.createComponent("RigidBody2D");
- vbody.castShadows = false;
- vbody.bodyType = Atomic.BT_DYNAMIC;
- // Create box
- var vbox = vnode.createComponent("CollisionBox2D");
- // Set friction
- vbox.friction = .2;
- // Set mask bits.
- vbox.maskBits = 0xFFFF & ~0x0002;
- vnode.position = [x + 0.5 + 1.0 * i, y, 0.0];
- vbox.size = [1.0, 0.1];
- vbox.density = 5.0;
- vbox.categoryBits = 0x0001;
- if (i == NUM_OBJECTS - 1)
- vbody.angularDamping = 0.4;
- var joint = vnode.createComponent("ConstraintRevolute2D");
- joint.otherBody = prevBody;
- joint.anchor = [x + i, y];
- joint.collideConnected = false;
- prevBody = vbody;
- }
- var constraintRope = node.createComponent("ConstraintRope2D");
- constraintRope.otherBody = prevBody;
- constraintRope.ownerBodyAnchor = [x, y];
- constraintRope.maxLength = (NUM_OBJECTS + 0.01);
- }
- }
- exports.component = component;
|