dici.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import MainScene from "./MainScene";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class NewClass extends cc.Component {
  6. /**
  7. * 落脚点类型 6:地刺
  8. */
  9. private KIND_FootHold = 6;
  10. /**
  11. * player是否落在落脚点上,默认false,没有
  12. */
  13. @property(Boolean)
  14. public isHold = false;
  15. @property(Number)
  16. public NodeH:number = 80;
  17. GoUp = false;
  18. private main:MainScene = null;
  19. /**
  20. * 落脚点对应动画
  21. */
  22. Ani:cc.Animation = null;
  23. AniState = null;
  24. gainSc = false;
  25. InjuredF = false;
  26. // LIFE-CYCLE CALLBACKS:
  27. onLoad () {
  28. this.node.y = -500;
  29. this.node.x = ( Math.random()*2-1)*140;
  30. this.Ani = this.node.getComponent(cc.Animation);
  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. Global.instance.CollisionFlag = false;
  50. this.node.isHold = false;
  51. }
  52. this.node.destroy();
  53. }
  54. }
  55. }
  56. /**
  57. * 初始化函数
  58. * @param main 主场景
  59. */
  60. 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. if(rootself.GoUp){
  72. return;
  73. }
  74. if(other.tag == 111){
  75. console.log("我被撞到了");
  76. rootself.main.Score();
  77. rootself.gainSc = true;
  78. return;
  79. }
  80. else{
  81. Global.instance.TheHolder = this.node;
  82. Global.instance.KIND_FootHold = this.KIND_FootHold;
  83. rootself.node.isHold = true;
  84. self.node.isHold = true;
  85. if(!rootself.InjuredF){
  86. Global.instance.Injured = true;
  87. rootself.InjuredF = true;
  88. }
  89. // this.main.Score();
  90. if(!Global.instance.CollisionFlag){
  91. Global.instance.CollisionFlag = true;
  92. rootself.node.isHold = true;
  93. self.node.isHold = true;
  94. rootself.AniState = rootself.Ani.play("dici");
  95. rootself.AniState.repeatCount = 100;
  96. }
  97. }
  98. }
  99. }
  100. /**
  101. * 地刺的问题貌似还没有解决
  102. * 不知道哪里有问题
  103. * 地刺的问题到底是碰撞标志位被修改了。
  104. *
  105. */