PageRenderTime 4ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/js/BubbleDots/traits/GravityTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 59 lines | 26 code | 8 blank | 25 comment | 0 complexity | 728a6d09050cb0e682971047786bd21f 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. GravityTrait.js
  4. Created By:
  5. Mario Gonzalez
  6. Project :
  7. RealtimeMultiplayerNodeJS
  8. Abstract:
  9. This trait will cause an entity to chase a target
  10. Basic Usage:
  11. */
  12. (function () {
  13. BubbleDots.namespace("BubbleDots.traits");
  14. var RATE = 0.2;
  15. BubbleDots.traits.GravityTrait = function () {
  16. BubbleDots.traits.GravityTrait.superclass.constructor.call(this);
  17. this._force = BubbleDots.traits.GravityTrait.prototype.DEFAULT_FORCE;
  18. };
  19. BubbleDots.traits.GravityTrait.prototype = {
  20. displayName: "GravityTrait", // Unique string name for this Trait
  21. _force: 0,
  22. DEFAULT_FORCE: 0.21,
  23. /**
  24. * @inheritDoc
  25. */
  26. attach: function (anEntity) {
  27. BubbleDots.traits.GravityTrait.superclass.attach.call(this, anEntity);
  28. this.intercept(['updatePosition']);
  29. },
  30. /**
  31. * Intercepted properties
  32. */
  33. updatePosition: function (speedFactor, gameClock, gameTick) {
  34. var trait = this.getTraitWithName("GravityTrait");
  35. this.acceleration.y += trait._force * speedFactor;
  36. // Call the original handleAcceleration
  37. trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick);
  38. },
  39. ///// ACCESSORS
  40. /**
  41. * Set the gravitational force
  42. * @param {Number} force Strength of gravity in Y axis
  43. */
  44. setForce: function (force) {
  45. this._force = force
  46. }
  47. };
  48. // Extend BaseTrait
  49. RealtimeMultiplayerGame.extend(BubbleDots.traits.GravityTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
  50. })();