BasePlayerController.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. gameStates: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. },
  9. topHole: {
  10. default: null,
  11. type: cc.Node,
  12. serializable: true,
  13. },
  14. leftHole: {
  15. default: null,
  16. type: cc.Node,
  17. serializable: true,
  18. },
  19. rightHole: {
  20. default: null,
  21. type: cc.Node,
  22. serializable: true,
  23. },
  24. avatar: {
  25. default: null,
  26. type: cc.Sprite,
  27. serializable: true,
  28. },
  29. playerName: {
  30. default: null,
  31. type: cc.Label,
  32. serializable: true,
  33. },
  34. score: {
  35. default: null,
  36. type: cc.Label,
  37. serializable: true,
  38. },
  39. gender: {
  40. default: null,
  41. type: cc.Node,
  42. serializable: true,
  43. },
  44. bAi:true
  45. },
  46. onLoad () {
  47. this.init();
  48. },
  49. init()
  50. {
  51. this.topHoleScpt = this.topHole.getComponent('Actor');
  52. this.leftHoleScpt = this.leftHole.getComponent('Actor');
  53. this.rightHoleScpt = this.rightHole.getComponent('Actor');
  54. this.gameStatesScpt = this.gameStates.getComponent('GameStates');
  55. },
  56. left()
  57. {
  58. if(this.leftHoleScpt.bDie) return;
  59. this.leftHoleScpt.leftPunch(this.bAi);
  60. this.hit();
  61. },
  62. top()
  63. {
  64. if(this.topHoleScpt.bDie) return;
  65. this.topHoleScpt.punch(this.bAi);
  66. this.hit();
  67. },
  68. right()
  69. {
  70. if(this.rightHoleScpt.bDie) return;
  71. this.rightHoleScpt.rightPunch(this.bAi);
  72. this.hit();
  73. },
  74. });