car.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. import { _decorator, BoxCollider2D, CircleCollider2D, Collider2D, Component, Contact2DType, Director, director, instantiate, IPhysics2DContact, Label, math, Node, ParticleSystem2D, PolygonCollider2D, Prefab, Rect, RigidBody, RigidBody2D, Sprite, tween, Tween, UITransform, Vec2, Vec3, View } from 'cc';
  2. import { wall } from './wall';
  3. import { box } from './box';
  4. import { coin } from './coin';
  5. import { tools } from '../tools';
  6. import { game } from './game';
  7. import { car_item_data, DirType, model_content_item_data } from '../data';
  8. import { config } from '../config';
  9. import { imageCacheManager } from '../manager/imageCacheManager';
  10. import { userDataManager } from '../manager/userDataManager';
  11. import { audioManager } from '../manager/audioManager';
  12. import { buff_manager } from './buff/buff_manager';
  13. import { hp_bar } from './hp_bar';
  14. import { GameManager } from '../GameManager';
  15. import { buff_active_effect_item } from './buff/buff_active_effect_item';
  16. import { dataManager } from '../manager/dataManager';
  17. const { ccclass, property } = _decorator;
  18. @ccclass('car')
  19. export class car extends Component {
  20. private offsetY:number = 0;
  21. private origin_pos_y:number = -300;
  22. private map:Node = null;
  23. private mDir:Vec3 = Vec3.ZERO;
  24. private mOldDir:Vec3 = Vec3.ZERO;
  25. private mGameOldDir:Vec3 = Vec3.ZERO;
  26. private mDis:number = 0;
  27. private isAction:boolean = false;
  28. private speed:number = 700;
  29. @property(CircleCollider2D) car_collider:CircleCollider2D = null;
  30. @property(Node) lab_hp:Node = null;
  31. private hp:number = 0
  32. private scores:number = 0
  33. private over_cb = null;
  34. private update_scores_cb = null;
  35. private game_manager:game = null;
  36. private buff_xi_status:boolean = false;
  37. private buff_dun_status:boolean = false;
  38. private buff_xing_status:boolean = false;
  39. private speed_bei:number = 1;
  40. @property(Number) move_speed_y:Number = 700;
  41. @property(Number) move_speed_x:Number = 700;
  42. @property(Boolean) is_open_jiaozheng:Boolean = true;
  43. private carDir:DirType = DirType.NONE
  44. private canvas_width:number = 1080;
  45. private isStopY:boolean = false
  46. private isStartGame:Boolean = false
  47. @property(Node) spr:Node = null
  48. @property(Node) hp_bar:Node = null
  49. @property(Prefab) buff_active_effect_pf:Prefab = null
  50. @property(ParticleSystem2D) smoke_particle:ParticleSystem2D = null
  51. private mIsReLife:boolean = false
  52. private mCarData:car_item_data = null
  53. public init(m:Node,cb,cb1,g:game,isReLife:boolean = false){
  54. this.mIsReLife = isReLife
  55. this.spr.getComponent(Sprite).spriteFrame = imageCacheManager.getGameCarImageById(userDataManager.user_car_list.default_car_id)
  56. this.spr.getComponent(buff_manager).init()
  57. this.origin_pos_y = this.node.position.y
  58. this.game_manager = g
  59. this.over_cb = cb
  60. this.update_scores_cb = cb1
  61. this.map = m;
  62. this.isAction = false;
  63. this.mOldDir = this.node.position
  64. this.buff_xi_status = false;
  65. this.buff_dun_status = false;
  66. this.buff_xing_status = false;
  67. this.isStopY = false;
  68. this.canvas_width = View.instance.getVisibleSize().width
  69. if(userDataManager.user_car_list.default_car_id==1){
  70. audioManager.Instance().playSound(config.AUDIO.zi_xing_che_qi_bu)
  71. }else{
  72. audioManager.Instance().playSound(config.AUDIO.car_qi_dong)
  73. }
  74. this.mCarData = dataManager.getUserCarInfo(userDataManager.user_car_list.default_car_id)
  75. // let cd = this.node.getComponent(BoxCollider2D)
  76. // cd.off(Contact2DType.BEGIN_CONTACT)
  77. // cd.on(Contact2DType.BEGIN_CONTACT,this.onColliderCoin.bind(this))
  78. // cd.off(Contact2DType.END_CONTACT)
  79. // cd.on(Contact2DType.END_CONTACT,this.onColliderCoin.bind(this))
  80. // cd.off(Contact2DType.PRE_SOLVE)
  81. // cd.on(Contact2DType.PRE_SOLVE,this.onColliderWall.bind(this))
  82. // this.car_collider.off(Contact2DType.BEGIN_CONTACT)
  83. // this.car_collider.on(Contact2DType.BEGIN_CONTACT,this.onColliderCoin.bind(this))
  84. // this.car_collider.off(Contact2DType.END_CONTACT)
  85. // this.car_collider.on(Contact2DType.END_CONTACT,this.onColliderCoin.bind(this))
  86. // this.car_collider.off(Contact2DType.POST_SOLVE)
  87. // this.car_collider.on(Contact2DType.POST_SOLVE,(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null)=>{
  88. // // console.log("this.car_collider",otherCollider.node.name)
  89. // if(otherCollider.node.name.endsWith("fku")){
  90. // if(otherCollider.node.parent.getComponent(box)!=null){
  91. // otherCollider.node.parent.getComponent(box).hurt(this.shake.bind(this),this.buff_dun_status)
  92. // }
  93. // }
  94. // if(otherCollider.node.name.endsWith("wall")){
  95. // // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(this.move_speed_x.valueOf(),this.move_speed_y.valueOf())
  96. // }
  97. // },this)
  98. this.move_speed_y = tools.game_config.car_origin_speed
  99. this.hp = tools.game_config.car_init_num + this.mCarData.attribute.k_oil_number
  100. this.hp_bar.getComponent(hp_bar).updateHp(this.hp)
  101. // this.hp = 100000
  102. if(isReLife){
  103. }else{
  104. this.scores = 0
  105. }
  106. this.updateHp()
  107. this.updateScores()
  108. this.node.getComponent(RigidBody2D).gravityScale = -3
  109. this.node.getComponent(RigidBody2D).linearDamping = 1
  110. // this.schedule(this.check.bind(this),0.01)
  111. // circle.radius = tools.game_config.buff_xi_range
  112. // circle.radius = 400
  113. // circle.off(Contact2DType.BEGIN_CONTACT)
  114. // circle.on(Contact2DType.BEGIN_CONTACT,(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null)=>{
  115. // if(otherCollider.node.name.endsWith("coin")){
  116. // if(otherCollider.node.getComponent(coin)!=null){
  117. // otherCollider.node.getComponent(coin).moveToTarget(otherCollider.node.parent.getComponent(UITransform).convertToNodeSpaceAR(this.node.position))
  118. // this.hp+=tools.randomCoin()
  119. // this.updateHp()
  120. // }
  121. // }
  122. // })
  123. this.unschedule(this.addSpeed)
  124. this.schedule(this.addSpeed.bind(this),tools.game_config.car_add_speed_time)
  125. }
  126. public hideEffect(){
  127. this.spr.getComponent(buff_manager).init()
  128. }
  129. public getIsReLife(){
  130. return this.mIsReLife
  131. }
  132. addSpeed(){
  133. let speed = this.move_speed_y.valueOf()+(tools.game_config.car_add_speed_num)
  134. if(speed<tools.game_config.car_add_speed_max){
  135. this.move_speed_y=speed
  136. }
  137. }
  138. addSpeedNum(num:number){
  139. let speed = this.move_speed_y.valueOf()+(num*0.01*this.move_speed_y.valueOf())
  140. if(speed<tools.game_config.car_add_speed_max){
  141. this.move_speed_y=speed
  142. }
  143. }
  144. onColliderCoin(coin_node:Node){
  145. if(coin_node.getComponent(coin)!=null){
  146. audioManager.Instance().playSound(config.AUDIO.qiyou)
  147. coin_node.getComponent(coin).removeSelf()
  148. this.hp+=coin_node.getComponent(coin).getAddHpNum()
  149. this.updateHp()
  150. let box_world=coin_node.parent.getComponent(UITransform).convertToWorldSpaceAR(coin_node.position)
  151. let p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(box_world)
  152. this.getGame().showQiYouEffect(p)
  153. }
  154. }
  155. onColliderBox(box_node:Node){
  156. if(box_node.getComponent(box)!=null){
  157. audioManager.Instance().playSound(config.AUDIO.peng_zhuang)
  158. box_node.getComponent(box).hurt(this.shake.bind(this),this.buff_dun_status)
  159. }
  160. }
  161. public getIsOpenJZ():boolean{
  162. return this.is_open_jiaozheng.valueOf()
  163. }
  164. public getGame(){
  165. return this.game_manager
  166. }
  167. public getXiStatus(){
  168. return this.buff_xi_status
  169. }
  170. private updateScores(){
  171. if(this.update_scores_cb!=null){
  172. this.update_scores_cb(this.scores)
  173. }
  174. }
  175. private updateHp(){
  176. this.lab_hp.getComponent(Label).string = this.hp+""
  177. this.hp_bar.getComponent(hp_bar).updateHp(this.hp)
  178. }
  179. public getScores(){
  180. return this.scores
  181. }
  182. private shake(data:model_content_item_data,isKill:boolean,scores:number){
  183. // Tween.stopAllByTarget(this.node)
  184. let new_hp = this.hp;
  185. // this.isAction = true;
  186. if(isKill){
  187. this.scores += ( scores*(this.buff_xing_status?2:1) )
  188. }else{
  189. this.scores+=( 1*(this.buff_xing_status?2:1) );
  190. new_hp = this.hp-1;
  191. }
  192. this.hp = new_hp;
  193. this.updateHp()
  194. // this.move_speed_y = 0
  195. this.isStopY = true
  196. this.updateScores()
  197. // this.node.getComponent(RigidBody2D).sleep()
  198. GameManager.vibrateShort()
  199. // this.node.position = new Vec3(this.node.position.x, this.node.position.y-8)
  200. // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(0,-2.5)
  201. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  202. // // this.move_speed_y = 0
  203. // })
  204. // tween(this.node).delay(0.1).call(()=>{
  205. // // this.isAction = false;
  206. // // this.node.position = new Vec3(this.node.position.x, this.node.position.y+8)
  207. // // this.node.getComponent(RigidBody2D).wakeUp()
  208. // // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(this.move_speed_x.valueOf(),30)
  209. // }).start()
  210. Tween.stopAllByTarget(this.lab_hp)
  211. tween(this.lab_hp).delay(0.05).call(()=>{ this.isStopY = false}).start()
  212. if(this.hp<0){
  213. if(this.isStartGame){
  214. Tween.stopAllByTarget(this.node)
  215. this.stopGame()
  216. // this.node.getComponent(RigidBody2D).gravityScale = 0
  217. // this.node.getComponent(RigidBody2D).linearDamping = 0
  218. this.over_cb()
  219. }
  220. }else{
  221. if(data!=null){
  222. if(data.buff_type!=-1){
  223. let buff_info = this.game_manager.getBuffShowView()
  224. let buff_active_node = instantiate(this.buff_active_effect_pf)
  225. buff_active_node.parent = buff_info.node.parent
  226. // console.log("data.buff_type::",data.buff_type)
  227. let box_p = buff_info.node.parent.getComponent(UITransform).convertToNodeSpaceAR(data.pos)
  228. switch (data.buff_type) {
  229. case config.buff_type.dun:
  230. // console.log("获取buff 盾")
  231. {
  232. let dis_node = buff_info.getBuffDun();
  233. let world = dis_node.parent.getComponent(UITransform).convertToWorldSpaceAR(dis_node.position)
  234. let p = buff_info.node.parent.getComponent(UITransform).convertToNodeSpaceAR(world)
  235. buff_active_node.getComponent(buff_active_effect_item).show(config.SHOW_BUFF_STATUS.DUN,p,box_p,()=>{
  236. this.buff_dun()
  237. })
  238. }
  239. break;
  240. case config.buff_type.xing:
  241. // console.log("获取buff 星")
  242. {
  243. let dis_node = buff_info.getBuffXing();
  244. let world = dis_node.parent.getComponent(UITransform).convertToWorldSpaceAR(dis_node.position)
  245. let p = buff_info.node.parent.getComponent(UITransform).convertToNodeSpaceAR(world)
  246. buff_active_node.getComponent(buff_active_effect_item).show(config.SHOW_BUFF_STATUS.XING,p,box_p,()=>{
  247. this.buff_xing()
  248. })
  249. }
  250. break;
  251. case config.buff_type.xi:
  252. // console.log("获取buff 吸")
  253. {
  254. let dis_node = buff_info.getBuffXi();
  255. let world = dis_node.parent.getComponent(UITransform).convertToWorldSpaceAR(dis_node.position)
  256. let p = buff_info.node.parent.getComponent(UITransform).convertToNodeSpaceAR(world)
  257. buff_active_node.getComponent(buff_active_effect_item).show(config.SHOW_BUFF_STATUS.XI,p,box_p,()=>{
  258. this.buff_xi()
  259. })
  260. }
  261. break;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. public buff_xi(){
  268. this.addSpeedNum(tools.game_config.buff_xi_add_speed)
  269. // Tween.stopAllByTarget(this.game_manager.getBuffShowView().getBuffXi())
  270. // this.cancelScheduleBuffXi()
  271. // tween(this.game_manager.getBuffShowView().getBuffXi()).delay(tools.game_config.buff_xi).call(this.cancelScheduleBuffXi.bind(this)).start()
  272. this.game_manager.getBuffShowView().showBuffXi(this.cancelScheduleBuffXi.bind(this),tools.game_config.buff_xi+this.mCarData.attribute.n_magnet_cd)
  273. audioManager.Instance().playSound(config.AUDIO.buff_xi)
  274. this.spr.getComponent(buff_manager).updateStatus(config.SHOW_BUFF_STATUS.XI)
  275. this.buff_xi_status = true;
  276. }
  277. public cancelScheduleBuffXi(){
  278. if(this.buff_xi_status){
  279. this.spr.getComponent(buff_manager).cancelStatus(config.SHOW_BUFF_STATUS.XI)
  280. this.buff_xi_status = false
  281. this.game_manager.getBuffShowView().hideBuffXi()
  282. }
  283. }
  284. public buff_xing(){
  285. this.addSpeedNum(tools.game_config.buff_xi_add_speed)
  286. // Tween.stopAllByTarget(this.game_manager.getBuffShowView().getBuffXing())
  287. // this.cancelScheduleBuffXing()
  288. // tween(this.game_manager.getBuffShowView().getBuffXing()).delay(tools.game_config.buff_xing).call(this.cancelScheduleBuffXing.bind(this)).start()
  289. this.game_manager.getBuffShowView().showBuffXing(this.cancelScheduleBuffXing.bind(this),tools.game_config.buff_xing+this.mCarData.attribute.n_star_cd)
  290. audioManager.Instance().playSound(config.AUDIO.buff_xing)
  291. this.spr.getComponent(buff_manager).updateStatus(config.SHOW_BUFF_STATUS.XING)
  292. this.buff_xing_status = true;
  293. }
  294. public cancelScheduleBuffXing(){
  295. if(this.buff_xing_status ){
  296. this.spr.getComponent(buff_manager).cancelStatus(config.SHOW_BUFF_STATUS.XING)
  297. this.buff_xing_status = false
  298. this.game_manager.getBuffShowView().hideBuffXing()
  299. }
  300. }
  301. public buff_dun(time:number =null){
  302. this.addSpeedNum(tools.game_config.buff_dun_add_speed)
  303. // Tween.stopAllByTarget(this.game_manager.getBuffShowView().getBuffDun())
  304. // this.cancelScheduleBuffDun()
  305. // tween(this.game_manager.getBuffShowView().getBuffDun()).delay(tools.game_config.buff_dun).call(this.cancelScheduleBuffDun.bind(this)).start()
  306. // this.scheduleOnce(this.cancelScheduleBuffDun.bind(this),tools.game_config.buff_dun)
  307. this.game_manager.getBuffShowView().showBuffDun(this.cancelScheduleBuffDun.bind(this),time!=null?time:(tools.game_config.buff_dun+this.mCarData.attribute.n_shield_cd))
  308. audioManager.Instance().playSound(config.AUDIO.buff_dun)
  309. this.spr.getComponent(buff_manager).updateStatus(config.SHOW_BUFF_STATUS.DUN)
  310. this.buff_dun_status = true;
  311. }
  312. public cancelScheduleBuffDun(){
  313. if(this.buff_dun_status){
  314. this.buff_dun_status = false
  315. this.game_manager.getBuffShowView().hideBuffDun()
  316. this.spr.getComponent(buff_manager).cancelStatus(config.SHOW_BUFF_STATUS.DUN)
  317. }
  318. }
  319. public setMoveSpeedX(speed_x:number){
  320. // this.move_speed_x = speed_x
  321. }
  322. public startGame(){
  323. this.isStartGame = true
  324. this.smoke_particle.node.active = true
  325. if(this.mCarData.attribute.k_sprint_cd>0){
  326. this.k_sprint_cd()
  327. }
  328. }
  329. public k_sprint_cd(){
  330. this.buff_dun(this.mCarData.attribute.k_sprint_cd)
  331. }
  332. public stopGame(){
  333. this.smoke_particle.node.active = false
  334. this.isStartGame = false
  335. }
  336. check(){
  337. }
  338. protected update(dt: number): void {
  339. if(!this.isStartGame){
  340. return
  341. }
  342. if(this.map!=null&&this.hp>=0){
  343. let x = 0
  344. let y = this.isStopY?this.node.position.y:this.node.position.y+this.move_speed_y.valueOf()*dt;
  345. let self_pos = new Vec3(this.node.position.x,this.node.position.y)
  346. let dis = Math.abs(self_pos.x-this.mDir.x)
  347. if(dis>1){
  348. // console.log("dis",this.move_speed_x)
  349. x = self_pos.subtract(this.mDir).normalize().x*this.move_speed_x.valueOf()*dt*this.speed_bei;
  350. }
  351. x = this.node.position.x-x;
  352. let size = this.node.getComponent(UITransform).contentSize;
  353. let left = this.canvas_width*0.5*-1+size.width*0.5;
  354. let right = this.canvas_width*0.5-90*0.5;
  355. if(this.carDir==DirType.LEFT){
  356. let left_x = this.game_manager.getLeftObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
  357. // console.log("left_x",left_x)
  358. if(left_x!=null&&x<left_x){
  359. x = left_x+5
  360. }
  361. if(x<=left){
  362. x = left
  363. }
  364. }
  365. if(this.carDir==DirType.RIGHT){
  366. let right_x = this.game_manager.getRightObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
  367. // console.log("right_x",right_x)
  368. if(right_x!=null&&x>right_x){
  369. x = right_x-5
  370. }
  371. if(x>=right){
  372. x = right
  373. }
  374. }
  375. if(x<left||x>right){
  376. x = this.node.position.x
  377. }
  378. let rect = new Rect(x-size.width*0.5,y-size.height*0.5,size.width,size.height)
  379. // let rect = this.node.getComponent(UITransform).getBoundingBox()
  380. let list = this.game_manager.carCollider(rect)
  381. if(list.length>0){
  382. for (let index = 0; index < list.length; index++) {
  383. const element = list[index];
  384. if(element.collider_dir==config.collider_dir.top){
  385. y = this.node.position.y
  386. if(element.type==0){
  387. this.onColliderBox(element.node)
  388. }else if(element.type==1){
  389. x-=element.moveOffset
  390. // console.log("carCollider wall",element)
  391. }
  392. }else{
  393. // x = this.node.position.x
  394. if(element.type==2){
  395. this.onColliderCoin(element.node)
  396. }else if(element.type==1||element.type==0){
  397. if(element.moveOffset==0){
  398. x = this.node.position.x
  399. }
  400. }
  401. }
  402. }
  403. }
  404. // this._curRingPos_1.set(0, 0, 0);
  405. // Vec3.lerp(this._curRingPos_1, this.node.position, new Vec3(x,y), 50 * dt);
  406. // this.node.setPosition(this._curRingPos_1);
  407. if(this.carDir==DirType.LEFT){
  408. if(x<=left){
  409. x = left
  410. }
  411. }
  412. if(this.carDir==DirType.RIGHT){
  413. if(x>=right){
  414. x = right
  415. }
  416. }
  417. this.offsetY =Math.abs(this.origin_pos_y-y)
  418. let dir = new Vec3(0,-this.offsetY,this.map.position.z)
  419. this.map.position = dir
  420. this.node.setPosition(x,y)
  421. }
  422. }
  423. public setDir(dir:DirType){
  424. // if(this.carDir!=dir){
  425. // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(0,this.move_speed_y.valueOf())
  426. // }
  427. this.carDir = dir
  428. }
  429. public setDisDir(dis:number){
  430. if(!this.isStartGame){
  431. return
  432. }
  433. if(Math.abs(dis) <1){
  434. return
  435. }
  436. this.speed_bei = Math.abs(dis / 8)
  437. if(this.speed_bei>4){
  438. dis*=4
  439. Tween.stopAllByTarget(this.smoke_particle.node)
  440. tween(this.smoke_particle.node).delay(1).call(()=>{
  441. this.smoke_particle.stopSystem()
  442. }).start()
  443. this.smoke_particle.resetSystem()
  444. if(userDataManager.user_car_list.default_car_id==1){
  445. audioManager.Instance().playSound(config.AUDIO.zi_xing_che_sha_che)
  446. }else{
  447. audioManager.Instance().playSound(config.AUDIO.car_sha_che,0.1)
  448. }
  449. }
  450. if(this.carDir==DirType.LEFT){
  451. this.mDir = new Vec3(this.node.position.x-dis,this.node.position.y)
  452. }
  453. if(this.carDir==DirType.RIGHT){
  454. this.mDir = new Vec3(this.node.position.x+dis,this.node.position.y)
  455. }
  456. }
  457. public setDis(dis:number){
  458. this.setSpeed(new Vec3(dis))
  459. // this.mDis = dis
  460. }
  461. public getDis(){
  462. return this.mDis
  463. }
  464. public getCarDir(){
  465. return this.carDir
  466. }
  467. public setSpeed(dir:Vec3){
  468. // let dis = Math.abs(this.node.position.x - dir.x)
  469. // if(dis>200){
  470. // dis = 500
  471. // }
  472. // this.mDis = dis;
  473. let dis = Math.abs(this.mOldDir.x - dir.x)
  474. // let is_char = false
  475. // if(this.carDir===DirType.LEFT){
  476. // if(dir.x>this.node.position.x){
  477. // is_char = true
  478. // }
  479. // }else if(this.carDir===DirType.RIGHT){
  480. // if(dir.x<this.node.position.x){
  481. // is_char = true
  482. // }
  483. // }
  484. // if(is_char){
  485. // dis = Math.abs(this.mGameOldDir.x - dir.x)
  486. // }else{
  487. // this.mGameOldDir = dir
  488. // }
  489. this.mOldDir = this.node.position
  490. // dis*=2
  491. // console.log("this.mDis",dis)
  492. this.mDis = dis;
  493. // if(this.mDir.x!=0){
  494. // //与目标位置的距离进行速度算法 - 距离越长 速度越快
  495. // if(!this.isAction){
  496. // let dis = Math.abs(this.mOldDir.x - dir.x)
  497. // if(this.carDir===DirType.LEFT){
  498. // if(dir.x>this.node.position.x){
  499. // dis = Math.abs(this.mGameOldDir.x - dir.x)
  500. // }
  501. // }else if(this.carDir===DirType.RIGHT){
  502. // if(dir.x<this.node.position.x){
  503. // dis = Math.abs(this.mGameOldDir.x - dir.x)
  504. // }
  505. // }
  506. // this.mDis = dis;
  507. // // if(dis<=100){
  508. // // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(10*x,30)
  509. // // }else if(dis>100&&dis<=200){
  510. // // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(20*x,30)
  511. // // }else{
  512. // // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(dis/200*35*x,25)
  513. // // }
  514. // // this.node.position = new Vec3(this.node.position.x+x*this.speed*dt,this.node.position.y,this.node.position.z)
  515. // }
  516. // }else{
  517. // if(this.node.getComponent(RigidBody2D).linearVelocity.x!=0){
  518. // this.node.getComponent(RigidBody2D).linearVelocity = new Vec2(0,this.move_speed_y.valueOf())
  519. // }
  520. // }
  521. }
  522. // protected update(dt: number): void {
  523. // this.node.position = new Vec3(this.node.position.x,this.node.position.y+dt*500,this.node.position.z)
  524. // this.map.position = new Vec3(this.map.position.x,this.map.position.y-dt*500,this.map.position.z)
  525. // }
  526. }