win.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // 胜利的动作
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. loc: 0, // 代表方向,0为正位,1为反位
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. // 配置绘制的数据
  10. // 从配置中心获取数据
  11. this.config = require ("gameconfig")
  12. // 配置绘制组件
  13. this.g = this.getComponent(cc.Graphics);
  14. // 配置方向
  15. if (this.loc == 0) {
  16. this.dir = 1;
  17. } else {
  18. this.dir = -1;
  19. }
  20. },
  21. start () {
  22. },
  23. win:function() {
  24. this.g.clear();
  25. // 画脑袋和身体
  26. this.g.lineWidth = this.config.CIRCLE_WIDTH
  27. // 画个脑袋
  28. this.g.fillColor.fromHEX('#ffffff');
  29. this.g.circle(this.dir * -42, 77, this.config.HEAD_SIZE);
  30. this.g.close();
  31. this.g.stroke();
  32. this.g.fill();
  33. // 画个身体
  34. this.g.fillColor.fromHEX('#ffffff');
  35. this.g.circle(this.dir * -31, 51, this.config.BODY_SIZE);
  36. this.g.close();
  37. this.g.stroke();
  38. this.g.fill();
  39. // 画手臂
  40. var handStart = cc.v2(this.dir * -21, 63);
  41. var handEnd = cc.v2(this.dir * -23, 109);
  42. this.g.lineWidth = this.config.LINE_WIDTH;
  43. this.g.moveTo(handStart.x, handStart.y);
  44. this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -7, 82, handEnd.x, handEnd.y);
  45. this.g.stroke();
  46. // 画个球拍
  47. this.g.lineWidth = this.config.CIRCLE_WIDTH
  48. this.g.fillColor.fromHEX('#ffffff');
  49. this.g.circle(this.dir * -28, 105, this.config.BAT_SIZE);
  50. this.g.close();
  51. this.g.stroke();
  52. this.g.fill();
  53. // 画手臂
  54. var handStart = cc.v2(this.dir * -45, 56);
  55. var handEnd = cc.v2(this.dir * -65, 102);
  56. this.g.lineWidth = this.config.LINE_WIDTH;
  57. this.g.moveTo(handStart.x, handStart.y);
  58. this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -70, 65, handEnd.x, handEnd.y);
  59. this.g.stroke();
  60. // 画裤子
  61. var trousersStart = cc.v2(this.dir * -41, 41);
  62. var trousersEnd = cc.v2(this.dir * -19, 45);
  63. this.g.moveTo(trousersStart.x, trousersStart.y);
  64. this.g.lineTo(trousersEnd.x, trousersEnd.y);
  65. this.g.stroke();
  66. // 画腿
  67. var legStart = cc.v2(this.dir * -39, 40);
  68. var legEnd = cc.v2(this.dir * -61, 0)
  69. this.g.moveTo(legStart.x, legStart.y);
  70. this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -95, 50, legEnd.x, legEnd.y);
  71. this.g.lineTo(this.dir * -67, 0);
  72. this.g.stroke();
  73. legStart = cc.v2(this.dir * -20, 42);
  74. legEnd = cc.v2(this.dir * 8, 0)
  75. this.g.moveTo(legStart.x, legStart.y);
  76. this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 12, 45, legEnd.x, legEnd.y);
  77. this.g.lineTo(this.dir * 18, 0);
  78. this.g.stroke();
  79. // 再跳动两下
  80. var jump = cc.jumpBy(0.5, cc.v2(0, 0), 20, 3);
  81. this.node.runAction(jump);
  82. },
  83. });