DummyShooter.re.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as RE from 'rogue-engine';
  2. import ShipCannonController from './ShipCannonController.re';
  3. export default class DummyShooter extends RE.Component {
  4. cannonController: ShipCannonController
  5. elapsed: number = 0
  6. hasShot: boolean = true
  7. cooldown: number = 3
  8. awake() {
  9. this.cannonController = RE.getComponent(ShipCannonController, this.object3d) as ShipCannonController
  10. this.elapsed = 0
  11. this.hasShot = true
  12. this.cooldown = 3
  13. }
  14. start() {
  15. }
  16. update() {
  17. this.elapsed += RE.Runtime.deltaTime
  18. if(this.cooldown > 0) {
  19. this.cooldown -= RE.Runtime.deltaTime
  20. }
  21. if(this.cooldown <= 0) {
  22. this.hasShot = false
  23. }
  24. if(!this.hasShot) {
  25. if(Math.floor(this.elapsed) % 5 == 0) {
  26. this.cannonController.fireRight = true
  27. this.hasShot = true
  28. this.cooldown = 3
  29. }
  30. if(Math.floor(this.elapsed) % 2 == 0) {
  31. this.cannonController.fireForward = true
  32. this.hasShot = true
  33. this.cooldown = 3
  34. }
  35. }
  36. }
  37. }
  38. RE.registerComponent(DummyShooter);