GameProp1002.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 AudioManager from "../AudioManager";
  8. import Character from "../Character/Character";
  9. import EventName from "../EventName/EventName";
  10. import LocalData from "../LocalData";
  11. import MyMap from "../Map/MyMap";
  12. import RewardMnr from "../Template/RewardMnr";
  13. import Prop from "./Prop";
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class GameProp1002 extends Prop {
  17. // onLoad () {}
  18. //触发几次获得奖励
  19. triggerCount = 1
  20. //完事之后自己是否消失
  21. IsDeleteMe = true
  22. protected onEnable(): void {
  23. this.node.active = RewardMnr.getInstance().isEnable(this.Flag())
  24. }
  25. onCollisionEnter(other: cc.CircleCollider, self: cc.BoxCollider) {
  26. if (this.triggerCount <= 0) {
  27. console.error('失效了');
  28. this.getComponent(cc.BoxCollider).enabled = false
  29. return
  30. }
  31. //如果碰撞了玩家
  32. if (other.node.getComponent(Character)) {
  33. this.triggerCount--
  34. if (this.triggerCount <= 0 && this.IsDeleteMe) {
  35. this.Reaward()
  36. }
  37. }
  38. }
  39. //奖励的方法
  40. Reaward() {
  41. let RoundState = this.getComponentInChildren(sp.Skeleton).setAnimation(0, '奖杯', false);
  42. this.scheduleOnce(() => {
  43. let NextLevel = cc.Canvas.instance.node.getChildByName('Map').getComponent(MyMap).MapjsonData.NextLevel
  44. if (!NextLevel) {
  45. console.log('通关');
  46. if (LocalData.getInstance().getOverCount() == 0) {//首次通关
  47. LocalData.getInstance().setOverCount(1)
  48. } else {
  49. LocalData.getInstance().setOverCount(LocalData.getInstance().getOverCount() + 1)
  50. }
  51. LocalData.getInstance().setMap(1)
  52. cc.systemEvent.emit(EventName.Over);
  53. this.scheduleOnce(() => {
  54. cc.director.loadScene("Hall")
  55. }, 3)
  56. return
  57. }
  58. LocalData.getInstance().setMap(NextLevel)
  59. if (NextLevel > 0) {
  60. cc.director.loadScene("Game")
  61. } else {
  62. cc.director.loadScene("Hall")
  63. }
  64. }, RoundState.animationEnd)
  65. }
  66. }