123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import { SofaColor, SofaDir } from "../EventName/EventName";
- import AudioManager from "../GameUI/AudioManager";
- import Down from "../GameUI/Down";
- import RoleQueue from "./RoleQueue";
- import Sofa from "./Sofa";
- import BarrierDrag from "./barrierDrag";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Role extends cc.Component {
- @property(sp.SkeletonData)
- Zhengmian: sp.SkeletonData = null
- @property(sp.SkeletonData)
- BeiMian: sp.SkeletonData = null
- @property(sp.SkeletonData)
- CeMian: sp.SkeletonData = null
- MysPsKeleton: sp.Skeleton = null
- MyColor: SofaColor
- start() {
- }
- setColor() {
- switch (this.MyColor) {
- case SofaColor.蓝:
- this.MysPsKeleton.setSkin('蓝')
- break;
- case SofaColor.灰:
- console.log('没有这个灰色颜色的人物');
- break;
- case SofaColor.粉:
- this.MysPsKeleton.setSkin('粉')
- break;
- case SofaColor.红:
- this.MysPsKeleton.setSkin('红')
- break;
- case SofaColor.黄:
- this.MysPsKeleton.setSkin('黄')
- break;
- default:
- break;
- }
- }
- init(RoleColor: SofaColor) {
- this.MysPsKeleton = this.node.getComponent(sp.Skeleton)
- this.MyColor = RoleColor
- this.setColor()
- //待机_站 待机_坐 坐 走路
- this.MysPsKeleton.setAnimation(0, '待机_站', true)
- }
- SofaComponent: Sofa
- //坐下
- SitDown(SubData: { x: number, y: number, isleft: number, slefNode: cc.Node }) {
- // console.log('坐下了得到');
- this.SofaComponent = SubData.slefNode.getComponent(Sofa)
- //切换父节点 自身位置修改
- let pos = SubData.slefNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))
- this.node.parent = SubData.slefNode
- this.node.setSiblingIndex(0)
- this.node.setPosition(pos)
-
- //执行并且得到入座时间
- let JumpSitDownTime = this.getRoleAnim().time
- let targetPos = cc.v3(0, 0)
- switch (SubData.isleft) {
- case 0:
- //单人
- // targetPos =cc.v3(0, 0)
- break;
- case 1:
- //双人左
- // targetPos =cc.v3(0, 0)
- break;
- case 2:
- //双人右
- targetPos = cc.v3(77, 0)
- break;
- default:
- break;
- }
- cc.tween(this.node)
- .to(JumpSitDownTime * 0.85 * 0.5, { position: targetPos })
- // .to(JumpSitDownTime, { position: targetPos }, { easing: dt => cc.easeBounceIn().easing(dt) })
- .call(() => {
- AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1)
- RoleQueue.SitdownRole++
- this.SofaComponent.isLock = false
- this.SofaComponent.NodeBarrierDragComp.ShowLock()
- switch (SubData.isleft) {
- case 0:
- //单人
- this.SofaComponent.isTarget[0] = false
- break;
- case 1:
- //双人左
- this.SofaComponent.isTarget[0] = false
- break;
- case 2:
- //双人右
- this.SofaComponent.isTarget[1] = false
- break;
- default:
- break;
- }
- })
- .start()
- }
- //弹射
- NowSitDowAni(targetNode: cc.Node, isleft: number, SeatColor: SofaColor, Sofadir: SofaDir) {
- this.SofaComponent = targetNode.getComponent(Sofa)
- Down.NowJumping = false
- let pos = targetNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0)))
- this.node.parent = targetNode
- this.node.setSiblingIndex(0)
- this.node.setPosition(pos)
- let time = 0
- let dddd = this.MysPsKeleton.setAnimation(0, '弹射', false)
- time = dddd.animationEnd
- this.scheduleOnce(() => {
- if (this.node.isValid) {
- let time1 = 0
- if (Sofadir == SofaDir.反) {
- this.MysPsKeleton.skeletonData = this.BeiMian
- } else {
- this.MysPsKeleton.skeletonData = this.Zhengmian
- }
- this.setColor()
- time1 = this.MysPsKeleton.setAnimation(0, '弹射', false).animationEnd
- this.scheduleOnce(() => {
- this.setColor()
- time1 = this.MysPsKeleton.setAnimation(0, '待机_坐', true).animationEnd
- }, time1)
- }
- }, time)
- let pos1
- //实际坐在哪个位置
- let downseatIndex = 0
- switch (isleft) {
- case 0:
- //单人
- this.SofaComponent.isTarget[0] = true
- this.SofaComponent.SofaSitDown[0] = 1
- pos1 = cc.v2(0, 0)
- downseatIndex = 0
- break;
- case 1:
- //双人左
- if (this.SofaComponent.SofaSitDown[0] == 0) {
- this.SofaComponent.isTarget[0] = true
- this.SofaComponent.SofaSitDown[0] = 1
- pos1 = cc.v2(0, 0)
- downseatIndex = 1
- } else {
- this.SofaComponent.isTarget[1] = true
- this.SofaComponent.SofaSitDown[1] = 1
- pos1 = cc.v2(77, 0)
- downseatIndex = 2
- }
- break;
- case 2:
- //双人右
- if (this.SofaComponent.SofaSitDown[1] == 0) {
- this.SofaComponent.isTarget[1] = true
- this.SofaComponent.SofaSitDown[1] = 1
- pos1 = cc.v2(77, 0)
- downseatIndex = 2
- } else {
- this.SofaComponent.isTarget[0] = true
- this.SofaComponent.SofaSitDown[0] = 1
- pos1 = cc.v2(0, 0)
- downseatIndex = 1
- }
- break;
- default:
- break;
- }
- this.scheduleOnce(() => {
- cc.tween(this.node)
- .to(1.26, { position: pos1 }, { easing: 'sineOut' })
- .call(() => {
- AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1)
- RoleQueue.SitdownRole++
- switch (downseatIndex) {
- case 0:
- //单人
- this.SofaComponent.isTarget[0] = false
- break;
- case 1:
- //双人左
- this.SofaComponent.isTarget[0] = false
- break;
- case 2:
- //双人右
- this.SofaComponent.isTarget[1] = false
- break;
- default:
- break;
- }
- this.SofaComponent.isLock = false
- this.SofaComponent.NodeBarrierDragComp.ShowLock()
- })
- .start()
- }, 0.06)
- }
- getRoleAnim() {
- let time = 0
- if (this.SofaComponent.NodeBarrierDragComp.MyisDouble()) {
- if (this.SofaComponent.Sofadir === SofaDir.正) {
- // console.log('zheng');
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.MysPsKeleton.timeScale = 2
- this.setColor()
- let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
- time = dddd.animationEnd
- this.scheduleOnce(() => {
- if (this.node.isValid) {
- this.MysPsKeleton.setAnimation(0, '待机_坐', true)
- }
- }, time)
- } else {
- // console.log('fan');
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.MysPsKeleton.timeScale = 2
- this.setColor()
- let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
- time = dddd.animationEnd
- this.scheduleOnce(() => {
- if (this.node.isValid) {
- this.MysPsKeleton.setAnimation(0, '待机_坐', true)
- }
- }, time)
- }
- } else {
- if (this.SofaComponent.Sofadir === SofaDir.正) {
- // console.log('zheng');
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.MysPsKeleton.timeScale = 2
- this.setColor()
- let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
- time = dddd.animationEnd
- this.scheduleOnce(() => {
- if (this.node.isValid) {
- this.MysPsKeleton.setAnimation(0, '待机_坐', true)
- }
- }, time)
- } else {
- // console.log('fan');
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.MysPsKeleton.timeScale = 2
- this.setColor()
- let dddd = this.MysPsKeleton.setAnimation(0, '坐', false)
- time = dddd.animationEnd
- this.scheduleOnce(() => {
- if (this.node.isValid) {
- this.MysPsKeleton.setAnimation(0, '待机_坐', true)
- }
- }, time)
- }
- }
- return { time }
- }
- // update (dt) {}
- lastDir: string = ''
- //坐下
- setRoleAnimbyRun(dir: string) {
- if (this.lastDir == dir) {
- return
- }
- switch (dir) {
- case '左':
- this.MysPsKeleton.skeletonData = this.CeMian
- this.setColor()
- this.node.scaleX = -0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- case '右':
- this.MysPsKeleton.skeletonData = this.CeMian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- case '上':
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- case '下':
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- default:
- break;
- }
- this.lastDir = dir
- }
- run(dir: string) {
- switch (dir) {
- case '上':
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- case '下':
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '走路', true)
- break;
- default:
- break;
- }
- }
- idle(dir: string) {
- switch (dir) {
- case '上':
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '待机_站', true)
- break;
- case '下':
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.setColor()
- this.node.scaleX = 0.2
- this.MysPsKeleton.setAnimation(0, '待机_站', true)
- break;
- default:
- break;
- }
- }
- //队伍第一站立
- QueueFirstIdle(isRightQueue: boolean) {
- //如果是右边的队列
- this.MysPsKeleton.skeletonData = this.CeMian
- this.setColor()
- if (isRightQueue == true) {
- this.node.scaleX = -0.2
- } else {
- // console.log(isRightQueue);
- this.node.scaleX = 0.2
- }
- this.MysPsKeleton.setAnimation(0, '眨眼', true)
- }
- //其他人
- QueueotherIdle(isRightQueue: boolean) {
- //如果是右边的队列
- if (isRightQueue == false) {
- this.MysPsKeleton.skeletonData = this.BeiMian
- this.setColor()
- this.MysPsKeleton.setAnimation(0, '待机_站', true)
- } else {
- this.MysPsKeleton.skeletonData = this.Zhengmian
- this.setColor()
- this.MysPsKeleton.setAnimation(0, '待机_站', true)
- }
- }
- }
|