lvdai.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class lvdai extends cc.Component {
  6. /**
  7. * 落脚点类型 3/4:传送带
  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 = 60;
  17. GoUp = false;
  18. private main:MainScene = null;
  19. /**
  20. * 落脚点对应动画
  21. */
  22. Ani:cc.Animation = null;
  23. AniState = null;
  24. gainSc = false;
  25. onLoad () {
  26. let kind = Math.random();
  27. this.node.y = -500;
  28. this.node.x = ( Math.random()*2-1)*140;
  29. this.Ani = this.node.getComponent(cc.Animation);
  30. this.AniState = this.Ani.play("lvdai");
  31. if(kind<=0.5){
  32. this.KIND_FootHold = 3;
  33. }
  34. else{
  35. this.KIND_FootHold = 4;
  36. this.AniState.wrapMode = cc.WrapMode.Reverse;//设置动画的播放方式为倒放
  37. }
  38. this.AniState.repeatCount = 100;
  39. this.AniState.speed = 2;
  40. /**
  41. * 这里有点问题,设置模式貌似不奏效。一旦成功可以减小包体
  42. */
  43. }
  44. start () {
  45. }
  46. update (dt) {
  47. // console.log(Global.instance.CollisionFlag);
  48. let self = this;
  49. if(Global.instance.OverFlag){
  50. self.enabled = false;
  51. }
  52. else{
  53. this.node.active = true;
  54. this.node.y += Global.instance.FHFallSpeed;
  55. if(this.node.isHold){
  56. Global.instance.CollisionFlag = true;
  57. Global.instance.TheHolder = this.node;
  58. }
  59. if(this.node.y>360){
  60. if(this.node.isHold){
  61. this.node.isHold = false;
  62. Global.instance.CollisionFlag = false;
  63. }
  64. this.node.destroy();
  65. }
  66. }
  67. }
  68. /**
  69. * 初始化函数
  70. * @param main 主场景
  71. */
  72. public init(main:MainScene){
  73. this.main = main;
  74. }
  75. /**
  76. * 获取落脚点类型
  77. */
  78. public getKind(){
  79. return this.KIND_FootHold;
  80. }
  81. onCollisionEnter(other,self){
  82. let rootself = this;//当前根节点
  83. if(rootself.GoUp){
  84. return;
  85. }
  86. Global.instance.KIND_FootHold = this.KIND_FootHold;
  87. Global.instance.TheHolder = this.node;
  88. if(other.tag == 111){
  89. // console.log("我被撞到了");
  90. rootself.main.Score();
  91. rootself.gainSc = true;
  92. return;
  93. }
  94. // this.main.Score();
  95. if(!Global.instance.CollisionFlag){
  96. // console.log(other);
  97. // console.log("5检测到碰撞!!!");
  98. // console.log(self);
  99. self.node.isHold = true;
  100. Global.instance.CollisionFlag = true;
  101. }
  102. }
  103. }