ball.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // 对手削球,从右侧到右侧
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. },
  6. // LIFE-CYCLE CALLBACKS:
  7. onLoad () {
  8. this.initValues();
  9. this.initNodes();
  10. },
  11. // start () {
  12. // this.rivalPeelLtoR_01();
  13. // this.ballAction();
  14. // },
  15. // update() {
  16. // var beginPos = cc.v2(-95, 264);
  17. // var centerPos = cc.v2(30, 5);
  18. // var endPos = cc.v2(163, -140);
  19. // this.g.lineWidth = 4;
  20. // this.g.moveTo(beginPos.x, beginPos.y);
  21. // this.g.bezierCurveTo(beginPos.x, beginPos.y, -270, 440, centerPos.x, centerPos.y);
  22. // this.g.bezierCurveTo(centerPos.x, centerPos.y, 110, 20, endPos.x, endPos.y);
  23. // this.g.stroke();
  24. // },
  25. // 初始化
  26. initValues:function () {
  27. // 配置绘制的数据
  28. // 从配置中心获取数据
  29. this.gameconfig = require ("gameconfig")
  30. // 配置绘制组件
  31. this.g = this.getComponent(cc.Graphics);
  32. // 球的状态
  33. this.ballconfig = require("ballconfig");
  34. // 记录下节点
  35. this.poses = new Array();
  36. // 记录是否需要撞击的效果
  37. this.showBump = false;
  38. // 速度
  39. this.speed = 100.0;
  40. },
  41. // 初始化子节点
  42. initNodes:function() {
  43. this.head = new cc.Node("");
  44. this.head.setPosition(cc.v2(0, 0));
  45. this.head.parent = this.node;
  46. },
  47. // 外部调用
  48. // 球的运动停止
  49. ballStop:function() {
  50. // 首先停止所有动作
  51. this.head.stopAllActions();
  52. // 清空节点数组
  53. this.poses = [];
  54. this.g.clear();
  55. },
  56. // 全部停止
  57. ballEnd:function() {
  58. this.unschedule(this.ballUpdate);
  59. // 首先停止所有动作
  60. this.head.stopAllActions();
  61. // 清空节点数组
  62. this.poses = [];
  63. this.g.clear();
  64. },
  65. // 球开始运动,开始刷新帧
  66. ballAction:function() {
  67. this.schedule(this.ballUpdate, 1 / 60);
  68. },
  69. // 我方接球,从左到左
  70. minePatLToL_01:function() {
  71. if(this.stateCallback != null) {
  72. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  73. }
  74. var beginPos = cc.v2(-103, -110);
  75. var dropPos = cc.v2(-64, 144);
  76. var endPos = cc.v2(-53, 313);
  77. // 将节点移动到指定位置
  78. this.head.setPosition(beginPos);
  79. var bezier_01 = [beginPos, cc.v2(-82, 20), dropPos];
  80. var bezier_02 = [dropPos, cc.v2(-68, 220), endPos];
  81. var move_01 = cc.bezierTo(this.speed / 300, bezier_01);
  82. var self = this;
  83. var move_01_end = cc.callFunc(function() {
  84. self.bump(dropPos);
  85. });
  86. var move_02_time = this.speed / 300;
  87. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  88. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  89. var delay = cc.delayTime(move_02_time / 4);
  90. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_LEFT_PAT);
  91. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  92. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
  93. var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
  94. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  95. },
  96. // 我方接球,从右到右
  97. minePatRToR_01:function() {
  98. if(this.stateCallback != null) {
  99. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  100. }
  101. var beginPos = cc.v2(52, -109);
  102. var dropPos = cc.v2(71, 141);
  103. var endPos = cc.v2(131, 309);
  104. // 将节点移动到指定位置
  105. this.head.setPosition(beginPos);
  106. var bezier_01 = [beginPos, cc.v2(61, 16), dropPos];
  107. var bezier_02 = [dropPos, cc.v2(40, 289), endPos];
  108. var move_01 = cc.bezierTo(this.speed / 350, bezier_01);
  109. var self = this;
  110. var move_01_end = cc.callFunc(function() {
  111. self.bump(dropPos);
  112. });
  113. var move_02_time = this.speed / 150;
  114. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  115. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  116. var delay = cc.delayTime(move_02_time / 4);
  117. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
  118. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  119. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
  120. var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
  121. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  122. },
  123. // 我方接球,从左到右
  124. minePatLToR_01:function() {
  125. if(this.stateCallback != null) {
  126. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  127. }
  128. var beginPos = cc.v2(-103, -76);
  129. var dropPos = cc.v2(47, 140);
  130. var endPos = cc.v2(221, 346);
  131. // 将节点移动到指定位置
  132. this.head.setPosition(beginPos);
  133. var bezier_01 = [beginPos, cc.v2(-52, 20), dropPos];
  134. var bezier_02 = [dropPos, cc.v2(22, 340), endPos];
  135. var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
  136. var self = this;
  137. var move_01_end = cc.callFunc(function() {
  138. self.bump(dropPos);
  139. });
  140. var move_02_time = this.speed / 150;
  141. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  142. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  143. var delay = cc.delayTime(move_02_time / 4);
  144. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
  145. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  146. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
  147. var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
  148. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  149. },
  150. // 我方削球,从右到左
  151. minePeelRToL_01:function() {
  152. if(this.stateCallback != null) {
  153. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  154. }
  155. var beginPos = cc.v2(128, -117);
  156. var dropPos = cc.v2(-66, 143);
  157. var endPos = cc.v2(-134, 308);
  158. // 将节点移动到指定位置
  159. this.head.setPosition(beginPos);
  160. var bezier_01 = [beginPos, cc.v2(31, 15), dropPos];
  161. var bezier_02 = [dropPos, cc.v2(-75, 300), endPos];
  162. var move_01 = cc.bezierTo(this.speed / 150, bezier_01);
  163. var self = this;
  164. var move_01_end = cc.callFunc(function() {
  165. self.bump(dropPos);
  166. });
  167. var move_02_time = this.speed / 150;
  168. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  169. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  170. var delay = cc.delayTime(move_02_time / 4);
  171. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_LEFT_PEEL);
  172. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  173. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
  174. var jump = cc.jumpBy(1, cc.v2(-50, 40), 30, 2);
  175. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  176. },
  177. // 我方削球,从右到右
  178. minePeelRToR_01:function() {
  179. if(this.stateCallback != null) {
  180. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  181. }
  182. var beginPos = cc.v2(148, -176);
  183. var dropPos = cc.v2(79, 99);
  184. var endPos = cc.v2(104, 319);
  185. // 将节点移动到指定位置
  186. this.head.setPosition(beginPos);
  187. var bezier_01 = [beginPos, cc.v2(180, -20), dropPos];
  188. var bezier_02 = [dropPos, cc.v2(92, 210), endPos];
  189. var move_01 = cc.bezierTo(this.speed / 250, bezier_01);
  190. var self = this;
  191. var move_01_end = cc.callFunc(function() {
  192. self.bump(dropPos);
  193. });
  194. var move_02_time = this.speed / 200;
  195. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  196. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  197. var delay = cc.delayTime(move_02_time / 2);
  198. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_RIVAL_RIGHT_PAT);
  199. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  200. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_RIVAL);
  201. var jump = cc.jumpBy(1, cc.v2(50, 40), 30, 2);
  202. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  203. },
  204. // 对手发球
  205. rivalServer:function() {
  206. if(this.stateCallback != null) {
  207. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  208. }
  209. var serverBegin = cc.v2(166, 290);
  210. var beatPos = cc.v2(96, 274);
  211. var dropPos = cc.v2(28, 144);
  212. var jumpPos = cc.v2(-14, 21);
  213. var endPos = cc.v2(-147, -161);
  214. // 将节点移动到指定位置
  215. this.head.setPosition(serverBegin);
  216. // 4条贝塞尔曲线
  217. var bezier_01 = [serverBegin, cc.v2(125, 400), beatPos];
  218. var bezier_02 = [beatPos, cc.v2(45, 250), dropPos];
  219. var bezier_03 = [dropPos, cc.v2(0, 56), jumpPos];
  220. var bezier_04 = [jumpPos, cc.v2(-80, 10), endPos];
  221. // 四条路线
  222. var move_01 = cc.bezierTo(1.2, bezier_01);
  223. var move_02 = cc.bezierTo(this.speed / 750, bezier_02);
  224. var move_03 = cc.bezierTo(this.speed / 1000, bezier_03);
  225. var self = this;
  226. var move_03_end = cc.callFunc(function() {
  227. self.bump(jumpPos);
  228. });
  229. var move_04_time = this.speed / 350;
  230. var move_04 = cc.bezierTo(move_04_time, bezier_04);
  231. // 在第四条路线后开始的一段时间,需要通知控制器改变状态
  232. var delay = cc.delayTime(move_04_time / 3);
  233. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
  234. var spawn = cc.spawn(move_04, cc.sequence(delay, change));
  235. var move_04_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  236. var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 4);
  237. this.head.runAction(cc.sequence(move_01, move_02, move_03, move_03_end, spawn, move_04_end, jump));
  238. },
  239. // 对手接球,从右到左
  240. rivalPatRToL_01:function() {
  241. if(this.stateCallback != null) {
  242. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  243. }
  244. var beginPos = cc.v2(112, 328);
  245. var dropPos = cc.v2(-22, 16);
  246. var endPos = cc.v2(-122, -182);
  247. // 将节点移动到指定位置
  248. this.head.setPosition(beginPos);
  249. // 贝塞尔曲线的关键点
  250. var bezier_01 = [beginPos, cc.v2(45, 172), dropPos];
  251. var bezier_02 = [dropPos, cc.v2(-120, -10), endPos];
  252. // 第一条路线
  253. var move_01 = cc.bezierTo(this.speed / 300, bezier_01);
  254. var self = this;
  255. // 中间碰到了桌面
  256. var move_01_end = cc.callFunc(function() {
  257. self.bump(dropPos);
  258. });
  259. var move_02_time = this.speed / 200;
  260. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  261. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  262. var delay = cc.delayTime(move_02_time / 4);
  263. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
  264. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  265. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  266. var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 3);
  267. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  268. },
  269. // 对手接球,第二种从右到左
  270. rivalPatRToL_02:function() {
  271. if(this.stateCallback != null) {
  272. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  273. }
  274. var beginPos = cc.v2(103, 272);
  275. var dropPos = cc.v2(-15, 23);
  276. var endPos = cc.v2(-135, -123);
  277. // 将节点移动到指定位置
  278. this.head.setPosition(beginPos);
  279. // 贝塞尔曲线的关键点
  280. var bezier_01 = [beginPos, cc.v2(-15, 350), dropPos];
  281. var bezier_02 = [dropPos, cc.v2(-85, 65), endPos];
  282. // 第一条路线
  283. var move_01 = cc.bezierTo(this.speed / 250, bezier_01);
  284. var self = this;
  285. // 中间碰到了桌面
  286. var move_01_end = cc.callFunc(function() {
  287. self.bump(dropPos);
  288. });
  289. var move_02_time = this.speed / 150;
  290. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  291. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  292. var delay = cc.delayTime(move_02_time / 4);
  293. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
  294. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  295. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  296. var jump = cc.jumpBy(1, cc.v2(-100, -40), 30, 3);
  297. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  298. },
  299. // 对手接球,从左到左
  300. rivalPatLToL_01:function() {
  301. if(this.stateCallback != null) {
  302. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  303. }
  304. var beginPos = cc.v2(-53, 272);
  305. var dropPos = cc.v2(-73, 10);
  306. var endPos = cc.v2(-127, -171);
  307. // 将节点移动到指定位置
  308. this.head.setPosition(beginPos);
  309. // 贝塞尔曲线的关键点
  310. var bezier_01 = [beginPos, cc.v2(-63, 149), dropPos];
  311. var bezier_02 = [dropPos, cc.v2(-95, -40), endPos];
  312. // 第一条路线
  313. var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
  314. var self = this;
  315. // 中间碰到了桌面
  316. var move_01_end = cc.callFunc(function() {
  317. self.bump(dropPos);
  318. });
  319. var move_02_time = this.speed / 250;
  320. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  321. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  322. var delay = cc.delayTime(move_02_time / 4);
  323. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
  324. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  325. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  326. var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
  327. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  328. },
  329. // 对手接球,从左到右
  330. rivalPatLToR_01:function() {
  331. if(this.stateCallback != null) {
  332. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  333. }
  334. var beginPos = cc.v2(-56, 298);
  335. var dropPos = cc.v2(25, 13);
  336. var endPos = cc.v2(95, -115);
  337. // 将节点移动到指定位置
  338. this.head.setPosition(beginPos);
  339. // 贝塞尔曲线的关键点
  340. var bezier_01 = [beginPos, cc.v2(4, 145), dropPos];
  341. var bezier_02 = [dropPos, cc.v2(95, -35), endPos];
  342. // 第一条路线
  343. var move_01 = cc.bezierTo(this.speed / 400, bezier_01);
  344. var self = this;
  345. // 中间碰到了桌面
  346. var move_01_end = cc.callFunc(function() {
  347. self.bump(dropPos);
  348. });
  349. var move_02_time = this.speed / 200;
  350. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  351. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  352. var delay = cc.delayTime(move_02_time / 4);
  353. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PEEL);
  354. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  355. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  356. var jump = cc.jumpBy(1, cc.v2(40, -40), 30, 2);
  357. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  358. },
  359. // 对手接球,从右到右
  360. rivalPatRToR_01:function() {
  361. if(this.stateCallback != null) {
  362. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  363. }
  364. var beginPos = cc.v2(101, 271);
  365. var dropPos = cc.v2(49, 29);
  366. var endPos = cc.v2(24, -171);
  367. // 将节点移动到指定位置
  368. this.head.setPosition(beginPos);
  369. // 贝塞尔曲线的关键点
  370. var bezier_01 = [beginPos, cc.v2(50, 450), dropPos];
  371. var bezier_02 = [dropPos, cc.v2(15, 95), endPos];
  372. // 第一条路线
  373. var move_01 = cc.bezierTo(this.speed / 200, bezier_01);
  374. var self = this;
  375. // 中间碰到了桌面
  376. var move_01_end = cc.callFunc(function() {
  377. self.bump(dropPos);
  378. });
  379. var move_02_time = this.speed / 250;
  380. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  381. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  382. var delay = cc.delayTime(move_02_time / 4);
  383. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PAT);
  384. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  385. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  386. var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
  387. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  388. },
  389. // 对手接球,第二种从右到右
  390. rivalPatRToR_02:function() {
  391. if(this.stateCallback != null) {
  392. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  393. }
  394. var beginPos = cc.v2(98, 273);
  395. var dropPos = cc.v2(49, 21);
  396. var endPos = cc.v2(28, -130);
  397. // 将节点移动到指定位置
  398. this.head.setPosition(beginPos);
  399. // 贝塞尔曲线的关键点
  400. var bezier_01 = [beginPos, cc.v2(68, 147), dropPos];
  401. var bezier_02 = [dropPos, cc.v2(15, -20), endPos];
  402. // 第一条路线
  403. var move_01 = cc.bezierTo(this.speed / 200, bezier_01);
  404. var self = this;
  405. // 中间碰到了桌面
  406. var move_01_end = cc.callFunc(function() {
  407. self.bump(dropPos);
  408. });
  409. var move_02_time = this.speed / 150;
  410. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  411. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  412. var delay = cc.delayTime(move_02_time / 4);
  413. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PAT);
  414. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  415. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  416. var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
  417. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  418. },
  419. // 对手削球,从左到左
  420. rivalPeelLtoL_01:function() {
  421. if(this.stateCallback != null) {
  422. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  423. }
  424. var beginPos = cc.v2(-95, 263);
  425. var centerPos = cc.v2(-75, 58);
  426. var endPos = cc.v2(-66, -163);
  427. // 将节点移动到指定位置
  428. this.head.setPosition(beginPos);
  429. var bezier_01 = [beginPos, cc.v2(-230, 410), centerPos];
  430. var move_01 = cc.bezierTo(this.speed / 180, bezier_01);
  431. var move_01_end = cc.callFunc(function() {
  432. this.bump(centerPos);
  433. }, this);
  434. var bezier_02 = [centerPos, cc.v2(-125, 40), endPos];
  435. var move_02_time = this.speed / 180;
  436. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  437. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  438. var delay = cc.delayTime(move_02_time / 4);
  439. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_LEFT_PAT);
  440. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  441. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  442. var jump = cc.jumpBy(1, cc.v2(-40, -40), 30, 2);
  443. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  444. },
  445. // 对手削球,从左到右
  446. rivalPeelLtoR_01:function() {
  447. if(this.stateCallback != null) {
  448. this.stateCallback(this.ballconfig.BALL_STATE_FLYING);
  449. }
  450. var beginPos = cc.v2(-95, 264);
  451. var centerPos = cc.v2(30, 5);
  452. var endPos = cc.v2(163, -140);
  453. // 将节点移动到指定位置
  454. this.head.setPosition(beginPos);
  455. var bezier_01 = [beginPos, cc.v2(-270, 440), centerPos];
  456. var move_01 = cc.bezierTo(this.speed / 180, bezier_01);
  457. var move_01_end = cc.callFunc(function() {
  458. this.bump(centerPos);
  459. }, this);
  460. var bezier_02 = [centerPos, cc.v2(110, 20), endPos];
  461. var move_02_time = this.speed / 150;
  462. var move_02 = cc.bezierTo(move_02_time, bezier_02);
  463. // 在第二条路线后开始的一段时间,需要通知控制器改变状态
  464. var delay = cc.delayTime(move_02_time / 4);
  465. var change = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_MINE_RIGHT_PEEL);
  466. var spawn = cc.spawn(move_02, cc.sequence(delay, change));
  467. var move_02_end = cc.callFunc(this.changeState, this, this.ballconfig.BALL_STATE_DROP_IN_MINE);
  468. var jump = cc.jumpBy(1, cc.v2(40, -40), 30, 2);
  469. this.head.runAction(cc.sequence(move_01, move_01_end, spawn, move_02_end, jump));
  470. },
  471. // 球磕碰
  472. bump:function(loc) {
  473. this.bumpLoc = loc;
  474. this.bumpTime = 0;
  475. this.showBump = true;
  476. },
  477. // 更改状态
  478. changeState:function(node, state) {
  479. // cc.log ("改变状态 ... " + state);
  480. if(this.stateCallback != null) {
  481. this.stateCallback(state);
  482. }
  483. },
  484. // 绘图
  485. draw:function(delay) {
  486. this.g.clear();
  487. // 画脑袋和身体
  488. this.g.lineWidth = this.gameconfig.CIRCLE_WIDTH
  489. // 画个头部
  490. this.g.fillColor.fromHEX('#ff00000');
  491. this.g.circle(this.head.x, this.head.y, this.gameconfig.HEAD_SIZE);
  492. this.g.close();
  493. this.g.stroke();
  494. this.g.fill();
  495. var pos = this.poses[0];
  496. this.g.lineWidth = 3;
  497. this.g.moveTo(pos.x, pos.y)
  498. for (var i = 0; i < this.poses.length; i++) {
  499. var getPos = this.poses[i];
  500. this.g.lineTo(getPos.x, getPos.y);
  501. }
  502. this.g.stroke();
  503. // 当需要绘制撞击点时
  504. if (this.showBump) {
  505. this.bumpTime += delay;
  506. var timeScale = 15;
  507. var space = 1;
  508. var low = 2.5;
  509. var high = 10;
  510. // 右上
  511. this.g.lineWidth = 3;
  512. this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
  513. this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
  514. this.g.stroke();
  515. // 右下
  516. this.g.lineWidth = 3;
  517. this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
  518. this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
  519. this.g.stroke();
  520. // 左上
  521. this.g.lineWidth = 3;
  522. this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
  523. this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
  524. this.g.stroke();
  525. // 右下
  526. this.g.lineWidth = 3;
  527. this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
  528. this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
  529. this.g.stroke();
  530. if (this.bumpTime > 0.1) {
  531. this.showBump = false;
  532. }
  533. }
  534. },
  535. // 帧更新
  536. ballUpdate:function (dt) {
  537. // 记录当前的位置
  538. var news = [this.head.position];
  539. // 在结合当前的数组
  540. this.poses = news.concat(this.poses);
  541. // 如果数组长度大于20,则将最后一个删除
  542. if (this.poses.length > 10) {
  543. this.poses.pop();
  544. }
  545. this.draw(dt);
  546. },
  547. });