Opplvdai.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class Opplvdai extends cc.Component {
  6. /**
  7. * 落脚点类型 2:向右传送带
  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 = 69;
  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. this.node.y = -500;
  27. this.node.x = ( Math.random()*2-1)*140;
  28. this.Ani = this.node.getComponent(cc.Animation);
  29. this.AniState = this.Ani.play("Opplvdai");
  30. this.AniState.repeatCount = 100;
  31. this.AniState.speed = 2;
  32. }
  33. start () {
  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. this.node.isHold = false;
  51. Global.instance.CollisionFlag = 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. onCollisionEnter(other,self){
  71. let rootself = this;//当前根节点
  72. if(rootself.GoUp){
  73. return;
  74. }
  75. Global.instance.KIND_FootHold = this.KIND_FootHold;
  76. Global.instance.TheHolder = this.node;
  77. if(other.tag == 111){
  78. console.log("我被撞到了");
  79. rootself.main.Score();
  80. rootself.gainSc = true;
  81. rootself.GoUp = true;
  82. return;
  83. }
  84. // this.main.Score();
  85. if(!Global.instance.CollisionFlag){
  86. // console.log(other);
  87. // console.log("2检测到碰撞!!!");
  88. // console.log(self);
  89. // other.node.y = this.node.y+50;
  90. self.node.isHold = true;
  91. Global.instance.CollisionFlag = true;
  92. }
  93. }
  94. }