PlayerPawnInput.re.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import * as RE from 'rogue-engine';
  2. import RapierMovementController from './RapierMovementController.re';
  3. import ShipCannonController from './ShipCannonController.re';
  4. export default class PlayerPawnInput extends RE.Component {
  5. movementController:RapierMovementController
  6. cannonController:ShipCannonController
  7. awake() {
  8. }
  9. start() {
  10. this.object3d.traverse(obj => {
  11. const components = RE.getObjectComponents(obj);
  12. components.forEach(comp => {
  13. if (comp instanceof RapierMovementController) {
  14. this.movementController = comp
  15. }
  16. });
  17. });
  18. this.object3d.traverse(obj => {
  19. const components = RE.getObjectComponents(obj);
  20. components.forEach(comp => {
  21. if (comp instanceof ShipCannonController) {
  22. this.cannonController = comp
  23. }
  24. });
  25. });
  26. }
  27. update() {
  28. if (RE.Input.keyboard.getKeyPressed("KeyW")) {
  29. this.movementController.thrust = true
  30. }
  31. if (RE.Input.keyboard.getKeyPressed("KeyA")) {
  32. this.movementController.rotateLeft = true
  33. }
  34. if (RE.Input.keyboard.getKeyPressed("KeyS")) {
  35. this.movementController.brake = true
  36. }
  37. if (RE.Input.keyboard.getKeyPressed("KeyD")) {
  38. this.movementController.rotateRight = true
  39. }
  40. if(RE.Input.keyboard.getKeyDown("Space")) {
  41. this.cannonController.fireLeft = true
  42. this.cannonController.fireRight = true
  43. this.cannonController.fireForward = true
  44. }
  45. }
  46. }
  47. RE.registerComponent(PlayerPawnInput);