PageRenderTime 41ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/js/BubbleDots/traits/PoisonTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 64 lines | 23 code | 9 blank | 32 comment | 0 complexity | e708532f1f483e9136e81e7d9e94346d 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. PoisonTrait.js
  4. Created By:
  5. Mario Gonzalez
  6. Project :
  7. RealtimeMultiplayerNodeJS
  8. Abstract:
  9. Basic Usage:
  10. */
  11. (function () {
  12. BubbleDots.namespace("BubbleDots.traits");
  13. BubbleDots.traits.PoisonTrait = function () {
  14. BubbleDots.traits.PoisonTrait.superclass.constructor.call(this);
  15. };
  16. BubbleDots.traits.PoisonTrait.prototype = {
  17. displayName: "PoisonTrait", // Unique string name for this Trait
  18. color: "2",
  19. /**
  20. * @inheritDoc
  21. */
  22. attach: function (anEntity) {
  23. BubbleDots.traits.PoisonTrait.superclass.attach.call(this, anEntity);
  24. this.intercept(['onCollision', 'color']);
  25. },
  26. /**
  27. * @inheritDoc
  28. */
  29. execute: function () {
  30. BubbleDots.traits.PoisonTrait.superclass.execute.call(this);
  31. },
  32. /**
  33. * Intercepted properties
  34. */
  35. /**
  36. * Called when this object has collided with another
  37. * @param a Object A in the collision pair, note this may be this object
  38. * @param b Object B in the collision pair, note this may be this object
  39. * @param collisionNormal A vector describing the collision
  40. */
  41. onCollision: function (a, b, collisionNormal) {
  42. // We're either A or B, so perform a simple check against A to figure out which of the two objects we are
  43. var me = this === a ? a : b;
  44. var them = this === a ? b : a;
  45. // var newRadius = Math.max( 0.1, them.radius-0.5 );
  46. // them.radius = newRadius;
  47. // them.collisionCircle.setRadius( newRadius );
  48. them.acceleration.translatePoint(collisionNormal.multiply(them.velocityMax * 0.9));
  49. }
  50. };
  51. // Extend BaseTrait
  52. RealtimeMultiplayerGame.extend(BubbleDots.traits.PoisonTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
  53. })();