gameLogic.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import dungeonLogic from "./dungeonLogic";
  2. import LevelLogic from "./levelLogic";
  3. import gameData from "./utrl/gameData";
  4. import { ATTACK_MODE, EVENT_TYPE } from "./utrl/gameEnum";
  5. import gameEventManager from "./utrl/gameEventManager";
  6. const { ccclass, property } = cc._decorator;
  7. /**游戏主逻辑 */
  8. @ccclass
  9. export default class GameLogic extends cc.Component {
  10. @property(cc.Node)
  11. /**摄像机节点 */
  12. camera: cc.Node = null;
  13. @property(cc.Prefab)
  14. /**玩家预制体 */
  15. player_pre: cc.Prefab = null;
  16. @property(cc.Prefab)
  17. /**僵尸预制体 */
  18. zombie_pre: cc.Prefab = null;
  19. /**子弹预制体 */
  20. @property(cc.Prefab)
  21. bullet_pre: cc.Prefab = null;
  22. /**迷你地图节点 */
  23. @property(cc.Node)
  24. mini_map: cc.Node = null;
  25. /**当前关卡逻辑 */
  26. private level_logic: LevelLogic = null;
  27. /**当前副本逻辑 */
  28. private dungeon_logic: dungeonLogic = null;
  29. onLoad() {
  30. let pm = cc.director.getPhysicsManager();
  31. pm.enabled = true;
  32. }
  33. /**初始化 */
  34. init(level: cc.Node,isNew = false) {
  35. this.level_logic = level.getComponent(LevelLogic);
  36. this.level_logic.setMiniMap(this.mini_map);
  37. this.level_logic.init(this.camera, this.player_pre, this.zombie_pre, this.bullet_pre,isNew);
  38. }
  39. //副本初始化
  40. dungeonInit(dungeon: cc.Node) {
  41. this.dungeon_logic = dungeon.getComponent(dungeonLogic);
  42. this.dungeon_logic.init(this.camera, this.player_pre, this.zombie_pre, this.bullet_pre);
  43. }
  44. /**切换攻击模式 */
  45. switchAttackMode() {
  46. if (gameData.cur_attack_mode == ATTACK_MODE.close) {
  47. gameData.cur_attack_mode = ATTACK_MODE.remote;
  48. }
  49. else {
  50. gameData.cur_attack_mode = ATTACK_MODE.close;
  51. }
  52. gameEventManager.emit(EVENT_TYPE.attack_mode);
  53. }
  54. }