PageRenderTime 127ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/js/DemoCircles/PlayerEntity.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 73 lines | 41 code | 11 blank | 21 comment | 5 complexity | 0738c1b9fd034a92c54808babbd2903c 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. DemoApp.CircleEntity
  4. Created By:
  5. Mario Gonzalez
  6. Project:
  7. DemoApp
  8. Abstract:
  9. This is the base entity for the demo game
  10. Basic Usage:
  11. Version:
  12. 1.0
  13. */
  14. (function () {
  15. DemoApp.PlayerEntity = function (anEntityid, aClientid) {
  16. DemoApp.PlayerEntity.superclass.constructor.call(this, anEntityid, aClientid);
  17. return this;
  18. };
  19. DemoApp.PlayerEntity.prototype = {
  20. entityType: DemoApp.Constants.ENTITY_TYPES.PLAYER_ENTITY,
  21. input: null,
  22. radius: 40,
  23. updateView: function () {
  24. DemoApp.PlayerEntity.superclass.updateView.call(this);
  25. },
  26. setInput: function (input) {
  27. this.input = input;
  28. },
  29. updatePosition: function () {
  30. var moveSpeed = 1.5;
  31. // Horizontal accelertheation
  32. if (this.input.isLeft()) this.acceleration.x -= moveSpeed;
  33. if (this.input.isRight()) this.acceleration.x += moveSpeed;
  34. // Vertical movement
  35. if (this.input.isUp()) this.acceleration.y -= moveSpeed;
  36. if (this.input.isDown()) this.acceleration.y += moveSpeed;
  37. this.velocity.translatePoint(this.acceleration);
  38. this.velocity.limit(5);
  39. this.velocity.multiply(0.85);
  40. this.acceleration.set(0, 0);
  41. this.collisionCircle.position.translatePoint(this.velocity);
  42. this.position = this.collisionCircle.position.clone();
  43. },
  44. setCollisionCircle: function (aCollisionCircle) {
  45. DemoApp.PlayerEntity.superclass.setCollisionCircle.call(this, aCollisionCircle);
  46. // this.collisionCircle.setIsFixed( true );
  47. },
  48. /**
  49. * Deallocate memory
  50. */
  51. dealloc: function () {
  52. if (this.input) {
  53. this.input.dealloc();
  54. delete this.input;
  55. }
  56. DemoApp.CircleEntity.superclass.dealloc.call(this);
  57. }
  58. };
  59. // extend RealtimeMultiplayerGame.model.GameEntity
  60. RealtimeMultiplayerGame.extend(DemoApp.PlayerEntity, DemoApp.CircleEntity, null);
  61. })();