PlayerCollisionLine.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Hero: {
  5. default: null,
  6. type: cc.Node,
  7. LevelIdex:0
  8. },
  9. },
  10. start : function() {
  11. this.LevelIdex=0;
  12. this.GameStates = cc.find("Canvas").getComponent("GameStates");
  13. },
  14. onCollisionEnter: function (other) {
  15. // if(!bDebug)return;
  16. //
  17. // if(this.node.parent.parent.name == 'Hero') return;
  18. //获取场景
  19. var scene = cc.director.getScene();
  20. if (this.GameStates.isRobot) {
  21. cc.find("AIBot").getComponent("AIBot").Enters(other,this);
  22. }
  23. },
  24. GetSyncObj:function(ParentName,ObjName,PositionX)
  25. {
  26. var Level = cc.find("Level");
  27. var aX = parseFloat(PositionX);
  28. var Obj = null;
  29. var LevelChildren = Level.children;
  30. // cc.log('Level'+length);
  31. for(var i=0;i<LevelChildren.length;i++)
  32. {
  33. if(LevelChildren[i].name === ParentName)
  34. {
  35. var aObj = LevelChildren[i].getChildByName(ObjName);
  36. if(aObj && aX===aObj.convertToWorldSpaceAR(cc.Vec2.ZERO).x)
  37. {
  38. Obj = aObj;
  39. }
  40. }
  41. }
  42. return Obj;
  43. },
  44. update : function (dt) {
  45. if(bDebug)return;
  46. // if(this.node.parent.parent.name != 'Hero') return;
  47. if(!cc.find('Canvas').getComponent('GameStates').bServer) return;
  48. var ColliderInfo = null;
  49. if(this.node.parent.parent.name == 'Hero')
  50. {
  51. ColliderInfo = this.node.getComponent('HeroColliderInfo');
  52. }
  53. else
  54. {
  55. ColliderInfo = this.node.getComponent('RivelColliderInfo');
  56. }
  57. if (ColliderInfo==null) {
  58. return;
  59. }
  60. var CurrentCollider = ColliderInfo.data[this.LevelIdex];
  61. if(this.LevelIdex==ColliderInfo.data.length) return;
  62. var aX = parseFloat(CurrentCollider.PositionX);
  63. if(this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x<aX+1 && this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x>aX-1)
  64. {
  65. var Obj= this.GetSyncObj(CurrentCollider.ParentName,CurrentCollider.ObjName,CurrentCollider.BarrierPositionX);
  66. if (Obj==null) {
  67. return;
  68. }
  69. var ObjScript = Obj.getComponent('BarrierSuper');
  70. if(CurrentCollider.State=='Enter')
  71. {
  72. ObjScript.onCollisionEnter(this);
  73. }
  74. else
  75. {
  76. ObjScript.onCollisionExit(this);
  77. }
  78. this.LevelIdex++;
  79. }
  80. }
  81. });