JG0106_1.ts 2.2 KB

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