PlayerController.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. _decorator,
  3. Component,
  4. Node,
  5. v3,
  6. Vec3,
  7. Vec2,
  8. v2,
  9. Prefab,
  10. instantiate,
  11. tween,
  12. KeyCode,
  13. director,
  14. } from "cc";
  15. import { GameEvent, GameMgr, Skill } from "../../module_basic/scripts/GameMgr";
  16. import { Cell } from "./Cell";
  17. import { PlayerMovement2D } from "./PlayerMovement2D";
  18. const { ccclass, property } = _decorator;
  19. const tempV2 = v2();
  20. @ccclass("PlayerController")
  21. export class PlayerController extends Component {
  22. @property(Node)
  23. firePoint: Node;
  24. @property(Node)
  25. barrel: Node;
  26. private _movement2d: PlayerMovement2D;
  27. start() {
  28. tgx.EasyController.on(
  29. tgx.EasyControllerEvent.BUTTON,
  30. this.onButtonHit,
  31. this
  32. );
  33. this._movement2d = this.node.getComponent(PlayerMovement2D);
  34. }
  35. onButtonHit(btnSlot: string) {
  36. if (btnSlot == "btn_skill_1") {
  37. if (GameMgr.inst.castSkill(Skill.SKILL_1)) {
  38. // this._cell.shoot();
  39. }
  40. } else if (btnSlot == "btn_skill_2") {
  41. if (GameMgr.inst.castSkill(Skill.SKILL_2)) {
  42. this._movement2d.tempSpeedUp(2.0, 3000);
  43. }
  44. } else if (btnSlot == "btn_spawn") {
  45. director.emit(GameEvent.LOCAL_PLAYER_SPAWN);
  46. }
  47. }
  48. onDestroy() {
  49. tgx.EasyController.off(
  50. tgx.EasyControllerEvent.BUTTON,
  51. this.onButtonHit,
  52. this
  53. );
  54. }
  55. }