BlockLong.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import GamePage from "../GamePage";
  2. const {ccclass, property} = cc._decorator;
  3. /**长条基类 */
  4. @ccclass
  5. export default class BlockLong extends cc.Component {
  6. @property({type: cc.Animation})
  7. animation: cc.Animation = null;
  8. /**是否可见 */
  9. visiable: boolean = false;
  10. /**能否被打击 */
  11. canHit: boolean = false;
  12. /**初始次数 */
  13. initCount: number = 0;
  14. /**剩余可击打次数 */
  15. count: number = 0;
  16. /**位置索引 */
  17. index: number;
  18. /**播放动画,开始该对象的逻辑 */
  19. release() {
  20. this.index = Math.random() * 3 << 0;
  21. let block_long: BlockLong;
  22. let animation_name: string;
  23. if (this.index == 1) {
  24. block_long = this.node.parent.getChildByName("block_long").getComponent(BlockLong);
  25. animation_name = "block_long";
  26. } else {
  27. block_long = this.node.parent.getChildByName("block_long_side").getComponent(BlockLong);
  28. animation_name = "block_long_side";
  29. }
  30. if (this.index == 0) {
  31. block_long.node.x = -Math.abs(block_long.node.x);
  32. block_long.node.scaleX = 1;
  33. } else if (this.index == 2) {
  34. block_long.node.x = Math.abs(block_long.node.x);
  35. block_long.node.scaleX = -1;
  36. }
  37. GamePage.instance.block_long = block_long;
  38. block_long.index = this.index;
  39. block_long.canHit = this.canHit;
  40. block_long.initCount = this.initCount;
  41. block_long.count = this.count;
  42. block_long.visiable = true;
  43. block_long.animation.play(animation_name);
  44. }
  45. /**刚进入击打线触发 */
  46. reach() {
  47. this.canHit = true;
  48. }
  49. /**完全离开击打线触发 */
  50. leave() {
  51. if (this.initCount == this.count) {
  52. GamePage.instance.miss();
  53. }
  54. GamePage.instance.countOverBeat(this.initCount);
  55. this.visiable = false;
  56. this.canHit = false;
  57. }
  58. }