1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import * as RE from 'rogue-engine';
- import RapierMovementController from './RapierMovementController.re';
- import ShipCannonController from './ShipCannonController.re';
- export default class PlayerPawnInput extends RE.Component {
- movementController:RapierMovementController
- cannonController:ShipCannonController
- awake() {
- }
- start() {
- this.object3d.traverse(obj => {
- const components = RE.getObjectComponents(obj);
- components.forEach(comp => {
- if (comp instanceof RapierMovementController) {
- this.movementController = comp
- }
- });
- });
- this.object3d.traverse(obj => {
- const components = RE.getObjectComponents(obj);
- components.forEach(comp => {
- if (comp instanceof ShipCannonController) {
- this.cannonController = comp
- }
- });
- });
- }
- update() {
- if (RE.Input.keyboard.getKeyPressed("KeyW")) {
- this.movementController.thrust = true
- }
- if (RE.Input.keyboard.getKeyPressed("KeyA")) {
- this.movementController.rotateLeft = true
- }
- if (RE.Input.keyboard.getKeyPressed("KeyS")) {
- this.movementController.brake = true
- }
- if (RE.Input.keyboard.getKeyPressed("KeyD")) {
- this.movementController.rotateRight = true
- }
-
- if(RE.Input.keyboard.getKeyDown("Space")) {
- this.cannonController.fireLeft = true
- this.cannonController.fireRight = true
- this.cannonController.fireForward = true
- }
- }
- }
- RE.registerComponent(PlayerPawnInput);
-
|