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

/js/DemoHelloWorld/CircleEntity.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 70 lines | 26 code | 7 blank | 37 comment | 1 complexity | 0f148fcc9f7382e8819d175e736f6372 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. DemoHelloWorld.CircleEntity
  4. Created By:
  5. Mario Gonzalez
  6. Project:
  7. DemoHelloWorld
  8. Abstract:
  9. This is the most basic entity i could come up with for a HelloWorldDemo of RealtimeMultiplayerNodeJS
  10. Basic Usage:
  11. // Create the GameEntity
  12. var circleEntity = new DemoHelloWorld.CircleEntity( anEntityid, aClientid );
  13. circleEntity.entityType = DemoHelloWorld.Constants.ENTITY_TYPES.GENERIC_CIRCLE;
  14. circleEntity.radius = aRadius;
  15. circleEntity.position.set( Math.random() * DemoHelloWorld.Constants.GAME_WIDTH, Math.random() * DemoHelloWorld.Constants.GAME_HEIGHT);
  16. // Place the circle and collision circle into corresponding containers
  17. this.fieldController.addEntity( circleEntity );
  18. Version:
  19. 1.0
  20. */
  21. (function () {
  22. DemoHelloWorld.CircleEntity = function (anEntityid, aClientid) {
  23. DemoHelloWorld.CircleEntity.superclass.constructor.call(this, anEntityid, aClientid);
  24. this.speed = Math.random();
  25. return this;
  26. };
  27. DemoHelloWorld.CircleEntity.prototype = {
  28. speed: 0,
  29. radius: DemoHelloWorld.Constants.ENTITY_DEFAULT_RADIUS,
  30. entityType: DemoHelloWorld.Constants.ENTITY_TYPES.CIRCLE,
  31. /**
  32. * Update the entity's view - this is only called on the clientside
  33. */
  34. updateView: function () {
  35. if (!this.view) return;
  36. this.view.x = this.position.x - this.radius;
  37. this.view.y = this.position.y - this.radius;
  38. },
  39. /**
  40. * @inheritDoc
  41. */
  42. updatePosition: function (speedFactor, gameClock, gameTick) {
  43. // This is where you would move your entity here
  44. // Speedfactor is a number between 0.0 and 2.0, where 1.0 means its running at perfect framerate
  45. },
  46. /**
  47. * Deallocate memory
  48. */
  49. dealloc: function () {
  50. DemoHelloWorld.CircleEntity.superclass.dealloc.call(this);
  51. },
  52. /**
  53. * Append radius to our entity description created by the super class
  54. */
  55. constructEntityDescription: function () {
  56. // Note: "~~" is just a way to round the value without the Math.round function call
  57. return DemoHelloWorld.CircleEntity.superclass.constructEntityDescription.call(this) + ',' + ~~this.radius;
  58. }
  59. };
  60. // extend RealtimeMultiplayerGame.model.GameEntity
  61. RealtimeMultiplayerGame.extend(DemoHelloWorld.CircleEntity, RealtimeMultiplayerGame.model.GameEntity, null);
  62. })();