player.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // index : 0
  14. },
  15. // LIFE-CYCLE CALLBACKS:
  16. // onLoad () {},
  17. start () {
  18. player = this
  19. this.scales = 1;
  20. //管理器
  21. this.dragonBonesManager = this.getComponent("dragonBonesManager")
  22. this.dragonBonesManager.frame(function (event) {
  23. // if (event.type === dragonBones.EventObject.COMPLETE) {
  24. // if (event.animationState.name === "attack") {
  25. // Debug.Log("attack 动作播放完毕!!!");
  26. // //TODO:
  27. // }
  28. // }
  29. // Log.info("玩家是什么",event.type,event.animationState.name,event.name ,event.data,"现在状态",this.status )
  30. this.playState(this.status)
  31. }.bind(this));
  32. this.initListener()
  33. this._init()
  34. },
  35. _init(){
  36. //-1 平常 0 防御 1 左面攻击 2 右面攻击 3左面躲闪 4右面躲闪
  37. this.status = -1
  38. // var l= this.life.getComponent("lifeManager")
  39. //
  40. // Log.info("lifeManager",l.getLife())
  41. // Log.info("现在血量管理",lifes[0].getLife())
  42. // Log.info("所有动画名字 玩家",this.dragonBonesManager._init())
  43. // this.dragonBonesManager.play(this.dragonBonesManager._init()[0],function (type) {
  44. // Log.info("播放完毕 type",this.index)
  45. // // Log.info("播放完毕 listener",listener)
  46. // // Log.info("播放完毕 target",target)
  47. // }.bind(this),1)
  48. },
  49. initListener(){
  50. rival.setActionCallback(function (status) {
  51. Log.info("现在对手状态是",status)
  52. this.rivalStatus = status
  53. switch (status) {
  54. case 0:
  55. break;
  56. case 1:
  57. if (this.status != 4 && this.status != 0) {
  58. this.takeaBeating()
  59. lifes[0].addLife(strike.ATK, function () {
  60. Log.info("玩家 输了")
  61. gameManager.gameOver(1)
  62. }.bind(this))
  63. // Log.info("现在血量",lifes[1].getLife())
  64. } else {
  65. if (this.status == 0) {
  66. Log.info("现在是 破防")
  67. this.atkDefendPow(null, function () {
  68. this.takeaBeating()
  69. lifes[0].addLife(strike.ATK, function () {
  70. Log.info("玩家 输了")
  71. gameManager.gameOver(1)
  72. }.bind(this))
  73. }.bind(this))
  74. }
  75. }
  76. break;
  77. case 2:
  78. if (this.status != 3 && this.status != 0) {
  79. this.takeaBeating()
  80. lifes[0].addLife(strike.ATK, function () {
  81. Log.info("玩家 输了")
  82. gameManager.gameOver(1)
  83. }.bind(this))
  84. // Log.info("现在血量",lifes[1].getLife())
  85. } else {
  86. if (this.status == 0) {
  87. // Log.info("现在防御住了")
  88. // this.atkDefend(function () {
  89. // this.strike_leftGetThrashing()
  90. // }.bind(this))
  91. Log.info("现在是 破防")
  92. this.atkDefendPow(null, function () {
  93. this.takeaBeating()
  94. lifes[0].addLife(strike.ATK, function () {
  95. Log.info("玩家 输了")
  96. gameManager.gameOver(1)
  97. }.bind(this))
  98. }.bind(this))
  99. }
  100. }
  101. }
  102. }.bind(this))
  103. },
  104. playState(state){
  105. rival.beAttacked(state,strike.playerATKData)
  106. },
  107. atkDefendPow(data, callback) {
  108. // if (data.power >= 80) {
  109. // if (callback) {
  110. // //破防
  111. // callback();
  112. // this.initDefend();
  113. // }
  114. // }
  115. lifes[0].addDefendLife(-20,callback)
  116. },
  117. playLeft(data){
  118. if (!this.check()) {
  119. return
  120. }
  121. this.status = 1
  122. strike.playerATKData = data
  123. rival.readyATK(data)
  124. this.node.scale =new cc.Vec2(this.scales, this.scales);
  125. this.dragonBonesManager.play(this.dragonBonesManager._init()[1],function (type) {
  126. this.idle()
  127. }.bind(this),1)
  128. },
  129. playMid(data){
  130. if (!this.check()) {
  131. return
  132. }
  133. strike.playerATKData = data
  134. this.status = 0
  135. this.node.scale =new cc.Vec2(this.scales, this.scales);
  136. this.dragonBonesManager.play(this.dragonBonesManager._init()[2],function (type) {
  137. this.idle()
  138. }.bind(this),1)
  139. },
  140. playRight(data){
  141. if (!this.check()) {
  142. return
  143. }
  144. strike.playerATKData = data
  145. rival.readyATK(data)
  146. this.status = 2
  147. this.node.scale =new cc.Vec2(-this.scales, this.scales);
  148. this.dragonBonesManager.play(this.dragonBonesManager._init()[1],function (type) {
  149. this.idle()
  150. }.bind(this),1)
  151. },
  152. // //右面挨打
  153. // strike_rightGetThrashing(){
  154. // this.node.scale =new cc.Vec2(0.5, 0.5);
  155. // this.dragonBonesManager.play(this.dragonBonesManager._init()[3],function (type) {
  156. // this.idle()
  157. // }.bind(this),1)
  158. // },
  159. // //左面挨打
  160. // strike_leftGetThrashing(){
  161. // this.node.scale =new cc.Vec2(-0.5, 0.5);
  162. // this.dragonBonesManager.play(this.dragonBonesManager._init()[3],function (type) {
  163. // this.idle()
  164. // }.bind(this),1)
  165. // },
  166. //右面躲闪
  167. strike_rightMiss(data){
  168. if (!this.check()) {
  169. return
  170. }
  171. this.status = 4
  172. strike.playerATKData = data
  173. this.node.scale =new cc.Vec2(-this.scales, this.scales);
  174. this.dragonBonesManager.play(this.dragonBonesManager._init()[3],function (type) {
  175. this.idle()
  176. }.bind(this),1)
  177. },
  178. //左面躲闪
  179. strike_leftMiss(data){
  180. if (!this.check()) {
  181. return
  182. }
  183. this.status = 3
  184. strike.playerATKData = data
  185. this.node.scale =new cc.Vec2(this.scales, this.scales);
  186. this.dragonBonesManager.play(this.dragonBonesManager._init()[3],function (type) {
  187. this.idle()
  188. }.bind(this),1)
  189. },
  190. idle(){
  191. this.node.scale =new cc.Vec2(this.scales, this.scales);
  192. this.dragonBonesManager.playNotEvent(this.dragonBonesManager._init()[0],0)
  193. this.status = -1
  194. },
  195. check(){
  196. var b = false
  197. if (this.status == -1) {
  198. b = true
  199. }
  200. return b
  201. },
  202. takeaBeating(){
  203. game.startAn();
  204. }
  205. // update (dt) {},
  206. });