GameLogic.re.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as RE from 'rogue-engine'
  2. import * as THREE from 'three'
  3. export default class GameLogic extends RE.Component {
  4. @RE.props.list.prefab() buildings: Array<RE.Prefab>;
  5. placementMode: number = 3
  6. focusPoint: THREE.Object3D | undefined
  7. awake() {
  8. }
  9. start() {
  10. for(let i = 0; i < 100; i++) {
  11. const newBuilding = this.buildings[Math.floor(3 * Math.random())].instantiate()
  12. const randomPosition = new THREE.Vector3(Math.floor(98 * Math.random()) - 49, 0.1,Math.floor(98 * Math.random()) - 49)
  13. newBuilding.position.copy(randomPosition)
  14. }
  15. this.focusPoint = RE.App.currentScene.getObjectByName("FocusPoint")
  16. }
  17. update() {
  18. // if(RE.Input.keyboard.getKeyDown("Digit1")) {
  19. // this.placementMode = 3
  20. // }
  21. // if(RE.Input.keyboard.getKeyDown("Digit2")) {
  22. // this.placementMode = 0
  23. // }
  24. // if(RE.Input.keyboard.getKeyDown("Digit3")) {
  25. // this.placementMode = 1
  26. // }
  27. // if(RE.Input.keyboard.getKeyDown("Digit4")) {
  28. // this.placementMode = 2
  29. // }
  30. // if(RE.Input.mouse.getButtonDown(0)) {
  31. // const targetSelector = RE.App.currentScene.getObjectByName("GridTarget")
  32. // if(!targetSelector) {
  33. // return
  34. // }
  35. // let newBuilding = this.buildings[this.placementMode].instantiate()
  36. // newBuilding.position.set(targetSelector.position.x, 0, targetSelector.position.z)
  37. // }
  38. }
  39. }
  40. RE.registerComponent(GameLogic);