PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/js/BubbleDots/traits/BoundaryTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 62 lines | 30 code | 7 blank | 25 comment | 0 complexity | cd19293a15a462e48e8cd2f6977536bc MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. (function () {
  13. BubbleDots.namespace("BubbleDots.traits");
  14. BubbleDots.traits.BoundaryTrait = function (aCollisionManager) {
  15. BubbleDots.traits.BoundaryTrait.superclass.constructor.call(this);
  16. this._collisionManager = aCollisionManager;
  17. };
  18. BubbleDots.traits.BoundaryTrait.prototype = {
  19. displayName: "BoundaryTrait", // Unique string name for this Trait
  20. _boundaryRule: 0,
  21. _collisionManager: null,
  22. /**
  23. * @inheritDoc
  24. */
  25. attach: function (anEntity) {
  26. BubbleDots.traits.BoundaryTrait.superclass.attach.call(this, anEntity);
  27. this.intercept(['updatePosition']);
  28. },
  29. /**
  30. * Intercepted properties
  31. */
  32. updatePosition: function (speedFactor, gameClock, gameTick) {
  33. var trait = this.getTraitWithName("BoundaryTrait");
  34. // Call the original handleAcceleration
  35. trait._collisionManager.handleBoundaryForCircle(this.getCollisionCircle(), trait._boundaryRule);
  36. trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick);
  37. },
  38. detach: function (force) {
  39. this._collisionManager = null;
  40. BubbleDots.traits.BoundaryTrait.superclass.detach.call(this, force);
  41. },
  42. ///// ACCESSORS
  43. /**
  44. * Set the gravitational force
  45. * @param {Number} aBoundaryRule Boundary rule to apply to collision circle, see CollisionManager
  46. */
  47. setBoundaryRule: function (aBoundaryRule) {
  48. this._boundaryRule = aBoundaryRule;
  49. return this;
  50. }
  51. };
  52. // Extend BaseTrait
  53. RealtimeMultiplayerGame.extend(BubbleDots.traits.BoundaryTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
  54. })();