Role.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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 { SofaColor, SofaDir } from "../EventName/EventName";
  8. import AudioManager from "../GameUI/AudioManager";
  9. import Down from "../GameUI/Down";
  10. import RoleQueue from "./RoleQueue";
  11. import Sofa from "./Sofa";
  12. import BarrierDrag from "./barrierDrag";
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class Role extends cc.Component {
  16. @property(sp.SkeletonData)
  17. Zhengmian: sp.SkeletonData = null
  18. @property(sp.SkeletonData)
  19. BeiMian: sp.SkeletonData = null
  20. @property(sp.SkeletonData)
  21. CeMian: sp.SkeletonData = null
  22. MysPsKeleton: sp.Skeleton = null
  23. MyColor: SofaColor
  24. start() {
  25. }
  26. setColor() {
  27. switch (this.MyColor) {
  28. case SofaColor.蓝:
  29. this.MysPsKeleton.setSkin('蓝')
  30. break;
  31. case SofaColor.灰:
  32. console.log('没有这个灰色颜色的人物');
  33. break;
  34. case SofaColor.粉:
  35. this.MysPsKeleton.setSkin('粉')
  36. break;
  37. case SofaColor.红:
  38. this.MysPsKeleton.setSkin('红')
  39. break;
  40. case SofaColor.黄:
  41. this.MysPsKeleton.setSkin('黄')
  42. break;
  43. default:
  44. break;
  45. }
  46. }
  47. init(RoleColor: SofaColor) {
  48. this.MysPsKeleton = this.node.getComponent(sp.Skeleton)
  49. this.MyColor = RoleColor
  50. this.setColor()
  51. //待机_站 待机_坐 坐 走路
  52. this.MysPsKeleton.setAnimation(0, '待机_站', true)
  53. }
  54. SofaComponent: Sofa
  55. //坐下
  56. SitDown(SubData: { x: number, y: number, isleft: number, slefNode: cc.Node }) {
  57. // console.log('坐下了得到');
  58. this.SofaComponent = SubData.slefNode.getComponent(Sofa)
  59. //切换父节点 自身位置修改
  60. let pos = SubData.slefNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))
  61. this.node.parent = SubData.slefNode
  62. this.node.setSiblingIndex(0)
  63. this.node.setPosition(pos)
  64. //执行并且得到入座时间
  65. let JumpSitDownTime = this.getRoleAnim().time
  66. let targetPos = cc.v3(0, 0)
  67. switch (SubData.isleft) {
  68. case 0:
  69. //单人
  70. // targetPos =cc.v3(0, 0)
  71. break;
  72. case 1:
  73. //双人左
  74. // targetPos =cc.v3(0, 0)
  75. break;
  76. case 2:
  77. //双人右
  78. targetPos = cc.v3(77, 0)
  79. break;
  80. default:
  81. break;
  82. }
  83. cc.tween(this.node)
  84. .to(JumpSitDownTime * 0.85 * 0.5, { position: targetPos })
  85. // .to(JumpSitDownTime, { position: targetPos }, { easing: dt => cc.easeBounceIn().easing(dt) })
  86. .call(() => {
  87. AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1)
  88. RoleQueue.SitdownRole++
  89. this.SofaComponent.isLock = false
  90. this.SofaComponent.NodeBarrierDragComp.ShowLock()
  91. switch (SubData.isleft) {
  92. case 0:
  93. //单人
  94. this.SofaComponent.isTarget[0] = false
  95. break;
  96. case 1:
  97. //双人左
  98. this.SofaComponent.isTarget[0] = false
  99. break;
  100. case 2:
  101. //双人右
  102. this.SofaComponent.isTarget[1] = false
  103. break;
  104. default:
  105. break;
  106. }
  107. })
  108. .start()
  109. }
  110. //弹射
  111. NowSitDowAni(targetNode: cc.Node, isleft: number, SeatColor: SofaColor, Sofadir: SofaDir) {
  112. this.SofaComponent = targetNode.getComponent(Sofa)
  113. Down.NowJumping = false
  114. let pos = targetNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))
  115. this.node.parent = targetNode
  116. this.node.setSiblingIndex(0)
  117. this.node.setPosition(pos)
  118. let time = 0
  119. let dddd = this.MysPsKeleton.setAnimation(0, '弹射', false)
  120. time = dddd.animationEnd
  121. this.scheduleOnce(() => {
  122. if (this.node.isValid) {
  123. let time1 = 0
  124. if (Sofadir == SofaDir.反) {
  125. this.MysPsKeleton.skeletonData = this.BeiMian
  126. } else {
  127. this.MysPsKeleton.skeletonData = this.Zhengmian
  128. }
  129. this.setColor()
  130. time1 = this.MysPsKeleton.setAnimation(0, '弹射', false).animationEnd
  131. this.scheduleOnce(() => {
  132. this.setColor()
  133. time1 = this.MysPsKeleton.setAnimation(0, '待机_坐', true).animationEnd
  134. }, time1)
  135. }
  136. }, time)
  137. let pos1
  138. //实际坐在哪个位置
  139. let downseatIndex = 0
  140. switch (isleft) {
  141. case 0:
  142. //单人
  143. this.SofaComponent.isTarget[0] = true
  144. this.SofaComponent.SofaSitDown[0] = 1
  145. pos1 = cc.v2(0, 0)
  146. downseatIndex = 0
  147. break;
  148. case 1:
  149. //双人左
  150. if (this.SofaComponent.SofaSitDown[0] == 0) {
  151. this.SofaComponent.isTarget[0] = true
  152. this.SofaComponent.SofaSitDown[0] = 1
  153. pos1 = cc.v2(0, 0)
  154. downseatIndex = 1
  155. } else {
  156. this.SofaComponent.isTarget[1] = true
  157. this.SofaComponent.SofaSitDown[1] = 1
  158. pos1 = cc.v2(77, 0)
  159. downseatIndex = 2
  160. }
  161. break;
  162. case 2:
  163. //双人右
  164. if (this.SofaComponent.SofaSitDown[1] == 0) {
  165. this.SofaComponent.isTarget[1] = true
  166. this.SofaComponent.SofaSitDown[1] = 1
  167. pos1 = cc.v2(77, 0)
  168. downseatIndex = 2
  169. } else {
  170. this.SofaComponent.isTarget[0] = true
  171. this.SofaComponent.SofaSitDown[0] = 1
  172. pos1 = cc.v2(0, 0)
  173. downseatIndex = 1
  174. }
  175. break;
  176. default:
  177. break;
  178. }
  179. this.scheduleOnce(() => {
  180. cc.tween(this.node)
  181. .to(1.26, { position: pos1 }, { easing: 'sineOut' })
  182. .call(() => {
  183. AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1)
  184. RoleQueue.SitdownRole++
  185. switch (downseatIndex) {
  186. case 0:
  187. //单人
  188. this.SofaComponent.isTarget[0] = false
  189. break;
  190. case 1:
  191. //双人左
  192. this.SofaComponent.isTarget[0] = false
  193. break;
  194. case 2:
  195. //双人右
  196. this.SofaComponent.isTarget[1] = false
  197. break;
  198. default:
  199. break;
  200. }
  201. this.SofaComponent.isLock = false
  202. this.SofaComponent.NodeBarrierDragComp.ShowLock()
  203. })
  204. .start()
  205. }, 0.06)
  206. }
  207. getRoleAnim() {
  208. let time = 0
  209. if (this.SofaComponent.NodeBarrierDragComp.MyisDouble()) {
  210. if (this.SofaComponent.Sofadir === SofaDir.正) {
  211. // console.log('zheng');
  212. this.MysPsKeleton.skeletonData = this.Zhengmian
  213. this.MysPsKeleton.timeScale = 2
  214. this.setColor()
  215. let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
  216. time = dddd.animationEnd
  217. this.scheduleOnce(() => {
  218. if (this.node.isValid) {
  219. this.MysPsKeleton.setAnimation(0, '待机_坐', true)
  220. }
  221. }, time)
  222. } else {
  223. // console.log('fan');
  224. this.MysPsKeleton.skeletonData = this.BeiMian
  225. this.MysPsKeleton.timeScale = 2
  226. this.setColor()
  227. let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
  228. time = dddd.animationEnd
  229. this.scheduleOnce(() => {
  230. if (this.node.isValid) {
  231. this.MysPsKeleton.setAnimation(0, '待机_坐', true)
  232. }
  233. }, time)
  234. }
  235. } else {
  236. if (this.SofaComponent.Sofadir === SofaDir.正) {
  237. // console.log('zheng');
  238. this.MysPsKeleton.skeletonData = this.Zhengmian
  239. this.MysPsKeleton.timeScale = 2
  240. this.setColor()
  241. let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
  242. time = dddd.animationEnd
  243. this.scheduleOnce(() => {
  244. if (this.node.isValid) {
  245. this.MysPsKeleton.setAnimation(0, '待机_坐', true)
  246. }
  247. }, time)
  248. } else {
  249. // console.log('fan');
  250. this.MysPsKeleton.skeletonData = this.BeiMian
  251. this.MysPsKeleton.timeScale = 2
  252. this.setColor()
  253. let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
  254. time = dddd.animationEnd
  255. this.scheduleOnce(() => {
  256. if (this.node.isValid) {
  257. this.MysPsKeleton.setAnimation(0, '待机_坐', true)
  258. }
  259. }, time)
  260. }
  261. }
  262. return { time }
  263. }
  264. // update (dt) {}
  265. lastDir: string = ''
  266. //坐下
  267. setRoleAnimbyRun(dir: string) {
  268. if (this.lastDir == dir) {
  269. return
  270. }
  271. switch (dir) {
  272. case '左':
  273. this.MysPsKeleton.skeletonData = this.CeMian
  274. this.setColor()
  275. this.node.scaleX = -0.2
  276. this.MysPsKeleton.setAnimation(0, '走路', true)
  277. break;
  278. case '右':
  279. this.MysPsKeleton.skeletonData = this.CeMian
  280. this.setColor()
  281. this.node.scaleX = 0.2
  282. this.MysPsKeleton.setAnimation(0, '走路', true)
  283. break;
  284. case '上':
  285. this.MysPsKeleton.skeletonData = this.Zhengmian
  286. this.setColor()
  287. this.node.scaleX = 0.2
  288. this.MysPsKeleton.setAnimation(0, '走路', true)
  289. break;
  290. case '下':
  291. this.MysPsKeleton.skeletonData = this.BeiMian
  292. this.setColor()
  293. this.node.scaleX = 0.2
  294. this.MysPsKeleton.setAnimation(0, '走路', true)
  295. break;
  296. default:
  297. break;
  298. }
  299. this.lastDir = dir
  300. }
  301. run(dir: string) {
  302. switch (dir) {
  303. case '上':
  304. this.MysPsKeleton.skeletonData = this.Zhengmian
  305. this.setColor()
  306. this.node.scaleX = 0.2
  307. this.MysPsKeleton.setAnimation(0, '走路', true)
  308. break;
  309. case '下':
  310. this.MysPsKeleton.skeletonData = this.BeiMian
  311. this.setColor()
  312. this.node.scaleX = 0.2
  313. this.MysPsKeleton.setAnimation(0, '走路', true)
  314. break;
  315. default:
  316. break;
  317. }
  318. }
  319. idle(dir: string) {
  320. switch (dir) {
  321. case '上':
  322. this.MysPsKeleton.skeletonData = this.Zhengmian
  323. this.setColor()
  324. this.node.scaleX = 0.2
  325. this.MysPsKeleton.setAnimation(0, '待机_站', true)
  326. break;
  327. case '下':
  328. this.MysPsKeleton.skeletonData = this.BeiMian
  329. this.setColor()
  330. this.node.scaleX = 0.2
  331. this.MysPsKeleton.setAnimation(0, '待机_站', true)
  332. break;
  333. default:
  334. break;
  335. }
  336. }
  337. //队伍第一站立
  338. QueueFirstIdle(isRightQueue: boolean) {
  339. //如果是右边的队列
  340. this.MysPsKeleton.skeletonData = this.CeMian
  341. this.setColor()
  342. if (isRightQueue == true) {
  343. this.node.scaleX = -0.2
  344. } else {
  345. // console.log(isRightQueue);
  346. this.node.scaleX = 0.2
  347. }
  348. this.MysPsKeleton.setAnimation(0, '眨眼', true)
  349. }
  350. //其他人
  351. QueueotherIdle(isRightQueue: boolean) {
  352. //如果是右边的队列
  353. if (isRightQueue == false) {
  354. this.MysPsKeleton.skeletonData = this.BeiMian
  355. this.setColor()
  356. this.MysPsKeleton.setAnimation(0, '待机_站', true)
  357. } else {
  358. this.MysPsKeleton.skeletonData = this.Zhengmian
  359. this.setColor()
  360. this.MysPsKeleton.setAnimation(0, '待机_站', true)
  361. }
  362. }
  363. }