GD.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class GD extends cc.Component {
  6. /**
  7. * 落脚点类型 1:向左传送带
  8. */
  9. private KIND_FootHold = 0;
  10. /**
  11. * player是否落在落脚点上,默认false,没有
  12. */
  13. @property(Boolean)
  14. public isHold = false;
  15. @property(Number)
  16. public NodeH:Number = 70;
  17. GoUp = false;
  18. private main:MainScene = null;
  19. /**
  20. * 落脚点对应动画
  21. */
  22. Ani:cc.Animation = null;
  23. AniState = null;
  24. LifeDing = null;
  25. gainSc = false;
  26. onLoad () {
  27. this.node.y = -500;
  28. // this.KIND_FootHold==7
  29. }
  30. start () {
  31. let moveStartT=0;
  32. let moveEndT = 0;
  33. if(this.KIND_FootHold==1){
  34. // this.KIND_FootHold = 1;
  35. this.node.x = ( Math.random()*2-1)*140;
  36. }
  37. if(this.KIND_FootHold==7){
  38. // this.KIND_FootHold = 7;
  39. this.node.x = ( Math.random()*2-1)*140;
  40. }
  41. if(this.KIND_FootHold==1){
  42. this.node.getChildByName("gd").getComponent("CliGD").enabled = false;
  43. }
  44. else{
  45. this.node.getChildByName("gd").getComponent("CliGD").enabled = true;
  46. }
  47. this.LifeDing = this.main.LifeDing.children;
  48. }
  49. update (dt) {
  50. // console.log(Global.instance.CollisionFlag);
  51. let self = this;
  52. // console.log("状态:"+ self.node.active+",位置:"+self.node.x);
  53. if(Global.instance.OverFlag){
  54. self.enabled = false;
  55. }
  56. else{
  57. this.node.active = true;
  58. if(this.node.isHold){
  59. Global.instance.CollisionFlag = true;
  60. Global.instance.TheHolder = this.node;
  61. this.node.y += Global.instance.FHFallSpeed;
  62. }
  63. else{
  64. this.node.y += Global.instance.FHFallSpeed;
  65. }
  66. if(this.node.y>360){
  67. if(this.node.isHold){
  68. this.node.isHold = false;
  69. Global.instance.CollisionFlag = false;
  70. }
  71. this.node.destroy();
  72. }
  73. }
  74. }
  75. public MoveThis(){
  76. }
  77. /**
  78. * 初始化函数
  79. * @param main 主场景
  80. */
  81. public init(main:MainScene,kind?){
  82. this.main = main;
  83. this.KIND_FootHold = kind;
  84. }
  85. /**
  86. * 获取落脚点类型
  87. */
  88. public getKind(){
  89. return this.KIND_FootHold;
  90. }
  91. onCollisionEnter(other,self){
  92. let rootself = this;
  93. if(rootself.GoUp){
  94. return;
  95. }
  96. if(other.tag == 111){
  97. // console.log("我被撞到了");
  98. rootself.main.Score();
  99. rootself.gainSc = true;
  100. rootself.GoUp = true;
  101. return;
  102. }
  103. Global.instance.TheHolder = this.node;
  104. Global.instance.KIND_FootHold = this.KIND_FootHold;
  105. Global.instance.CollisionFlag = true;
  106. this.node.isHold = true;
  107. // this.main.Score();
  108. }
  109. }