GD.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. First = false;
  27. onLoad() {
  28. this.node.y = -500;
  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. if (this.First) {
  37. this.node.x = 0
  38. }
  39. }
  40. if (this.KIND_FootHold == 7) {
  41. // this.KIND_FootHold = 7;
  42. this.node.x = (Math.random() * 2 - 1) * 140;
  43. }
  44. if (this.KIND_FootHold == 1) {
  45. this.node.getChildByName("gd").getComponent("CliGD").enabled = false;
  46. }
  47. else {
  48. this.node.getChildByName("gd").getComponent("CliGD").enabled = true;
  49. }
  50. this.LifeDing = this.main.LifeDing.children;
  51. }
  52. update(dt) {
  53. // console.log(Global.instance.CollisionFlag);
  54. let self = this;
  55. // console.log("状态:"+ self.node.active+",位置:"+self.node.x);
  56. if (Global.instance.OverFlag) {
  57. self.enabled = false;
  58. }
  59. else {
  60. this.node.active = true;
  61. if (this.node.isHold) {
  62. Global.instance.CollisionFlag = true;
  63. Global.instance.TheHolder = this.node;
  64. this.node.y += Global.instance.FHFallSpeed;
  65. }
  66. else {
  67. this.node.y += Global.instance.FHFallSpeed;
  68. }
  69. if (this.node.y > 360) {
  70. if (this.node.isHold) {
  71. this.node.isHold = false;
  72. Global.instance.CollisionFlag = false;
  73. }
  74. this.node.destroy();
  75. }
  76. }
  77. }
  78. public MoveThis() {
  79. }
  80. /**
  81. * 初始化函数
  82. * @param main 主场景
  83. */
  84. public init(main: MainScene, kind?) {
  85. this.main = main;
  86. this.KIND_FootHold = kind;
  87. }
  88. /**
  89. * 获取落脚点类型
  90. */
  91. public getKind() {
  92. return this.KIND_FootHold;
  93. }
  94. onCollisionEnter(other, self) {
  95. let rootself = this;
  96. // if (rootself.GoUp) {
  97. // console.error("已经碰撞过了");
  98. // return;
  99. // }
  100. if (other.tag == 111) {
  101. rootself.main.Score();
  102. rootself.gainSc = true;
  103. // rootself.GoUp = true;
  104. return;
  105. }
  106. Global.instance.TheHolder = this.node;
  107. Global.instance.KIND_FootHold = this.KIND_FootHold;
  108. Global.instance.CollisionFlag = true;
  109. this.node.isHold = true;
  110. }
  111. }