BallPauseTest.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { _decorator, Component, Node, KeyCode, input, Input, EventKeyboard } from 'cc';
  2. import EventBus, { GameEvents } from '../Core/EventBus';
  3. const { ccclass, property } = _decorator;
  4. /**
  5. * 小球暂停模式测试脚本
  6. * 用于测试技能选择暂停和底板选择暂停的不同表现
  7. */
  8. @ccclass('BallPauseTest')
  9. export class BallPauseTest extends Component {
  10. start() {
  11. // 监听键盘事件
  12. input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
  13. console.log('[BallPauseTest] 测试脚本已启动');
  14. console.log('[BallPauseTest] 按键说明:');
  15. console.log('[BallPauseTest] 1 - 触发技能选择暂停(所有小球停止)');
  16. console.log('[BallPauseTest] 2 - 触发底板选择暂停(所有小球继续运动)');
  17. console.log('[BallPauseTest] 3 - 恢复游戏');
  18. console.log('[BallPauseTest] 4 - 创建额外小球(用于测试多球暂停)');
  19. }
  20. private onKeyDown(event: EventKeyboard) {
  21. const eventBus = EventBus.getInstance();
  22. switch (event.keyCode) {
  23. case KeyCode.DIGIT_1:
  24. console.log('[BallPauseTest] 触发技能选择暂停 - 所有小球应该停止运动');
  25. eventBus.emit(GameEvents.GAME_PAUSE_SKILL_SELECTION);
  26. break;
  27. case KeyCode.DIGIT_2:
  28. console.log('[BallPauseTest] 触发底板选择暂停 - 所有小球应该继续运动');
  29. eventBus.emit(GameEvents.GAME_PAUSE_BLOCK_SELECTION);
  30. break;
  31. case KeyCode.DIGIT_3:
  32. console.log('[BallPauseTest] 恢复游戏 - 恢复所有小球运动');
  33. eventBus.emit(GameEvents.GAME_RESUME);
  34. break;
  35. case KeyCode.DIGIT_4:
  36. console.log('[BallPauseTest] 创建额外小球');
  37. eventBus.emit(GameEvents.BALL_CREATE_ADDITIONAL);
  38. break;
  39. }
  40. }
  41. onDestroy() {
  42. // 清理键盘事件监听
  43. input.off(Input.EventType.KEY_DOWN, this.onKeyDown, this);
  44. }
  45. }