RoleQueue.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName, { SofaColor, SofaDir } from "../EventName/EventName";
  8. import Down from "../GameUI/Down";
  9. import GamePause from "../GameUI/GamePause";
  10. import HonorManger from "../GameUI/HonorManger";
  11. import LocalData from "../Template/LocalData";
  12. import MyComponent from "../Template/MyComponent";
  13. import { BusNodeData, BusType, ChangeRoloInitOver, GetRoloQueues, GraySitDownColor, MapRoleQueuePos, MapRoleQueuePosType, MenX, MenXLeft, MenY, MenYLeft, leftButtomStatPos, tableData, tiledSize } from "./DataConfig";
  14. import Role from "./Role";
  15. import Sofa from "./Sofa";
  16. import { AStar } from "./aStar";
  17. import BarrierDrag from "./barrierDrag";
  18. const { ccclass, property } = cc._decorator;
  19. @ccclass
  20. export default class RoleQueue extends MyComponent {
  21. private aStar: AStar
  22. // update (dt) {}
  23. targetPos: cc.Vec2 = new cc.Vec2(0, 0)
  24. selectNode: cc.Node = null
  25. @property(cc.Node)
  26. barrierLayer: cc.Node = null
  27. @property(cc.Node)
  28. gameLayer: cc.Node = null
  29. //队列类型
  30. RoleQueueType: number = 1
  31. //人物预制体
  32. @property(cc.Prefab)
  33. Role: cc.Prefab = null
  34. @property(cc.Node)
  35. RoleQueue1: cc.Node = null
  36. @property(cc.Node)
  37. RoleQueue2: cc.Node = null
  38. @property(cc.Node)
  39. An1: cc.Node = null
  40. @property(cc.Node)
  41. An2: cc.Node = null
  42. //是否发送了一次下一关的表示 。放置 双层队列发送两次
  43. IsSendNextCoustomGameFlag = false
  44. onLoad(): void {
  45. super.onLoad();
  46. RoleQueue.SitdownRole = 0
  47. this.aStar = new AStar()
  48. this.regEvent(EventName.BronRole, this.BronRoles, this)
  49. this.regEvent(EventName.RoleStartBus, this.RoleStartBus, this)
  50. this.regEvent(EventName.RoleStopBus, this.RoleStopBus, this)
  51. this.regEvent(EventName.initRoleQueuePos, this.initRoleQueuePos, this)
  52. this.regEvent(EventName.NowSitDowninSeatAnim, this.NowSitDowninSeatAnim, this)
  53. this.regEvent(EventName.RestartCurrentLevel, this.RestartCurrentLevel, this)
  54. }
  55. RestartCurrentLevel() {
  56. this.RoleQueue1.children.forEach(e => {
  57. e.stopAllActions()
  58. e.destroy()
  59. })
  60. this.RoleQueue2.children.forEach(e => {
  61. e.stopAllActions()
  62. e.destroy()
  63. })
  64. cc.systemEvent.emit(EventName.RoleStopBus)
  65. cc.systemEvent.emit(EventName.NextCoustomGameStop)
  66. cc.systemEvent.emit(EventName.CloseDoor)
  67. }
  68. NowSitDowninSeatAnim(targetNode: cc.Node, isleft: number, SeatColor: SofaColor, Sofadir: SofaDir) {
  69. //按照先右边后左边的顺序
  70. let rightRoleColor = this.RoleQueue1.children[0]?.getComponent(Role)
  71. let leftRoleColor = this.RoleQueue2.children[0]?.getComponent(Role)
  72. if (rightRoleColor?.MyColor == SeatColor ||
  73. (SeatColor == SofaColor.灰 && GraySitDownColor == rightRoleColor?.MyColor)) {
  74. cc.systemEvent.emit(EventName.StopNowSitDowninSeatAnim)
  75. BarrierDrag.PlayJump = false
  76. rightRoleColor.NowSitDowAni(targetNode, isleft, SeatColor, Sofadir)
  77. //更新排队队列
  78. this.UpdateRoleQueue(true)
  79. return
  80. }
  81. if (leftRoleColor?.MyColor == SeatColor ||
  82. (SeatColor == SofaColor.灰 && GraySitDownColor == leftRoleColor?.MyColor)
  83. ) {
  84. cc.systemEvent.emit(EventName.StopNowSitDowninSeatAnim)
  85. BarrierDrag.PlayJump = false
  86. leftRoleColor?.NowSitDowAni(targetNode, isleft, SeatColor, Sofadir)
  87. //更新排队队列
  88. this.UpdateRoleQueue(false)
  89. }
  90. }
  91. // 此次管卡有多少乘客
  92. TotalRole = 0;
  93. // 现在坐下的乘客数量
  94. static SitdownRole = 0;
  95. //初始化队列
  96. initRoleQueuePos() {
  97. // console.log('initRoleQueuePos');
  98. this.IsSendNextCoustomGameFlag = false
  99. if (this.isValid) {
  100. let temp: MapRoleQueuePosType = MapRoleQueuePos[BusType][LocalData.getInstance().getBusSkin() - 1]
  101. this.node.scale = BusNodeData[BusType][LocalData.getInstance().getBusSkin() - 1].RoleScale
  102. this.node.setPosition(BusNodeData[BusType][LocalData.getInstance().getBusSkin() - 1].gameLayer[0], BusNodeData[BusType][LocalData.getInstance().getBusSkin() - 1].gameLayer[1])
  103. this.RoleQueueType = temp.type
  104. //一个队列
  105. if (temp.type == 1) {
  106. let RoleQueue1 = this.RoleQueue1
  107. RoleQueue1.setPosition(temp.pos[0], temp.pos[1])
  108. if (!temp?.an) {
  109. return
  110. }
  111. if (temp?.an[0]) {
  112. this.An1.setPosition(temp.an[0][0], temp.an[0][1])
  113. this.An1.setScale(temp.an[0][2])
  114. this.An1.active = true
  115. } else {
  116. this.An1.active = false
  117. }
  118. if (temp?.an[1]) {
  119. this.An2.active = true
  120. } else {
  121. this.An2.active = false
  122. }
  123. }
  124. //两个队列
  125. if (temp.type == 2) {
  126. let RoleQueue1 = this.RoleQueue1
  127. RoleQueue1.setPosition(temp.pos[0], temp.pos[1])
  128. let RoleQueue2 = this.RoleQueue2
  129. RoleQueue2.setPosition(temp.pos1[0], temp.pos1[1])
  130. if (!temp?.an) {
  131. return
  132. }
  133. if (temp?.an[0]) {
  134. this.An1.setPosition(temp.an[0][0], temp.an[0][1])
  135. this.An1.setScale(temp.an[0][2])
  136. this.An1.active = true
  137. } else {
  138. this.An1.active = false
  139. }
  140. if (temp?.an[1]) {
  141. this.An2.setPosition(temp.an[1][0], temp.an[1][1])
  142. this.An2.setScale(temp.an[1][2])
  143. this.An2.active = true
  144. } else {
  145. this.An2.active = false
  146. }
  147. }
  148. }
  149. }
  150. BronRoles() {
  151. //第一个人出生时间
  152. let First_time = 0
  153. let last_time = 0.2
  154. //第一个人是侧着站立
  155. if (this.RoleQueueType == 1) {
  156. //右边的队列
  157. for (let index = 0; index < GetRoloQueues().length; index++) {
  158. this.scheduleOnce(() => {
  159. const element = GetRoloQueues()[index];
  160. this.BronRole(element, this.RoleQueue1, true, index)
  161. if (index == GetRoloQueues().length - 1) {
  162. ChangeRoloInitOver(true)
  163. }
  164. }, index > 0 ? last_time : First_time)
  165. }
  166. this.TotalRole = GetRoloQueues().length
  167. }
  168. if (this.RoleQueueType == 2) {
  169. //右边的队列
  170. for (let index = 0; index < GetRoloQueues()[0].length; index++) {
  171. this.scheduleOnce(() => {
  172. const element = GetRoloQueues()[0][index];
  173. this.BronRole(element, this.RoleQueue1, true, index)
  174. if (index == GetRoloQueues()[0].length - 1) {
  175. ChangeRoloInitOver(true)
  176. }
  177. }, index > 0 ? last_time : First_time)
  178. }
  179. //左边的队列
  180. for (let index = 0; index < GetRoloQueues()[1].length; index++) {
  181. this.scheduleOnce(() => {
  182. const element = GetRoloQueues()[1][index];
  183. this.BronRole(element, this.RoleQueue2, false, index)
  184. if (index == GetRoloQueues()[1].length - 1) {
  185. ChangeRoloInitOver(true)
  186. }
  187. }, index > 0 ? last_time : First_time)
  188. }
  189. this.TotalRole = GetRoloQueues()[0].length + GetRoloQueues()[1].length
  190. }
  191. RoleQueue.SitdownRole = 0
  192. console.log('开始发车');
  193. }
  194. //停止上车
  195. RoleStopBus() {
  196. this.unschedule(this.GoBus)
  197. }
  198. e_first_run_time = 0.15//0.2
  199. e_run_time = 0.15//0.2
  200. //每只乘客上车的间隔
  201. e_GoBus_time = 0.15//0.2
  202. //开始上车
  203. RoleStartBus() {
  204. this.schedule(this.GoBus, this.e_GoBus_time, cc.macro.REPEAT_FOREVER)
  205. }
  206. //上车逻辑
  207. GoBus() {
  208. //玩家在编辑中 不上人
  209. if (BarrierDrag.PlayEditer == false || BarrierDrag.PlayJump == true) {
  210. //创建完毕 更新一下渲染
  211. cc.systemEvent.emit(EventName.UpdataRender)
  212. //第一个人是侧着站立
  213. if (this.RoleQueueType == 1) {
  214. //右边的队列
  215. this.StartOneNode(this.RoleQueue1.children[0]?.getComponent(Role).MyColor, true)
  216. }
  217. if (this.RoleQueueType == 2) {
  218. //左边的队列
  219. //左右随机出
  220. // if (this.node.isValid) {
  221. // if (Math.random() > 0.5) {
  222. // this.StartOneNode(this.RoleQueue1.children[0]?.getComponent(Role).MyColor, true)
  223. // } else {
  224. // this.StartOneNode(this.RoleQueue2.children[0]?.getComponent(Role).MyColor, false)
  225. // }
  226. // }
  227. //优先出右边的
  228. this.StartOneNode(this.RoleQueue1.children[0]?.getComponent(Role).MyColor, true)
  229. this.scheduleOnce(() => {
  230. if (this.node.isValid) {
  231. this.StartOneNode(this.RoleQueue2.children[0]?.getComponent(Role).MyColor, false)
  232. }
  233. }, 0.05)
  234. }
  235. }
  236. }
  237. onDestroy(): void {
  238. super.onDestroy();
  239. this.unscheduleAllCallbacks()
  240. }
  241. //沙发颜色
  242. SofaColor: SofaColor = SofaColor.红
  243. //生成人物
  244. BronRole(RoleColor: SofaColor, parent: cc.Node, isRightQueue: boolean, index: number) {
  245. let tempNode = cc.instantiate(this.Role)
  246. if (isRightQueue) {
  247. tempNode.parent = parent
  248. } else {
  249. parent.addChild(tempNode, 0, parent.childrenCount.toString())
  250. }
  251. // let x = Math.floor(Math.random() * (41)) - 20
  252. let x = Math.floor(Math.random() * (31)) - 15
  253. tempNode.getComponent(Role).init(RoleColor)
  254. tempNode.active = true
  255. let setPos
  256. let targetpos
  257. if (isRightQueue) {
  258. setPos = -this.Right_Path - this.Right_Role_interval * (parent.childrenCount - 1)
  259. targetpos = - this.Right_Role_interval * (parent.childrenCount - 1)
  260. tempNode.setPosition(cc.v2(x, setPos))
  261. tempNode.getComponent(Role).run('上')
  262. let move = cc.moveTo(this.Right_Path_time, cc.v2(x, targetpos))
  263. let cb = cc.callFunc(() => {
  264. tempNode.getComponent(Role).idle('上')
  265. if (index == 0) {
  266. this.RoleQueueFirst(this.RoleQueue1, true)
  267. }
  268. })
  269. tempNode.runAction(cc.sequence(move, cb))
  270. } else {
  271. setPos = -this.Left_Path + this.Left_Role_interval * (parent.childrenCount - 1)
  272. targetpos = this.Left_Role_interval * (parent.childrenCount - 1)
  273. tempNode.setPosition(cc.v2(x, setPos))
  274. tempNode.getComponent(Role).run('下')
  275. let move = cc.moveTo(this.Left_Path_time, cc.v2(x, targetpos))
  276. let cb = cc.callFunc(() => {
  277. tempNode.getComponent(Role).idle('下')
  278. if (index == 0) {
  279. this.RoleQueueFirst(this.RoleQueue2, false)
  280. }
  281. })
  282. tempNode.runAction(cc.sequence(move, cb))
  283. }
  284. }
  285. async StartOneNode(RoleColor: SofaColor, isRightQueue: boolean) {
  286. //如果正在跳跃模式中
  287. if (Down.NowJumping) {
  288. return
  289. }
  290. if (BarrierDrag.PlayEditer == true) {
  291. return
  292. }
  293. if (GamePause.GamePause == true) {
  294. return
  295. }
  296. let MoveNode
  297. // console.log(RoleColor, isRightQueue);
  298. if (isRightQueue == true) {
  299. MoveNode = this.RoleQueue1.children[0]
  300. } else {
  301. MoveNode = this.RoleQueue2.children[0]
  302. }
  303. if (isRightQueue == true) {
  304. if (tableData[MenY][MenX] != 0) {
  305. cc.log('----右侧入口被阻挡---')
  306. return
  307. }
  308. } else {
  309. if (tableData[MenYLeft][MenXLeft] != 0) {
  310. cc.log('----左侧入口被阻挡---')
  311. return
  312. }
  313. }
  314. if (!MoveNode) {
  315. if (this.RoleQueue1.children[0] || this.RoleQueue2.children[0]) {
  316. } else {
  317. if (RoleQueue.SitdownRole == this.TotalRole && this.IsSendNextCoustomGameFlag == false) {
  318. this.IsSendNextCoustomGameFlag = true
  319. cc.systemEvent.emit(EventName.RoleStopBus)
  320. cc.systemEvent.emit(EventName.NextCoustomGameStop)
  321. cc.systemEvent.emit(EventName.CloseDoor)
  322. }
  323. }
  324. return
  325. }
  326. if (!RoleColor) {
  327. // cc.log('为空直接退出')
  328. return
  329. }
  330. if (MoveNode.getComponent(Role).MyColor != RoleColor) {
  331. console.log('乘客颜色不对');
  332. return
  333. }
  334. for (let index = 0; index < this.barrierLayer.children.length; index++) {
  335. const element = this.barrierLayer.children[index];
  336. if (element.getComponent(Sofa)?.SofaColor == RoleColor || (element.getComponent(Sofa)?.SofaColor == SofaColor.灰 && GraySitDownColor == RoleColor)) {
  337. let paths = element.getComponent(Sofa).getSitDownMapIndex()
  338. for (let k = 0; k < paths.length; k++) {
  339. const SubData = paths[k];
  340. let isOK = this.showPathsAndMove(cc.v2(SubData.x, SubData.y), SubData, MoveNode, isRightQueue)
  341. if (await isOK == true) {
  342. cc.systemEvent.emit(EventName.StartCountDown)
  343. //更新排队队列
  344. this.UpdateRoleQueue(isRightQueue)
  345. //如果是单人
  346. if (SubData.isleft == 0) {
  347. element.getComponent(Sofa).SofaSitDown = [1]
  348. } else {
  349. //如果是双人
  350. if (SubData.isleft == 1) {
  351. element.getComponent(Sofa).SofaSitDown[0] = 1
  352. }
  353. if (SubData.isleft == 2) {
  354. element.getComponent(Sofa).SofaSitDown[1] = 1
  355. }
  356. }
  357. return
  358. }
  359. }
  360. }
  361. }
  362. }
  363. async showPathsAndMove(targetPos: cc.Vec2, SubData, MoveNode: cc.Node, isRightQueue: boolean) {
  364. //起始点
  365. // console.time('findPath')
  366. let resultList
  367. if (isRightQueue == true) {
  368. // cc.log('----右侧---')
  369. resultList = await this.aStar.findePaths(cc.v2(MenX, MenY), targetPos)
  370. } else {
  371. // cc.log('----左侧---')
  372. resultList = await this.aStar.findePaths(cc.v2(MenXLeft, MenYLeft), targetPos)
  373. }
  374. if (resultList[0]) {
  375. let mapPosList = <[cc.Vec2]>resultList[1]
  376. // this.stork(resultList)
  377. this.playerMove(mapPosList, null, SubData, MoveNode, isRightQueue)
  378. return true
  379. } else {
  380. // cc.log('----找不到路径---')
  381. return null
  382. }
  383. }
  384. stork(resultList) {
  385. console.log('66');
  386. if (resultList[0]) {
  387. let mapPosList = <[cc.Vec2]>resultList[1]
  388. let pathLayer = this.node.parent.getChildByName('MapLayer').getChildByName('pathLayer')
  389. let gp = pathLayer.getComponent(cc.Graphics)
  390. gp.clear()
  391. // 画openList
  392. let closeList = <any[]>resultList[3]
  393. // cc.log('--openList---',closeList)
  394. for (let i = 0; i < closeList.length; i++) {
  395. let nodePos = this.getNodePosByMapPos(closeList[i].pos.x, closeList[i].pos.y)
  396. gp.fillRect(nodePos.x - tiledSize.width / 2, nodePos.y - tiledSize.height / 2, tiledSize.width, tiledSize.height)
  397. gp.strokeColor = new cc.Color().fromHEX('##B23FAB');
  398. gp.stroke()
  399. }
  400. // 画路径
  401. for (let i = 0; i < mapPosList.length; i++) {
  402. let nodePos = this.getNodePosByMapPos(mapPosList[i].x, mapPosList[i].y)
  403. gp.fillRect(nodePos.x - tiledSize.width / 2, nodePos.y - tiledSize.height / 2, tiledSize.width, tiledSize.height)
  404. gp.strokeColor = new cc.Color().fromHEX('#4B64BC9A');
  405. gp.stroke()
  406. }
  407. } else {
  408. // cc.log('----找不到路径---')
  409. }
  410. }
  411. UpdateRoleQueue(isright: boolean = true) {
  412. if (this.RoleQueueType == 1) {
  413. //右边的队列
  414. for (let index = 0; index < this.RoleQueue1.children.length; index++) {
  415. this.UpdateRolePos(this.RoleQueue1.children[index], this.RoleQueue1.children[index].position.x, index, true)
  416. }
  417. //第一个人是侧着站立
  418. this.RoleQueue1.children[0]?.getComponent(Role).QueueFirstIdle(true)
  419. }
  420. if (this.RoleQueueType == 2) {
  421. if (isright) {
  422. //右边的队列
  423. for (let index = 0; index < this.RoleQueue1.children.length; index++) {
  424. this.UpdateRolePos(this.RoleQueue1.children[index], this.RoleQueue1.children[index].position.x, index, true)
  425. }
  426. //第一个人是侧着站立
  427. this.RoleQueueFirst(this.RoleQueue1, true)
  428. } else {
  429. //左边的队列
  430. for (let index = 0; index < this.RoleQueue2.children.length; index++) {
  431. this.UpdateRolePos(this.RoleQueue2.children[index], this.RoleQueue2.children[index].position.x, index, false)
  432. }
  433. //第一个人是侧着站立
  434. this.RoleQueueFirst(this.RoleQueue2, false)
  435. }
  436. }
  437. HonorManger.getInstance().remainingpassengers = this.RoleQueue1.childrenCount + this.RoleQueue2.childrenCount
  438. }
  439. RoleQueueFirst(RoleQueue: cc.Node, isRightQueue: boolean) {
  440. for (let index = 0; index < RoleQueue.children.length; index++) {
  441. const element = RoleQueue.children[index];
  442. if (element) {
  443. if (index == 0) {
  444. element.getComponent(Role).QueueFirstIdle(isRightQueue)
  445. } else {
  446. element.getComponent(Role).QueueotherIdle(isRightQueue)
  447. }
  448. }
  449. }
  450. }
  451. getTargetPosInMap(MapPos: cc.Vec2) {
  452. return cc.v3(leftButtomStatPos.x + MapPos.x * tiledSize.width + tiledSize.width / 2, leftButtomStatPos.y + MapPos.y * tiledSize.height + tiledSize.height / 2)
  453. }
  454. //右侧追车路径
  455. Right_Path: number = 1400
  456. //左侧追车路径
  457. Left_Path: number = -1400
  458. //右侧追车时间
  459. Right_Path_time: number = 1
  460. //左侧追车时间
  461. Left_Path_time: number = 1
  462. //右侧排队间隔
  463. Right_Role_interval: number = 50
  464. //左侧排队间隔
  465. Left_Role_interval: number = 100
  466. UpdateRolePos(RoleNode: cc.Node, x, y, isRightQueue: boolean) {
  467. if (isRightQueue) {
  468. let move = cc.moveTo(this.e_first_run_time, cc.v2(x, - this.Right_Role_interval * y))
  469. RoleNode.runAction(move)
  470. } else {
  471. let move = cc.moveTo(this.e_first_run_time, cc.v2(x, + this.Left_Role_interval * y))
  472. RoleNode.runAction(move)
  473. }
  474. }
  475. playerMove(paths: [cc.Vec2], gp: cc.Graphics, SubData, MoveNode: cc.Node, isRightQueue: boolean) {
  476. let quance = []
  477. let startcallBack = cc.callFunc(() => {
  478. switch (SubData.isleft) {
  479. case 0:
  480. //单人
  481. SubData.slefNode.getComponent(Sofa).isTarget[0] = true
  482. break;
  483. case 1:
  484. //双人左
  485. SubData.slefNode.getComponent(Sofa).isTarget[0] = true
  486. break;
  487. case 2:
  488. //双人右
  489. SubData.slefNode.getComponent(Sofa).isTarget[1] = true
  490. break;
  491. default:
  492. break;
  493. }
  494. })
  495. quance.push(startcallBack)
  496. if (isRightQueue == true) {
  497. let name = MoveNode.parent.childrenCount
  498. //找到路径了在放置在第一位
  499. MoveNode.parent = this.barrierLayer
  500. MoveNode.name = name + ''
  501. //障碍物的是 200多 我们 333开始
  502. MoveNode.zIndex = (333 + (name))
  503. } else {
  504. let name = MoveNode.parent.childrenCount
  505. //找到路径了在放置在第一位
  506. MoveNode.parent = this.barrierLayer
  507. MoveNode.name = name + ''
  508. //障碍物的是 200多 我们 333开始
  509. MoveNode.zIndex = (333 + (99 - name))
  510. }
  511. let pos = this.gameLayer.convertToNodeSpaceAR(MoveNode.convertToWorldSpaceAR(MoveNode.position))
  512. MoveNode.setPosition(pos)
  513. if (isRightQueue == true) {
  514. quance.push(cc.callFunc(() => {
  515. MoveNode.getComponent(Role).setRoleAnimbyRun('左')
  516. }))
  517. // cc.log('----右侧---')
  518. let move = cc.moveTo(this.e_first_run_time, cc.v2(this.getNodePosByMapPos(MenX, MenY)))
  519. quance.push(move)
  520. } else {
  521. quance.push(cc.callFunc(() => {
  522. MoveNode.getComponent(Role).setRoleAnimbyRun('右')
  523. }))
  524. let move = cc.moveTo(this.e_first_run_time, cc.v2(this.getNodePosByMapPos(MenXLeft, MenYLeft)))
  525. quance.push(move)
  526. }
  527. for (let index = 0; index < paths.length; index++) {
  528. const path = paths[index];
  529. //添加移动路径
  530. let TargetPos = this.getNodePosByMapPos(path.x, path.y)
  531. let move
  532. if (index == 0) {
  533. move = cc.moveTo(0, cc.v2(TargetPos))
  534. } else {
  535. move = cc.moveTo(this.e_run_time, cc.v2(TargetPos))
  536. }
  537. //移动方向
  538. let MoveDir = cc.callFunc(() => {
  539. let NextPath = paths[index + 1];
  540. if (NextPath) {
  541. let NextTargetPos = this.getNodePosByMapPos(NextPath.x, NextPath.y)
  542. let xxx = TargetPos.x - NextTargetPos.x
  543. let yyy = TargetPos.y - NextTargetPos.y
  544. if (Math.abs(xxx) > 10) {
  545. if (xxx > 0) {
  546. // console.log('左');
  547. MoveNode.getComponent(Role).setRoleAnimbyRun('左')
  548. } else {
  549. // console.log('右');
  550. MoveNode.getComponent(Role).setRoleAnimbyRun('右')
  551. }
  552. }
  553. if (Math.abs(yyy) > 10) {
  554. if (xxx > 0) {
  555. // console.log('上');
  556. MoveNode.getComponent(Role).setRoleAnimbyRun('上')
  557. } else {
  558. // console.log('下');
  559. MoveNode.getComponent(Role).setRoleAnimbyRun('下')
  560. }
  561. }
  562. }
  563. })
  564. quance.push(move)
  565. quance.push(MoveDir)
  566. }
  567. let callBack = cc.callFunc(() => {
  568. // cc.log('---moveEnd--')
  569. //人物节点
  570. MoveNode.getComponent(Role).SitDown(SubData)
  571. })
  572. quance.push(callBack)
  573. MoveNode.stopAllActions()
  574. MoveNode.runAction(cc.sequence(quance))
  575. ///////////////////////////////////////////////////////////////////////////////////////
  576. }
  577. /**
  578. * 地图坐标转为节点坐标
  579. * @param x
  580. * @param y
  581. * @returns
  582. */
  583. getNodePosByMapPos(x: number, y: number) {
  584. x = Math.floor(x)
  585. y = Math.floor(y)
  586. let nodePos = cc.v3(leftButtomStatPos.x + x * tiledSize.width + tiledSize.width / 2, leftButtomStatPos.y + y * tiledSize.height + tiledSize.height / 2)
  587. return nodePos
  588. }
  589. }