JG0106_1.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import BaseEvent from "../../fight/evnet/base/BaseEvent";
  2. import AIPet from "../../fight/object/AI/AIPet";
  3. import { SpriteActionType } from "../../fight/object/FSprite";
  4. import PSprite from "../../fight/object/PSprite";
  5. /**
  6. * 带着小鹿走。
  7. 小鹿走到拿钥匙的地方不再走,趴在地上,肚子饿的咕咕声。
  8. 角色:或许它饿了。
  9. 角色:在附近找一找吃的。
  10. 采集浆果。
  11. 直到采集4个给小鹿吃,小鹿才起身,跟着角色走。
  12. */
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class JG0106_1 extends BaseEvent {
  16. @property({
  17. type:cc.Node,
  18. displayName: '宠物碰撞位置'
  19. })
  20. public mPetNode:cc.Node = null;
  21. /**
  22. * 主角进入碰撞区域
  23. * @param tag 碰撞组件编号
  24. */
  25. public onBegin(tag: number) {
  26. this.pettl()
  27. this.pause()
  28. this.ff.mainSprite.stopMove()
  29. this.ff.mainSprite.playAction(SpriteActionType.run,true)
  30. cc.tween(this.ff.mainSprite.node).sequence(
  31. cc.moveBy(0.5,cc.v2(-20,0)),
  32. cc.callFunc(()=>{
  33. this.ff.mainSprite.playAction(SpriteActionType.stand,true)
  34. this.ff.mainSprite.setLR(1)
  35. this.dialog()
  36. let sprite:PSprite = this.getPet() as PSprite;
  37. this.mPetNode.x = sprite.node.x
  38. this.mPetNode.y = sprite.node.y
  39. })
  40. ).start()
  41. }
  42. /**
  43. * 宠物脱离队伍
  44. */
  45. private pettl(){
  46. let sprite:PSprite = this.getPet() as PSprite;
  47. sprite.inFront = null
  48. sprite.playAction(SpriteActionType.dead,false)
  49. sprite.node.removeComponent(AIPet)
  50. }
  51. private getPet(){
  52. let sprites = this.ff.getGroupBy('A')
  53. for (let i = 0; i < sprites.length; i++) {
  54. const element = sprites[i];
  55. if(element != this.ff.mainSprite){
  56. return element
  57. }
  58. }
  59. }
  60. private dialog(){
  61. let text = [
  62. '或许它饿了。',
  63. '在附近找一找吃的。',
  64. ]
  65. this.showDialog(this.ff.mainSprite.node,text,()=>{
  66. this.resume()
  67. this.node.destroy()
  68. })
  69. }
  70. }