Monkey.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function(){
  2. var Monkey = game.Monkey = function(props)
  3. {
  4. props = props || {};
  5. Monkey.superClass.constructor.call(this, props);
  6. this.id = props.id || Q.UIDUtil.createUID("Monkey");
  7. this.avatar = null;
  8. this.jumping = false;
  9. this.moving = false;
  10. this.mov = false;
  11. this.init();
  12. }
  13. Q.inherit(Monkey, Q.DisplayObjectContainer);
  14. Monkey.prototype.init = function()
  15. {
  16. var avatar = new Q.MovieClip({id:"monkey", image:game.getImage("monkey"), interval:120});
  17. avatar.addFrame([
  18. {rect:[0,0,223,250], label:"idle"},
  19. {rect:[223,0,223,250]},
  20. {rect:[0,250,223,250], jump:"idle"},
  21. //{rect:[217,0,217,229], jump:"idle"},
  22. {rect:[223,250,223,250], label:"jump"},
  23. ]);
  24. this.width = 223;
  25. this.height = 250;
  26. this.currentSpeedX = this.speedX = 5;
  27. this.currentSpeedY = this.speedY = 10;
  28. this.dirX = 0;
  29. this.dirY = 0;
  30. this.oldY = 0;
  31. this.avatar = avatar;
  32. this.addChild(avatar);
  33. };
  34. Monkey.prototype.move = function(dir)
  35. {
  36. if(this.moving) return;
  37. this.dirX = dir;
  38. this.currentSpeedX = this.speedX;
  39. this.moving = true;
  40. }
  41. Monkey.prototype.stopMove = function()
  42. {
  43. this.dirX = 0;
  44. this.currentSpeedX = this.speedX;
  45. this.moving = false;
  46. }
  47. Monkey.prototype.jump = function()
  48. {
  49. if(this.jumping) return;
  50. this.oldY = this.y;
  51. this.dirY = 1;
  52. this.currentSpeedY = this.speedY;
  53. this.jumping = true;
  54. this.avatar.gotoAndStop("jump");
  55. }
  56. Monkey.prototype.stopJump = function()
  57. {
  58. this.y = this.oldY;
  59. this.dirY = 0;
  60. this.jumping = false;
  61. this.avatar.gotoAndPlay("idle");
  62. }
  63. })();