tanhuang.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class tanhuang extends cc.Component {
  6. /**
  7. * 落脚点类型 2:tanhuang
  8. */
  9. private KIND_FootHold = 2;
  10. /**
  11. * player是否落在落脚点上,默认false,没有
  12. */
  13. @property(Boolean)
  14. public isHold = false;
  15. @property(Number)
  16. public NodeH:number = 60;
  17. GoUp = false;
  18. private gainSc = false;//弹簧加分标志
  19. private main:MainScene = null;
  20. /**
  21. * 落脚点对应动画
  22. */
  23. Ani:cc.Animation = null;
  24. AniState = null;
  25. Ding;
  26. onLoad () {
  27. this.node.y = -500;
  28. this.node.x = ( Math.random()*2-1)*140;
  29. this.Ani = this.node.getComponent(cc.Animation);
  30. this.gainSc = false;
  31. }
  32. start () {
  33. this.Ding = this.main.node.getChildByName("BgNode").getChildByName("LifeDing").getChildByName("ding");
  34. }
  35. update (dt) {
  36. // console.log(Global.instance.CollisionFlag);
  37. let self = this;
  38. if(Global.instance.OverFlag){
  39. self.enabled = false;
  40. }
  41. else{
  42. this.node.active = true;
  43. this.node.y += Global.instance.FHFallSpeed;
  44. if(this.node.isHold){
  45. Global.instance.CollisionFlag = true;
  46. Global.instance.TheHolder = this.node;
  47. }
  48. if(this.node.y>360){
  49. if(this.node.isHold){
  50. Global.instance.CollisionFlag = false;
  51. this.node.isHold = false;
  52. }
  53. this.node.destroy();
  54. }
  55. }
  56. }
  57. /**
  58. * 初始化函数
  59. * @param main 主场景
  60. */
  61. public init(main:MainScene){
  62. this.main = main;
  63. }
  64. /**
  65. * 获取落脚点类型
  66. */
  67. public getKind(){
  68. return this.KIND_FootHold;
  69. }
  70. /**
  71. * 碰撞
  72. * @param other 碰撞主体player
  73. * @param self 碰撞主体落脚点tanhuang
  74. */
  75. onCollisionEnter(other,self){
  76. let rootself = this;
  77. if(rootself.GoUp){
  78. return;
  79. }
  80. if(rootself.main ==null){
  81. rootself.main = Global.instance.getMN();
  82. }
  83. if(other.tag===111){
  84. if(rootself.gainSc==false){
  85. rootself.main.Score();
  86. rootself.gainSc = true;
  87. rootself.GoUp = true;
  88. }
  89. return;
  90. }
  91. else{
  92. Global.instance.KIND_FootHold = rootself.KIND_FootHold;
  93. if(!Global.instance.CollisionFlag){
  94. Global.instance.CollisionFlag = true;
  95. Global.instance.TheHolder = rootself.node;
  96. rootself.isHold = true;
  97. other.node.y = self.node.y+60;
  98. let spawn;
  99. spawn = cc.spawn(cc.callFunc(function(){
  100. if(rootself.Ani==null){
  101. return;
  102. }
  103. rootself.AniState = rootself.Ani.play("tanhuang");
  104. rootself.AniState.speed = 0.8;
  105. }),cc.callFunc(function(){
  106. other.node.runAction(cc.moveBy(0.15,0,50));
  107. Global.instance.CollisionFlag = false;
  108. rootself.isHold = false;
  109. other.node.getComponent("Playcontroler").enabled = false;
  110. }));
  111. rootself.scheduleOnce(()=>{
  112. other.node.getComponent("Playcontroler").enabled = true;
  113. },0.27);
  114. rootself.scheduleOnce(function(){
  115. // console.log(Global.instance.CollisionFlag+"5")
  116. Global.instance.CollisionFlag = false;
  117. rootself.isHold = false;
  118. rootself.Ani.stop();
  119. },0.41);
  120. other.node.runAction(spawn);
  121. }
  122. }
  123. }
  124. }