/js/BubbleDots/traits/BoundaryTrait.js
JavaScript | 62 lines | 30 code | 7 blank | 25 comment | 0 complexity | cd19293a15a462e48e8cd2f6977536bc MD5 | raw file
1/** 2 File: 3 BoundaryTrait.js 4 Created By: 5 Mario Gonzalez 6 Project : 7 RealtimeMultiplayerNodeJS 8 Abstract: 9 This trait will cause an entity to react to boundary collisions 10 Basic Usage: 11 12 */ 13(function () { 14 BubbleDots.namespace("BubbleDots.traits"); 15 BubbleDots.traits.BoundaryTrait = function (aCollisionManager) { 16 BubbleDots.traits.BoundaryTrait.superclass.constructor.call(this); 17 this._collisionManager = aCollisionManager; 18 }; 19 20 BubbleDots.traits.BoundaryTrait.prototype = { 21 displayName: "BoundaryTrait", // Unique string name for this Trait 22 _boundaryRule: 0, 23 _collisionManager: null, 24 25 /** 26 * @inheritDoc 27 */ 28 attach: function (anEntity) { 29 BubbleDots.traits.BoundaryTrait.superclass.attach.call(this, anEntity); 30 this.intercept(['updatePosition']); 31 }, 32 33 /** 34 * Intercepted properties 35 */ 36 updatePosition: function (speedFactor, gameClock, gameTick) { 37 var trait = this.getTraitWithName("BoundaryTrait"); 38 39 // Call the original handleAcceleration 40 trait._collisionManager.handleBoundaryForCircle(this.getCollisionCircle(), trait._boundaryRule); 41 trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick); 42 }, 43 44 detach: function (force) { 45 this._collisionManager = null; 46 BubbleDots.traits.BoundaryTrait.superclass.detach.call(this, force); 47 }, 48 49 ///// ACCESSORS 50 /** 51 * Set the gravitational force 52 * @param {Number} aBoundaryRule Boundary rule to apply to collision circle, see CollisionManager 53 */ 54 setBoundaryRule: function (aBoundaryRule) { 55 this._boundaryRule = aBoundaryRule; 56 return this; 57 } 58 }; 59 60 // Extend BaseTrait 61 RealtimeMultiplayerGame.extend(BubbleDots.traits.BoundaryTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait); 62})();