fail.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. fail: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 * 1, 36, 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 * 27, 46, this.config.BODY_SIZE);
  36. this.g.close();
  37. this.g.stroke();
  38. this.g.fill();
  39. // 画手臂
  40. var handStart = cc.v2(this.dir * 16, 36);
  41. var handEnd = cc.v2(this.dir * 6, 1);
  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 * 16, 5, 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 * 2, 5, this.config.BAT_SIZE);
  50. this.g.close();
  51. this.g.stroke();
  52. this.g.fill();
  53. // 画手臂
  54. var handStart = cc.v2(this.dir * 20, 51);
  55. var handEnd = cc.v2(this.dir * 12, -1);
  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 * 25, 0, handEnd.x, handEnd.y);
  59. this.g.stroke();
  60. // 画裤子
  61. var trousersStart = cc.v2(this.dir * 39, 53);
  62. var trousersEnd = cc.v2(this.dir * 30, 32);
  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 * 27, 32);
  68. var legMid = cc.v2(this.dir * 26, 7);
  69. var legEnd = cc.v2(this.dir * 55, 8)
  70. this.g.moveTo(legStart.x, legStart.y);
  71. this.g.lineTo(legMid.x, legMid.y)
  72. this.g.bezierCurveTo(legMid.x, legMid.y, this.dir * 20, 0, legEnd.x, legEnd.y);
  73. this.g.lineTo(this.dir * 60, 5);
  74. this.g.stroke();
  75. legStart = cc.v2(this.dir * 38, 36);
  76. legMid = cc.v2(this.dir * 35, 5);
  77. legEnd = cc.v2(this.dir * 69, 3)
  78. this.g.moveTo(legStart.x, legStart.y);
  79. this.g.lineTo(legMid.x, legMid.y)
  80. this.g.bezierCurveTo(legMid.x, legMid.y, this.dir * 30, 0, legEnd.x, legEnd.y);
  81. this.g.lineTo(this.dir * 72, -2);
  82. this.g.stroke();
  83. },
  84. });