PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/js/BubbleDots/traits/FoodTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 81 lines | 34 code | 12 blank | 35 comment | 0 complexity | 532c89f17865764dda91fbce875a1e05 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. FoodTrait.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.FoodTrait = function () {
  14. BubbleDots.traits.FoodTrait.superclass.constructor.call(this);
  15. };
  16. BubbleDots.traits.FoodTrait.prototype = {
  17. displayName: "FoodTrait", // Unique string name for this Trait
  18. color: "3",
  19. /**
  20. * @inheritDoc
  21. */
  22. attach: function (anEntity) {
  23. BubbleDots.traits.FoodTrait.superclass.attach.call(this, anEntity);
  24. this.intercept(['onCollision', 'color']);
  25. },
  26. /**
  27. * @inheritDoc
  28. */
  29. execute: function () {
  30. BubbleDots.traits.FoodTrait.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. // me.addTrait( )
  46. BubbleDots.lib.TWEEN.remove(me._tween);
  47. me._tween = new BubbleDots.lib.TWEEN.Tween({radius: me.radius})
  48. .to({radius: 2}, 500)
  49. .easing(BubbleDots.lib.TWEEN.Easing.Back.EaseInOut)
  50. .onUpdate(function () {
  51. me.setRadius(~~this.radius);
  52. })
  53. .start();
  54. // var newRadius = Math.max( BubbleDots.traits.FoodTrait.prototype.radius, them.radius+0.1 );
  55. // them.radius = newRadius;
  56. // them.collisionCircle.setRadius( newRadius );
  57. me.collisionCircle.collisionGroup = 0;
  58. // me.acceleration.translatePoint( collisionNormal.multiply(-10) );
  59. var chaseTrait = this.addTraitAndExecute(new BubbleDots.traits.ChaseTrait());
  60. chaseTrait.setTarget(them);
  61. this.addTraitAndExecute(new BubbleDots.traits.PerlinNoiseTrait());
  62. // me.tempColor();
  63. }
  64. };
  65. // Extend BaseTrait
  66. RealtimeMultiplayerGame.extend(BubbleDots.traits.FoodTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
  67. })();