FGass.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import FObject, { GroupType } from "../object/FObject";
  2. import FF from "../FF";
  3. import DialogSay from "../box/DialogSay";
  4. import FSprite from "../object/FSprite";
  5. import CMath from "../../../util/CMath";
  6. /**
  7. * 草丛中对话和刷新怪物
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class FGass extends cc.Component {
  12. @property({
  13. type:cc.Prefab,
  14. displayName: '对话框'
  15. })
  16. mDialog: cc.Prefab = null;
  17. @property({
  18. type:[cc.String],
  19. displayName: '对话内容'
  20. })
  21. mContents: Array<string> = [];
  22. @property({
  23. type:[cc.Prefab],
  24. displayName: '对话完成刷怪'
  25. })
  26. mMonster: Array<cc.Prefab> = [];
  27. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  28. if(otherCollider.node.group == 'A'){
  29. let sobject = otherCollider.node.getComponent(FObject);
  30. if(sobject){
  31. this.node.removeComponent(cc.PhysicsBoxCollider);
  32. let ff = sobject.ff;
  33. ff.stopRuning();
  34. this.showDialog(ff);
  35. }
  36. }
  37. }
  38. public showDialog(ff:FF){
  39. let node = cc.instantiate(this.mDialog);
  40. ff.main.viewManage.popView(node);
  41. let dialog:DialogSay = node.getComponent(DialogSay);
  42. dialog.setContents(this.mContents);
  43. dialog.setEndCallback(()=>{
  44. ff.startRuning();
  45. this.flushMonster(ff);
  46. });
  47. }
  48. public flushMonster(ff:FF){
  49. for (let i = 0; i < this.mMonster.length; i++) {
  50. // let node: cc.Node = cc.instantiate(this.mMonster[i]);
  51. // let sp: FSprite = node.getComponent(FSprite);
  52. // sp.node.group = GroupType.B;
  53. // sp.fData = ff.main.sManage.getMonsterData(1001);
  54. // node.setPosition(this.getRandInit());
  55. // ff.mMap.addSprite(sp);
  56. }
  57. }
  58. public getRandInit(): cc.Vec2 {
  59. let pos = cc.v2();
  60. pos.x = CMath.getRandom(this.node.x - this.node.width / 2, this.node.x + this.node.width / 2);
  61. pos.y = CMath.getRandom(this.node.y - this.node.height / 2, this.node.y + this.node.height / 2);
  62. return pos;
  63. }
  64. }