boli.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class boli extends cc.Component {
  6. /**
  7. * 落脚点类型 5:玻璃
  8. */
  9. private KIND_FootHold = 5;
  10. /**
  11. * player是否落在落脚点上,默认false,没有
  12. */
  13. @property(Boolean)
  14. public isHold = false;
  15. @property(Number)
  16. public NodeH:number = 40;
  17. private main:MainScene = null;
  18. /**
  19. * 落脚点对应动画
  20. */
  21. Ani:cc.Animation = null;
  22. AniState = null;
  23. gainSc = false;
  24. onLoad () {
  25. this.node.y = -500;
  26. this.node.x =( Math.random()*2-1)*140;
  27. this.Ani = this.node.getComponent(cc.Animation);
  28. }
  29. start () {
  30. }
  31. update (dt) {
  32. let self = this;
  33. if(Global.instance.OverFlag){
  34. self.enabled = false;
  35. }
  36. else{
  37. this.node.active = true;
  38. this.node.y += Global.instance.FHFallSpeed;
  39. if(this.node.isHold){
  40. Global.instance.CollisionFlag = true;
  41. Global.instance.TheHolder = this.node;
  42. }
  43. if(this.node.y>360){
  44. if(this.node.isHold){
  45. this.node.isHold = false;
  46. Global.instance.CollisionFlag = false;
  47. }
  48. this.node.destroy();
  49. }
  50. }
  51. }
  52. /**
  53. * 初始化函数
  54. * @param main 主场景
  55. */
  56. public init(main:MainScene){
  57. this.main = main;
  58. }
  59. /**
  60. * 获取落脚点类型
  61. */
  62. public getKind(){
  63. return this.KIND_FootHold;
  64. }
  65. onCollisionEnter(other,self){
  66. // let spawn;
  67. let rootself = this;
  68. Global.instance.KIND_FootHold = this.KIND_FootHold;
  69. Global.instance.TheHolder = this.node;
  70. self.node.isHold = true;
  71. Global.instance.CollisionFlag = true;
  72. if(other.tag == 111){
  73. console.log("我被撞到了");
  74. rootself.main.Score();
  75. rootself.gainSc = true;
  76. return;
  77. }
  78. // this.main.Score();
  79. this.scheduleOnce(function(){
  80. this.AniState = this.Ani.play("boli");
  81. rootself.node.isHold = false;
  82. Global.instance.CollisionFlag = false;
  83. self.destroy();
  84. },0.5);
  85. }
  86. }