car.ts 23 KB

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