shandian.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class shandian extends cc.Component {
  6. /**
  7. * 落脚点类型 8:闪电
  8. */
  9. private KIND_FootHold = 8;
  10. /**
  11. * player是否落在落脚点上,默认false,没有
  12. */
  13. @property(Boolean)
  14. public isHold = false;
  15. @property(Number)
  16. public NodeH:number = 50;
  17. private
  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("shandian");
  30. this.AniState.repeatCount = 100;
  31. }
  32. start () {
  33. }
  34. update (dt) {
  35. // console.log(Global.instance.CollisionFlag);
  36. let self = this;
  37. if(Global.instance.OverFlag){
  38. self.enabled = false;
  39. }
  40. else{
  41. this.node.active = true;
  42. this.node.y += Global.instance.FHFallSpeed;
  43. if(this.node.isHold){
  44. Global.instance.CollisionFlag = true;
  45. Global.instance.TheHolder = this.node;
  46. }
  47. if(this.node.y>360){
  48. if(this.node.isHold){
  49. this.node.isHold = false;
  50. Global.instance.CollisionFlag = false;
  51. }
  52. this.node.destroy();
  53. }
  54. }
  55. }
  56. /**
  57. * 初始化函数
  58. * @param main 主场景
  59. */
  60. public init(main:MainScene){
  61. this.main = main;
  62. }
  63. /**
  64. * 获取落脚点类型
  65. */
  66. public getKind(){
  67. return this.KIND_FootHold;
  68. }
  69. onCollisionEnter(other,self){
  70. let rootself = this;
  71. switch(other.tag){
  72. case 0:{
  73. Global.instance.KIND_FootHold = this.KIND_FootHold;
  74. Global.instance.TheHolder = this.node;
  75. Global.instance.Injured = true;
  76. break;
  77. }
  78. case 111:{
  79. console.log("我被撞到了");
  80. rootself.main.Score();
  81. rootself.gainSc = true;
  82. return;
  83. }
  84. }
  85. // this.main.Score();
  86. if(!Global.instance.CollisionFlag){
  87. self.node.isHold = false;
  88. Global.instance.CollisionFlag = false;
  89. }
  90. }
  91. }