FStoneDrop.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import FF from "../../FF";
  2. import FSprite from "../../object/FSprite";
  3. /**
  4. * 掉落的石头
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class FStoneDrop extends cc.Component {
  9. @property({
  10. displayName: '数值(怪物id)'
  11. })
  12. public monsterId = 1001;
  13. @property({
  14. displayName: '每次滚动停留时间(秒)'
  15. })
  16. public interval = 2;
  17. @property({
  18. type: sp.Skeleton,
  19. displayName: '滚动动画'
  20. })
  21. public spine: sp.Skeleton = null;
  22. @property({
  23. displayName: "警告",
  24. type: cc.Node
  25. })
  26. warnNode: cc.Node = null;
  27. private ff: FF;
  28. private isRoll = false;
  29. private isHit: boolean = false;
  30. private isWarn: boolean = false;
  31. private tempTime: number = 0;
  32. public spriteList: Array<FSprite> = [];
  33. callFunc: Function = null;
  34. onLoad() {
  35. cc.tween(this.node).sequence(
  36. cc.delayTime(this.interval),
  37. cc.fadeIn(0),
  38. cc.callFunc(() => {
  39. this.isRoll = true;
  40. this.spine.setAnimation(0, "atk", false);
  41. // this.spine.setEndListener(() => {
  42. // this.isRoll = false;
  43. // this.isHit = false;
  44. // })
  45. }),
  46. cc.delayTime(1),
  47. cc.fadeOut(0.2),
  48. cc.callFunc(() => {
  49. this.isRoll = false;
  50. this.isHit = false;
  51. this.tempTime = 0;
  52. this.isWarn = false;
  53. })
  54. ).repeatForever().start();
  55. }
  56. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  57. if (other.node.group == 'A' && other.tag == 1) {
  58. let obj = other.node.getComponent(FSprite);
  59. this.ff = obj.ff;
  60. if (this.spriteList.indexOf(obj) == -1) {
  61. this.spriteList.push(obj);
  62. }
  63. }
  64. }
  65. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  66. if (other.node.group == 'A' && other.tag == 1) {
  67. let obj = other.node.getComponent(FSprite);
  68. this.removeSprite(obj);
  69. this.isHit = false;
  70. }
  71. }
  72. removeSprite(sprite: FSprite) {
  73. for (let i = 0; i < this.spriteList.length; i++) {
  74. const element = this.spriteList[i];
  75. if (element == sprite) {
  76. this.spriteList.splice(i, 1);
  77. break
  78. }
  79. }
  80. }
  81. hit() {
  82. this.isHit = true;
  83. this.spriteList.forEach(sprite => {
  84. let main = this.ff.main;
  85. let attrData = main.sManage.getMonsterData(this.monsterId);
  86. sprite.bAtkjs(attrData)
  87. })
  88. }
  89. warnAction() {
  90. if (this.isWarn) return
  91. this.warnNode.stopActionByTag(1);
  92. this.isWarn = true;
  93. this.warnNode.opacity = 0;
  94. let action = cc.tween(this.warnNode).sequence(
  95. cc.fadeIn(0.1),
  96. cc.fadeOut(0.1),
  97. ).repeat(6).start();
  98. action.tag(1);
  99. }
  100. update(dt) {
  101. if (this.isRoll && !this.isHit) {
  102. this.hit();
  103. }
  104. this.tempTime += dt;
  105. if (this.interval - this.tempTime <= 1) {
  106. this.warnAction();
  107. }
  108. }
  109. }